Best Python code snippet using devtools-proxy_python
test_real_transforms.py
Source:test_real_transforms.py  
...96        y = idst(np.arange(5)*1j)97        x = 1j*idst(np.arange(5))98        assert_array_almost_equal(x, y)99class _TestDCTBase(object):100    def setup_method(self):101        self.rdt = None102        self.dec = 14103        self.type = None104    def test_definition(self):105        for i in FFTWDATA_SIZES:106            x, yr, dt = fftw_dct_ref(self.type, i, self.rdt)107            y = dct(x, type=self.type)108            assert_equal(y.dtype, dt)109            # XXX: we divide by np.max(y) because the tests fail otherwise. We110            # should really use something like assert_array_approx_equal. The111            # difference is due to fftw using a better algorithm w.r.t error112            # propagation compared to the ones from fftpack.113            assert_array_almost_equal(y / np.max(y), yr / np.max(y), decimal=self.dec,114                    err_msg="Size %d failed" % i)115    def test_axis(self):116        nt = 2117        for i in [7, 8, 9, 16, 32, 64]:118            x = np.random.randn(nt, i)119            y = dct(x, type=self.type)120            for j in range(nt):121                assert_array_almost_equal(y[j], dct(x[j], type=self.type),122                        decimal=self.dec)123            x = x.T124            y = dct(x, axis=0, type=self.type)125            for j in range(nt):126                assert_array_almost_equal(y[:,j], dct(x[:,j], type=self.type),127                        decimal=self.dec)128class _TestDCTIIBase(_TestDCTBase):129    def test_definition_matlab(self):130        # Test correspondence with matlab (orthornomal mode).131        for i in range(len(X)):132            dt = np.result_type(np.float32, self.rdt)133            x = np.array(X[i], dtype=dt)134            yr = Y[i]135            y = dct(x, norm="ortho", type=2)136            assert_equal(y.dtype, dt)137            assert_array_almost_equal(y, yr, decimal=self.dec)138class _TestDCTIIIBase(_TestDCTBase):139    def test_definition_ortho(self):140        # Test orthornomal mode.141        for i in range(len(X)):142            x = np.array(X[i], dtype=self.rdt)143            dt = np.result_type(np.float32, self.rdt)144            y = dct(x, norm='ortho', type=2)145            xi = dct(y, norm="ortho", type=3)146            assert_equal(xi.dtype, dt)147            assert_array_almost_equal(xi, x, decimal=self.dec)148class TestDCTIDouble(_TestDCTBase):149    def setup_method(self):150        self.rdt = np.double151        self.dec = 10152        self.type = 1153class TestDCTIFloat(_TestDCTBase):154    def setup_method(self):155        self.rdt = np.float32156        self.dec = 5157        self.type = 1158class TestDCTIInt(_TestDCTBase):159    def setup_method(self):160        self.rdt = int161        self.dec = 5162        self.type = 1163class TestDCTIIDouble(_TestDCTIIBase):164    def setup_method(self):165        self.rdt = np.double166        self.dec = 10167        self.type = 2168class TestDCTIIFloat(_TestDCTIIBase):169    def setup_method(self):170        self.rdt = np.float32171        self.dec = 5172        self.type = 2173class TestDCTIIInt(_TestDCTIIBase):174    def setup_method(self):175        self.rdt = int176        self.dec = 5177        self.type = 2178class TestDCTIIIDouble(_TestDCTIIIBase):179    def setup_method(self):180        self.rdt = np.double181        self.dec = 14182        self.type = 3183class TestDCTIIIFloat(_TestDCTIIIBase):184    def setup_method(self):185        self.rdt = np.float32186        self.dec = 5187        self.type = 3188class TestDCTIIIInt(_TestDCTIIIBase):189    def setup_method(self):190        self.rdt = int191        self.dec = 5192        self.type = 3193class _TestIDCTBase(object):194    def setup_method(self):195        self.rdt = None196        self.dec = 14197        self.type = None198    def test_definition(self):199        for i in FFTWDATA_SIZES:200            xr, yr, dt = fftw_dct_ref(self.type, i, self.rdt)201            x = idct(yr, type=self.type)202            if self.type == 1:203                x /= 2 * (i-1)204            else:205                x /= 2 * i206            assert_equal(x.dtype, dt)207            # XXX: we divide by np.max(y) because the tests fail otherwise. We208            # should really use something like assert_array_approx_equal. The209            # difference is due to fftw using a better algorithm w.r.t error210            # propagation compared to the ones from fftpack.211            assert_array_almost_equal(x / np.max(x), xr / np.max(x), decimal=self.dec,212                    err_msg="Size %d failed" % i)213class TestIDCTIDouble(_TestIDCTBase):214    def setup_method(self):215        self.rdt = np.double216        self.dec = 10217        self.type = 1218class TestIDCTIFloat(_TestIDCTBase):219    def setup_method(self):220        self.rdt = np.float32221        self.dec = 4222        self.type = 1223class TestIDCTIInt(_TestIDCTBase):224    def setup_method(self):225        self.rdt = int226        self.dec = 4227        self.type = 1228class TestIDCTIIDouble(_TestIDCTBase):229    def setup_method(self):230        self.rdt = np.double231        self.dec = 10232        self.type = 2233class TestIDCTIIFloat(_TestIDCTBase):234    def setup_method(self):235        self.rdt = np.float32236        self.dec = 5237        self.type = 2238class TestIDCTIIInt(_TestIDCTBase):239    def setup_method(self):240        self.rdt = int241        self.dec = 5242        self.type = 2243class TestIDCTIIIDouble(_TestIDCTBase):244    def setup_method(self):245        self.rdt = np.double246        self.dec = 14247        self.type = 3248class TestIDCTIIIFloat(_TestIDCTBase):249    def setup_method(self):250        self.rdt = np.float32251        self.dec = 5252        self.type = 3253class TestIDCTIIIInt(_TestIDCTBase):254    def setup_method(self):255        self.rdt = int256        self.dec = 5257        self.type = 3258class _TestDSTBase(object):259    def setup_method(self):260        self.rdt = None  # dtype261        self.dec = None  # number of decimals to match262        self.type = None  # dst type263    def test_definition(self):264        for i in FFTWDATA_SIZES:265            xr, yr, dt = fftw_dst_ref(self.type, i, self.rdt)266            y = dst(xr, type=self.type)267            assert_equal(y.dtype, dt)268            # XXX: we divide by np.max(y) because the tests fail otherwise. We269            # should really use something like assert_array_approx_equal. The270            # difference is due to fftw using a better algorithm w.r.t error271            # propagation compared to the ones from fftpack.272            assert_array_almost_equal(y / np.max(y), yr / np.max(y), decimal=self.dec,273                    err_msg="Size %d failed" % i)274class TestDSTIDouble(_TestDSTBase):275    def setup_method(self):276        self.rdt = np.double277        self.dec = 14278        self.type = 1279class TestDSTIFloat(_TestDSTBase):280    def setup_method(self):281        self.rdt = np.float32282        self.dec = 5283        self.type = 1284class TestDSTIInt(_TestDSTBase):285    def setup_method(self):286        self.rdt = int287        self.dec = 5288        self.type = 1289class TestDSTIIDouble(_TestDSTBase):290    def setup_method(self):291        self.rdt = np.double292        self.dec = 14293        self.type = 2294class TestDSTIIFloat(_TestDSTBase):295    def setup_method(self):296        self.rdt = np.float32297        self.dec = 6298        self.type = 2299class TestDSTIIInt(_TestDSTBase):300    def setup_method(self):301        self.rdt = int302        self.dec = 6303        self.type = 2304class TestDSTIIIDouble(_TestDSTBase):305    def setup_method(self):306        self.rdt = np.double307        self.dec = 14308        self.type = 3309class TestDSTIIIFloat(_TestDSTBase):310    def setup_method(self):311        self.rdt = np.float32312        self.dec = 7313        self.type = 3314class TestDSTIIIInt(_TestDSTBase):315    def setup_method(self):316        self.rdt = int317        self.dec = 7318        self.type = 3319class _TestIDSTBase(object):320    def setup_method(self):321        self.rdt = None322        self.dec = None323        self.type = None324    def test_definition(self):325        for i in FFTWDATA_SIZES:326            xr, yr, dt = fftw_dst_ref(self.type, i, self.rdt)327            x = idst(yr, type=self.type)328            if self.type == 1:329                x /= 2 * (i+1)330            else:331                x /= 2 * i332            assert_equal(x.dtype, dt)333            # XXX: we divide by np.max(x) because the tests fail otherwise. We334            # should really use something like assert_array_approx_equal. The335            # difference is due to fftw using a better algorithm w.r.t error336            # propagation compared to the ones from fftpack.337            assert_array_almost_equal(x / np.max(x), xr / np.max(x), decimal=self.dec,338                    err_msg="Size %d failed" % i)339class TestIDSTIDouble(_TestIDSTBase):340    def setup_method(self):341        self.rdt = np.double342        self.dec = 12343        self.type = 1344class TestIDSTIFloat(_TestIDSTBase):345    def setup_method(self):346        self.rdt = np.float32347        self.dec = 4348        self.type = 1349class TestIDSTIInt(_TestIDSTBase):350    def setup_method(self):351        self.rdt = int352        self.dec = 4353        self.type = 1354class TestIDSTIIDouble(_TestIDSTBase):355    def setup_method(self):356        self.rdt = np.double357        self.dec = 14358        self.type = 2359class TestIDSTIIFloat(_TestIDSTBase):360    def setup_method(self):361        self.rdt = np.float32362        self.dec = 6363        self.type = 2364class TestIDSTIIInt(_TestIDSTBase):365    def setup_method(self):366        self.rdt = int367        self.dec = 6368        self.type = 2369class TestIDSTIIIDouble(_TestIDSTBase):370    def setup_method(self):371        self.rdt = np.double372        self.dec = 14373        self.type = 3374class TestIDSTIIIFloat(_TestIDSTBase):375    def setup_method(self):376        self.rdt = np.float32377        self.dec = 6378        self.type = 3379class TestIDSTIIIInt(_TestIDSTBase):380    def setup_method(self):381        self.rdt = int382        self.dec = 6383        self.type = 3384class TestOverwrite(object):385    """Check input overwrite behavior """386    real_dtypes = [np.float32, np.float64]387    def _check(self, x, routine, type, fftsize, axis, norm, overwrite_x,388               should_overwrite, **kw):389        x2 = x.copy()390        routine(x2, type, fftsize, axis, norm, overwrite_x=overwrite_x)391        sig = "%s(%s%r, %r, axis=%r, overwrite_x=%r)" % (392            routine.__name__, x.dtype, x.shape, fftsize, axis, overwrite_x)393        if not should_overwrite:394            assert_equal(x2, x, err_msg="spurious overwrite in %s" % sig)...test_build.py
Source:test_build.py  
...36    cli = BuildCLI(config)37    cli.db = Mock()38    return cli39class BuildTest:40    def setup_method(self, method):41        self.build = Build(mock.MagicMock())42        self.base_config = BASE_CONFIG43class TestBuildSetup(BuildTest):44    def setup_method(self, method):45        self.methods = (46            # 'add_build',47            'set_logfile',48            'set_version',49            'configure_env',50            'configure_steps',51            'configure_pipeline',52            'setup_env',53        )54        super(TestBuildSetup, self).setup_method(method)55    def test_setup_calls(self):56        for method in self.methods:57            setattr(self.build, method, mock.Mock())58        self.build.setup()59        for method in self.methods:60            getattr(self.build, method).assert_called_once_with()61class TestBuildRun(BuildTest):62    def setup_method(self, method):63        self.methods = ('setup', 'execute', 'teardown', 'finish')64        super(TestBuildRun, self).setup_method(method)65        self.build.version = mock.Mock()66        for method in self.methods:67            setattr(self.build, method, mock.Mock())68    def test_run_calls(self):69        self.build.run('pipeline', 'env')70        for method in self.methods:71            getattr(self.build, method).assert_called_once_with()72    def test_run_returns_boolean_success(self):73        self.build.success = False74        ret = self.build.run('pipeline', 'env')75        assert ret is False76        self.build.success = True77        ret = self.build.run('other', 'illusion')78        assert ret is True79class TestBuildSetVersion:80    def setup_method(self, method):81        self.version = '0.0.0.0.0.0.0.0.1-beta'82        self.cls = mock.Mock()83        self.cls_key = 'mandowar.FearOfTheDark'84        self.build = Build(mock.Mock())85        self.build.config.raw = {86            'version': {87                'class': self.cls_key,88            },89        }90        self.build.config.classes = {self.cls_key: self.cls}91    def test_set_version(self):92        self.build.set_version()93        self.cls.assert_called_once_with(94            self.build,95            self.build.config.raw['version'],96        )97        self.cls.return_value.validate.assert_called_once_with()98class TestBuildConfigureEnv:99    def setup_method(self, method):100        env_key = 'local'101        self.cls_key = 'unisonic.KingForADay'102        self.cls = mock.Mock()103        self.config = mock.Mock()104        self.config.env = env_key105        self.config.classes = {self.cls_key: self.cls}106        self.config.raw = {107            'envs': {108                env_key: {109                    'class': self.cls_key,110                }111            },112            'env': env_key,113        }114        self.build = Build(self.config)115        self.build.env = env_key116    def test_configure_env(self):117        self.build.configure_env()118        self.cls.assert_called_once_with(119            self.build,120            self.build.config.raw['envs'][self.config.env],121        )122        self.cls.return_value.validate.assert_called_once_with()123class TestBuildConfigureSteps:124    def setup_method(self, method):125        self.step_key = 'local'126        self.raw = {127            'steps': {128                'bang': {129                    'class': 'edguy.police.LoveTyger',130                },131                'boom': {132                    'class': 'bethhart.light.LiftsUUp',133                }134            },135        }136        self.build = Build(mock.Mock(pipeline=self.step_key))137        self.build.config = mock.Mock()138        self.build.config.classes = {}139        self.build.config.raw = self.raw140        for key in self.raw['steps']:141            cls = self.raw['steps'][key]['class']142            self.build.config.classes[cls] = mock.Mock()143    def test_configure_steps(self):144        self.build.configure_steps()145        for key in self.raw['steps']:146            cls_key = self.raw['steps'][key]['class']147            cls = self.build.config.classes[cls_key]148            cls.assert_called_once_with(149                self.build,150                self.build.config.raw['steps'][key],151                key152            )153            cls.return_value.validate.assert_called_once_with()154class TestBuildConfigurePipeline:155    def setup_method(self, method):156        self.step_keys = ('bidubidappa', 'dubop', 'schuwappa')157        self.pipeline_key = 'mmmbop'158        self.config = mock.MagicMock()159        self.config.pipeline = self.pipeline_key160        self.config.raw = {161            'pipeline': self.pipeline_key,162            'pipelines': {self.pipeline_key: self.step_keys}163        }164        self.steps = (mock.Mock(), mock.Mock(), mock.Mock())165        for step in self.steps:166            step.config.depends = None167    def get_build(self, config):168        build = Build(self.config)169        build.steps = dict(zip(self.step_keys, self.steps))170        build.pipeline = self.pipeline_key171        return build172    def test_configure_pipeline(self):173        self.build = self.get_build(self.config)174        self.build.configure_pipeline()175        for x, _ in enumerate(self.step_keys):176            assert self.build.order[x] is self.steps[x]177class TestBuildExecute:178    def setup_method(self, method):179        self.build = Build(mock.Mock())180        self.build.order = [mock.Mock() for _ in range(3)]181        self.build.env = mock.Mock()182        self.build.config.raw = {183            'pipeline': 'gemma',184        }185    def test_all_successful(self):186        self.build.execute()187        calls = [mock.call(step) for step in self.build.order]188        assert self.build.env.execute.call_args_list == calls189        assert self.build.success is True190    def test_execution_stops_by_failed_step(self):191        self.build.order[1].success = False192        self.build.env.execute.side_effect = (193            mock.Mock(),194            mock.Mock(success=False),195        )196        self.build.execute()197        calls = [mock.call(step) for step in self.build.order[:2]]198        assert self.build.env.execute.call_args_list == calls199        assert self.build.success is False200class TestBuildSetupEnv(BuildTest):201    def setup_method(self, method):202        super(TestBuildSetupEnv, self).setup_method(method)203        self.build.env = mock.Mock()204    def test_setup_env(self):205        self.build.setup_env()206        self.build.env.setup.assert_called_once_with()207class TestBuildTeardown(BuildTest):208    def setup_method(self, method):209        super(TestBuildTeardown, self).setup_method(method)210        self.build.env = mock.Mock()211    def test_teardown(self):212        self.build.teardown_env = mock.Mock()213        self.build.teardown()214        self.build.teardown_env.assert_called_once_with()215    def test_teardown_env(self):216        self.build.teardown_env()217        self.build.env.teardown.assert_called_once_with()218class TestBuildQueue(BuildTest):219    @mock.patch('piper.config.get_app_config')220    @mock.patch('requests.post')221    def test_queue(self, post, gac):222        gac.return_value = {223            'masters': ['protocol://hehe:1000']224        }225        self.build.queue('pipeline', 'env')226        post.assert_called_once_with(227            'protocol://hehe:1000/builds/',228            json=self.build.config.raw,229        )230class TestBuildFinish(BuildTest):231    def setup_method(self, method):232        super(TestBuildFinish, self).setup_method(method)233        self.build.db = mock.Mock()234        self.build.log_handler = mock.Mock()235    @mock.patch('ago.human')236    @mock.patch('piper.utils.now')237    def test_log_handler_is_popped(self, now, human):238        self.build.finish()239        assert self.build.ended is now.return_value240        now.assert_called_once_with()241        self.build.log_handler.pop_application.assert_called_once_with()242class TestBuildSetLogfile(BuildTest):243    def setup_method(self, method):244        super(TestBuildSetLogfile, self).setup_method(method)245        self.build.ref = mock.Mock()246        self.build.log_handler = mock.Mock()247    @mock.patch('piper.logging.get_file_logger')248    def test_logger_is_set(self, gfl):249        self.build.log = None250        self.build.set_logfile()251        assert self.build.log is not None252    @mock.patch('piper.logging.get_file_logger')253    def test_logfile_is_set(self, gfl):254        self.build.logfile = None255        self.build.set_logfile()256        assert self.build.logfile is not None257    @mock.patch('piper.logging.get_file_logger')258    def test_log_handler_is_configured(self, gfl):259        self.build.set_logfile()260        assert gfl.call_count == 1261        assert gfl.return_value is self.build.log_handler262        self.build.log_handler.push_application.assert_called_once_with()263class TestExecCLIRun:264    def setup_method(self, method):265        self.config = mock.Mock()266        self.cli = ExecCLI(self.config)267    @mock.patch('piper.build.Build')268    def test_calls(self, b, ns):269        ret = self.cli.run(ns)270        assert ret == 0271        b.assert_called_once_with(self.config)272        b.return_value.run.assert_called_once_with(ns.pipeline, ns.env)273    @mock.patch('piper.build.Build')274    def test_nonzero_exitcode_on_failure(self, b, ns):275        b.return_value.run.return_value = False276        ret = self.cli.run(ns)277        assert ret == 1278class TestBuildApiGet(object):...py_benchmark.py
Source:py_benchmark.py  
1import sys2import os3import timeit4import math5import argparse6import fnmatch7import json8parser = argparse.ArgumentParser(description="Python protobuf benchmark")9parser.add_argument("data_files", metavar="dataFile", nargs="+", 10                    help="testing data files.")11parser.add_argument("--json", action="store_const", dest="json",12                    const="yes", default="no",13                    help="Whether to output json results")14parser.add_argument("--behavior_prefix", dest="behavior_prefix",15                    help="The output json format's behavior's name's prefix",16                    default="")17# BEGIN CPP GENERATED MESSAGE18parser.add_argument("--cpp_generated", action="store_const",19                    dest="cpp_generated", const="yes", default="no",20                    help="Whether to link generated code library")21# END CPP GENERATED MESSAGE22args = parser.parse_args()23# BEGIN CPP GENERATED MESSAGE24# CPP generated code must be linked before importing the generated Python code25# for the descriptor can be found in the pool26if args.cpp_generated != "no":27  sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/.libs" )28  import libbenchmark_messages29  sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/tmp" )30# END CPP GENERATED MESSAGE31import datasets.google_message1.proto2.benchmark_message1_proto2_pb2 as benchmark_message1_proto2_pb232import datasets.google_message1.proto3.benchmark_message1_proto3_pb2 as benchmark_message1_proto3_pb233import datasets.google_message2.benchmark_message2_pb2 as benchmark_message2_pb234import datasets.google_message3.benchmark_message3_pb2 as benchmark_message3_pb235import datasets.google_message4.benchmark_message4_pb2 as benchmark_message4_pb236import benchmarks_pb2 as benchmarks_pb237def run_one_test(filename):38  data = open(filename).read()39  benchmark_dataset = benchmarks_pb2.BenchmarkDataset()40  benchmark_dataset.ParseFromString(data)41  benchmark_util = Benchmark(full_iteration=len(benchmark_dataset.payload),42                             module="py_benchmark",43                             setup_method="init")44  result={}45  result["filename"] =  filename46  result["message_name"] =  benchmark_dataset.message_name47  result["benchmarks"] = {}48  benchmark_util.set_test_method("parse_from_benchmark")49  result["benchmarks"][args.behavior_prefix + "_parse_from_benchmark"] = \50    benchmark_util.run_benchmark(setup_method_args='"%s"' % (filename))51  benchmark_util.set_test_method("serialize_to_benchmark")52  result["benchmarks"][args.behavior_prefix + "_serialize_to_benchmark"] = \53    benchmark_util.run_benchmark(setup_method_args='"%s"' % (filename))54  return result55def init(filename):56  global benchmark_dataset, message_class, message_list, counter57  message_list=[]58  counter = 059  data = open(os.path.dirname(sys.argv[0]) + "/../" + filename).read()60  benchmark_dataset = benchmarks_pb2.BenchmarkDataset()61  benchmark_dataset.ParseFromString(data)62  if benchmark_dataset.message_name == "benchmarks.proto3.GoogleMessage1":63    message_class = benchmark_message1_proto3_pb2.GoogleMessage164  elif benchmark_dataset.message_name == "benchmarks.proto2.GoogleMessage1":65    message_class = benchmark_message1_proto2_pb2.GoogleMessage166  elif benchmark_dataset.message_name == "benchmarks.proto2.GoogleMessage2":67    message_class = benchmark_message2_pb2.GoogleMessage268  elif benchmark_dataset.message_name == "benchmarks.google_message3.GoogleMessage3":69    message_class = benchmark_message3_pb2.GoogleMessage370  elif benchmark_dataset.message_name == "benchmarks.google_message4.GoogleMessage4":71    message_class = benchmark_message4_pb2.GoogleMessage472  else:73    raise IOError("Message %s not found!" % (benchmark_dataset.message_name))74  for one_payload in benchmark_dataset.payload:75    temp = message_class()76    temp.ParseFromString(one_payload)77    message_list.append(temp)78def parse_from_benchmark():79  global counter, message_class, benchmark_dataset80  m = message_class().ParseFromString(benchmark_dataset.payload[counter % len(benchmark_dataset.payload)])81  counter = counter + 182def serialize_to_benchmark():83  global counter, message_list, message_class84  s = message_list[counter % len(benchmark_dataset.payload)].SerializeToString()85  counter = counter + 186class Benchmark:87  def __init__(self, module=None, test_method=None,88               setup_method=None, full_iteration = 1):89    self.full_iteration = full_iteration90    self.module = module91    self.test_method = test_method92    self.setup_method = setup_method93  def set_test_method(self, test_method):94    self.test_method = test_method95  def full_setup_code(self, setup_method_args=''):96    setup_code = ""97    setup_code += "from %s import %s\n" % (self.module, self.test_method)98    setup_code += "from %s import %s\n" % (self.module, self.setup_method)99    setup_code += "%s(%s)\n" % (self.setup_method, setup_method_args)100    return setup_code101  def dry_run(self, test_method_args='', setup_method_args=''):102    return timeit.timeit(stmt="%s(%s)" % (self.test_method, test_method_args),103                         setup=self.full_setup_code(setup_method_args),104                         number=self.full_iteration);105  def run_benchmark(self, test_method_args='', setup_method_args=''):106    reps = self.full_iteration;107    t = self.dry_run(test_method_args, setup_method_args);108    if t < 3 :109      reps = int(math.ceil(3 / t)) * self.full_iteration110    t = timeit.timeit(stmt="%s(%s)" % (self.test_method, test_method_args),111                      setup=self.full_setup_code(setup_method_args),112                      number=reps);113    return 1.0 * t / reps * (10 ** 9)114  115if __name__ == "__main__":116  results = []117  for file in args.data_files:118    results.append(run_one_test(file))119  120  if args.json != "no":121    print json.dumps(results)122  else:123    for result in results:124      print "Message %s of dataset file %s" % \125          (result["message_name"], result["filename"])126      print "Average time for parse_from_benchmark: %.2f ns" % \127          (result["benchmarks"][ \128                      args.behavior_prefix + "_parse_from_benchmark"])129      print "Average time for serialize_to_benchmark: %.2f ns" % \130          (result["benchmarks"][ \131                      args.behavior_prefix + "_serialize_to_benchmark"])...test_parse.py
Source:test_parse.py  
...10    """11    NotFound word has no header, and any meaning12    so, this class has no Parse.parse_word_header, parse_meaning tests.13    """14    def setup_method(self):15        self.word_name = "notfound"16        self.html = get_html(self.word_name)17        self.soup = BeautifulSoup(self.html, "lxml")18    def test_word_name(self):19        word_info = Parse.parse(self.word_name, self.html)20        assert word_info["word_name"] == self.word_name21    def test_get_part_of_speech(self):22        word_info = Parse.parse(self.word_name, self.html)23        assert word_info["type_of_speech"] == []24class TestParseNoun:25    def setup_method(self):26        self.word_name = "dictionary"27        self.html = get_html(self.word_name)28        self.soup = BeautifulSoup(self.html, "lxml")29    def test_parse_word_header(self):30        word_info = {}31        Parse.parse_word_header(word_info, self.soup)32        assert word_info["main_meaning"] == "è¾æ¸ãè¾å
¸"33    @pytest.mark.skip()34    def test_parse_meaning(self):35        word_info = {}36        Parse.parse_meaning(word_info, self.soup)37        assert word_info["noun"] == "è¾æ¸ï¼è¾å
¸"38@pytest.mark.skip()39class TestParseVerb:40    def setup_method(self):41        pass42    def test_get_part_of_speech(self):43        pass44@pytest.mark.skip()45class TestParseAdjective:46    def setup_method(self):47        pass48    def test_get_part_of_speech(self):49        pass50@pytest.mark.skip()51class TestParsePreposition:52    def setup_method(self):53        self.word_name = "into"54        self.html = get_html(self.word_name)55        self.parsed = Parse.parse(self.word_name, self.html)56    def test_get_part_of_speech(self):57        pass58@pytest.mark.skip()59class TestParseConjunction:60    def setup_method(self):61        pass62    def test_get_part_of_speech(self):63        pass64class TestParseMultiplePartOfSpeeches:65    def setup_method(self):66        self.word_name = "take"67        self.html = get_html(self.word_name)68        self.soup = BeautifulSoup(self.html, "lxml")69    def test_parse_word_header(self):70        word_info = {}71        Parse.parse_word_header(word_info, self.soup)72        assert (73            word_info["main_meaning"]74            == "(æãªã©ã§)åãã(â¦ã)åããã¤ããã(â¦ã)æ±ããæ±ãç· ããã(ããªã»ãããªã©ã§)æããããæç¸ãããæèã«ããã(â¦ã)(â¦ã§)æããããå é ãã"75        )76    @pytest.mark.skip()77    def test_parse_meaning(self):78        word_info = {}79        Parse.parse_meaning(word_info, self.soup)...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
