How to use test_identify method in yandex-tank

Best Python code snippet using yandex-tank

test_cyclone_identification_full.py

Source:test_cyclone_identification_full.py Github

copy

Full Screen

1#!/usr/bin/env python32# Standard library3import json4import logging as log5import os6import pytest7import unittest8import sys9from unittest import TestCase10# Third-party11import numpy as np12# First-party13import stormtrack.extra.utilities_misc as io14from stormtrack.extra.cyclone_id.cyclone import CycloneIOWriterJson15from stormtrack.extra.cyclone_id.identify import identify_features16from stormtrack.extra.utilities_misc import Field2D17# log.getLogger().addHandler(log.StreamHandler(sys.stdout))18# log.getLogger().setLevel(log.DEBUG)19@unittest.skip("missing input data")20@pytest.mark.skip("missing input data")21class TestIdentifyFeatures(TestCase):22 """Run the identification using the same case but different configs.23 The input fields are read from disk (binary), as is the solution (JSON).24 Assertion is done by comparing result and solution as JSON strings.25 If a test fails, both result and solution are written to JSON files.26 """27 DBG = False28 WORK_DIR = "."29 DATA_DIR = "./test_data"30 FILE_DIR = os.path.dirname(os.path.relpath(__file__))31 TOPO_NAME = "HSURF"32 @classmethod33 def setUpClass(cls):34 file_in = "{p}/test_identify.input.npz".format(p=cls.DATA_DIR)35 cls.read_test_data(file_in)36 @classmethod37 def read_test_data(cls, file_name):38 """Read the input data from file. Return data as Field2D objects."""39 if cls.DBG:40 print("READ TEST DATA FROM FILE: {n}".format(n=file_name))41 data = np.load(file_name)42 cls.slp_raw = data["slp"]43 cls.topo_raw = data["topo"]44 cls.lon = data["lon"]45 cls.lat = data["lat"]46 cls.topo = Field2D(cls.topo_raw, cls.lon, cls.lat, name=cls.TOPO_NAME)47 def setUp(s):48 # Create new SLP field49 s.slp = Field2D(s.slp_raw.copy(), s.lon, s.lat)50 # Default configuration51 s.conf = {52 "timings-identify": False,53 "size-boundary-zone": 5,54 "smoothing-sigma": 7.0,55 "force-contours-closed": False,56 "contour-interval": 0.5,57 "depression-min-contours": 1,58 "contour-length-max": -1.0,59 "bcc-fraction": 0.5,60 "min-cyclone-depth": 1.0,61 "extrema-identification-size": 9,62 "max-minima-per-cyclone": 3,63 "contour-length-min": -1.0,64 "topo-cutoff-level": 1500.0,65 "read-slp-contours": False,66 "read-slp-extrema": False,67 "save-slp-contours": False,68 "save-slp-extrema": False,69 }70 def run_identification(s, conf):71 """Run the cyclone identification. Return as a JSON string."""72 if s.DBG:73 print("RUN IDENTIFICATION")74 features = identify_features(s.slp, s.topo, conf)75 writer = CycloneIOWriterJson()76 writer.add_points("MINIMA", s.slp.minima())77 writer.add_points("MAXIMA", s.slp.maxima())78 writer.add_depressions(features["depressions"])79 writer.add_cyclones(features["cyclones"])80 # SR_TMP<81 depressions, cyclones = features["depressions"], features["cyclones"]82 levels = np.arange(950, 1050, 0.5)83 io.plot_depressions("nodypy_depressions.png", depressions, s.slp, levels)84 io.plot_cyclones("nodypy_cyclones.png", cyclones, s.slp, levels)85 # SR_TMP>86 return writer.write_string().strip()87 def read_solution(s, name):88 """Read the solution from file as a JSON string."""89 file_sol = "{p}/test_identify.{n}.sol.json".format(p=s.FILE_DIR, n=name)90 if s.DBG:91 print("READ SOLUTION FROM FILE: {f}".format(f=file_sol))92 with open(file_sol, "r") as f:93 return f.read().strip()94 def evaluate_result(s, name, jstr_res, jstr_sol):95 """Compare result and solution in form of JSON string.96 If the test fails, write both strings to file for comparison.97 """98 if s.DBG:99 print("EVALUATE RESULTS OF TEST: {n}".format(n=name))100 tag = "test_identify"101 file_res = "{p}/tmp.{t}.{n}.res.json".format(p=s.WORK_DIR, t=tag, n=name)102 file_sol = "{p}/{t}.{n}.sol.json".format(p=s.FILE_DIR, t=tag, n=name)103 err_msg = (104 "JSON strings not equal! Dumped result: {r}\n"105 "To check what's wrong, run:\nvimdiff {r} {s}"106 ).format(r=file_res, s=file_sol)107 try:108 s.assertEqual(jstr_res, jstr_sol, err_msg)109 except AssertionError:110 with open(file_res, "w") as f:111 f.write(jstr_res)112 with open(file_sol, "w") as f:113 f.write(jstr_sol)114 raise115 def run_test(s, test_name):116 if s.DBG:117 print("RUN TEST: {n}".format(n=test_name))118 jstr_res = s.run_identification(s.conf)119 jstr_sol = s.read_solution(test_name)120 s.evaluate_result(test_name, jstr_res, jstr_sol)121 # DEFAULT122 def test_default(s):123 s.run_test("test_default")124 # SMOOTHING125 @unittest.skip("takes far too long")126 @pytest.mark.skip("takes far too long")127 def test_sig00(s):128 s.conf["smoothing-sigma"] = 0.0129 s.run_test("test_sig00")130 def test_sig03(s):131 s.conf["smoothing-sigma"] = 3.0132 s.run_test("test_sig03")133 @unittest.skip("fails...")134 @pytest.mark.skip("fails...")135 def test_sig15(s):136 s.conf["smoothing-sigma"] = 15.0137 s.run_test("test_sig15")138 # BCC FRACTION139 def test_bcc00(s):140 s.conf["bcc-fraction"] = 0.0141 s.run_test("test_bcc00")142 def test_bcc03(s):143 s.conf["bcc-fraction"] = 0.3144 s.run_test("test_bcc03")145 def test_bcc06(s):146 s.conf["bcc-fraction"] = 0.6147 s.run_test("test_bcc06")148 def test_bcc10(s):149 s.conf["bcc-fraction"] = 1.0150 s.run_test("test_bcc10")151if __name__ == "__main__":...

Full Screen

Full Screen

keypoints_test.py

Source:keypoints_test.py Github

copy

Full Screen

...11 pass12 def data_detect(self, data):13 return True14 @identifying15 def test_identify(self, data):16 return data17 @verifying18 def test_verify(self, data):19 return data20def identifying_test():21 detector = TestDetector()22 assert detector is not None23 assert detector.test_identify({}) == {}24def verifying_test():25 detector = TestDetector()26 assert detector is not None27 assert detector.test_verify({}) == {}28def KeypointsObjectDetector_test():29 img = cv2.imread(TEST_IMAGE_PATH)30 detector = KeypointsObjectDetector()31 assert detector is not None32 assert detector.threshold() == 25.033 assert detector.last_error() == ""34 detector.setUseROIDetection(False)35 assert detector.addSource({'path': TEST_IMAGE_PATH, 'data': img})36 assert detector.addSources([{'path': TEST_IMAGE_PATH, 'data': img}, {'path': TEST_IMAGE_PATH, 'data': img},37 {'path': TEST_IMAGE_PATH, 'data': img}, {'path': TEST_IMAGE_PATH, 'data': img}]) == 4...

Full Screen

Full Screen

test_identify.py

Source:test_identify.py Github

copy

Full Screen

...3 mp.dps = 154 assert pslq([3*pi+4*e/7, pi, e, log(2)]) == [7, -21, -4, 0]5 assert pslq([4.9999999999999991, 1]) == [1, -5]6 assert pslq([2,1]) == [1, -2]7def test_identify():8 mp.dps = 209 assert identify(zeta(4), ['log(2)', 'pi**4']) == '((1/90)*pi**4)'10 mp.dps = 1511 assert identify(exp(5)) == 'exp(5)'12 assert identify(exp(4)) == 'exp(4)'13 assert identify(log(5)) == 'log(5)'14 assert identify(exp(3*pi), ['pi']) == 'exp((3*pi))'15 assert identify(3, full=True) == ['3', '3', '1/(1/3)', 'sqrt(9)',16 '1/sqrt((1/9))', '(sqrt(12)/2)**2', '1/(sqrt(12)/6)**2']...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful