How to use test_unicode_name method in avocado

Best Python code snippet using avocado_python

test_simulationresult.py

Source:test_simulationresult.py Github

copy

Full Screen

1from pysb.simulator import ScipyOdeSimulator, BngSimulator2from pysb.simulator.base import SimulationResult3from pysb.examples import tyson_oscillator, robertson, \4 expression_observables, earm_1_3, bax_pore_sequential, bax_pore, \5 bngwiki_egfr_simple6from pysb.bng import generate_equations7import numpy as np8import tempfile9from nose.tools import assert_raises, raises10import warnings11from pysb.pattern import SpeciesPatternMatcher12import collections13import copy14import io15import pandas as pd16def test_simres_dataframe():17 """ Test SimulationResult.dataframe() """18 tspan1 = np.linspace(0, 100, 100)19 tspan2 = np.linspace(50, 100, 50)20 tspan3 = np.linspace(100, 150, 100)21 model = tyson_oscillator.model22 sim = ScipyOdeSimulator(model, integrator='lsoda')23 simres1 = sim.run(tspan=tspan1)24 # Check retrieving a single simulation dataframe25 df_single = simres1.dataframe26 # Generate multiple trajectories27 trajectories1 = simres1.species28 trajectories2 = sim.run(tspan=tspan2).species29 trajectories3 = sim.run(tspan=tspan3).species30 # Try a simulation result with two different tspan lengths31 sim = ScipyOdeSimulator(model, param_values={'k6' : [1.,1.]}, integrator='lsoda')32 simres = SimulationResult(sim, [tspan1, tspan2], [trajectories1, trajectories2])33 df = simres.dataframe34 assert df.shape == (len(tspan1) + len(tspan2),35 len(model.species) + len(model.observables))36 # Next try a simulation result with two identical tspan lengths, stacked37 # into a single 3D array of trajectories38 simres2 = SimulationResult(sim, [tspan1, tspan3],39 np.stack([trajectories1, trajectories3]))40 df2 = simres2.dataframe41 assert df2.shape == (len(tspan1) + len(tspan3),42 len(model.species) + len(model.observables))43def test_simres_observable():44 """ Test on demand observable evaluation """45 models = [tyson_oscillator.model, robertson.model,46 expression_observables.model, earm_1_3.model,47 bax_pore_sequential.model, bax_pore.model,48 bngwiki_egfr_simple.model]49 for model in models:50 generate_equations(model)51 spm = SpeciesPatternMatcher(model)52 for obs in model.observables:53 dyn_obs = spm.match(pattern=obs.reaction_pattern, index=True,54 counts=True)55 # Need to sort by species numerical order for comparison purposes56 dyn_obs = collections.OrderedDict(sorted(dyn_obs.items()))57 dyn_species = list(dyn_obs.keys())58 if obs.match == 'species':59 dyn_coeffs = [1] * len(dyn_obs)60 else:61 dyn_coeffs = list(dyn_obs.values())62 assert dyn_species == obs.species63 assert dyn_coeffs == obs.coefficients64class TestSimulationResultEarm13(object):65 def setUp(self):66 self.model = earm_1_3.model67 self.tspan = np.linspace(0, 100, 101)68 self.sim = ScipyOdeSimulator(self.model, tspan=self.tspan)69 self.simres = self.sim.run()70 @raises(ValueError)71 def test_dynamic_observable_nonpattern(self):72 self.simres.observable('cSmac')73 @raises(ValueError)74 def test_match_nonexistent_pattern(self):75 m = self.model.monomers76 self.simres.observable(m.cSmac() % m.Bid())77 def test_on_demand_observable(self):78 m = self.model.monomers79 assert isinstance(self.simres.observable(m.cSmac()), pd.Series)80def test_save_load():81 tspan = np.linspace(0, 100, 101)82 # Make a copy of model so other tests etc. don't see the changed name.83 model = copy.deepcopy(tyson_oscillator.model)84 test_unicode_name = u'Hello \u2603 and \U0001f4a9!'85 model.name = test_unicode_name86 sim = ScipyOdeSimulator(model, integrator='lsoda')87 simres = sim.run(tspan=tspan, param_values={'k6': 1.0})88 sim_rob = ScipyOdeSimulator(robertson.model, integrator='lsoda')89 simres_rob = sim_rob.run(tspan=tspan)90 # Reset equations from any previous network generation91 robertson.model.reset_equations()92 A = robertson.model.monomers['A']93 # NFsim without expressions94 nfsim1 = BngSimulator(robertson.model)95 nfres1 = nfsim1.run(n_runs=2, method='nf', tspan=np.linspace(0, 1))96 # Test attribute saving (text, float, list)97 nfres1.custom_attrs['note'] = 'NFsim without expressions'98 nfres1.custom_attrs['pi'] = 3.1499 nfres1.custom_attrs['some_list'] = [1, 2, 3]100 # NFsim with expressions101 nfsim2 = BngSimulator(expression_observables.model)102 nfres2 = nfsim2.run(n_runs=1, method='nf', tspan=np.linspace(0, 100, 11))103 with tempfile.NamedTemporaryFile() as tf:104 # Cannot have two file handles on Windows105 tf.close()106 simres.save(tf.name, dataset_name='test', append=True)107 # Try to reload when file contains only one dataset and group108 SimulationResult.load(tf.name)109 simres.save(tf.name, append=True)110 # Trying to overwrite an existing dataset gives a ValueError111 assert_raises(ValueError, simres.save, tf.name, append=True)112 # Trying to write to an existing file without append gives an IOError113 assert_raises(IOError, simres.save, tf.name)114 # Trying to write a SimulationResult to the same group with a115 # different model name results in a ValueError116 assert_raises(ValueError, simres_rob.save, tf.name,117 dataset_name='robertson', group_name=model.name,118 append=True)119 simres_rob.save(tf.name, append=True)120 # Trying to load from a file with more than one group without121 # specifying group_name should raise a ValueError122 assert_raises(ValueError, SimulationResult.load, tf.name)123 # Trying to load from a group with more than one dataset without124 # specifying a dataset_name should raise a ValueError125 assert_raises(ValueError, SimulationResult.load, tf.name,126 group_name=model.name)127 # Load should succeed when specifying group_name and dataset_name128 simres_load = SimulationResult.load(tf.name, group_name=model.name,129 dataset_name='test')130 assert simres_load._model.name == test_unicode_name131 # Saving network free results requires include_obs_exprs=True,132 # otherwise a warning should be raised133 with warnings.catch_warnings(record=True) as w:134 warnings.simplefilter("always", UserWarning)135 nfres1.save(tf.name, dataset_name='nfsim_no_obs', append=True)136 assert len(w) == 1137 nfres1.save(tf.name, include_obs_exprs=True,138 dataset_name='nfsim test', append=True)139 # NFsim load140 nfres1_load = SimulationResult.load(tf.name,141 group_name=nfres1._model.name,142 dataset_name='nfsim test')143 # NFsim with expression144 nfres2.save(tf.name, include_obs_exprs=True, append=True)145 nfres2_load = SimulationResult.load(tf.name,146 group_name=nfres2._model.name)147 _check_resultsets_equal(simres, simres_load)148 _check_resultsets_equal(nfres1, nfres1_load)149 _check_resultsets_equal(nfres2, nfres2_load)150def test_save_load_observables_expressions():151 buff = io.BytesIO()152 tspan = np.linspace(0, 100, 100)153 sim = ScipyOdeSimulator(tyson_oscillator.model, tspan).run()154 sim.save(buff, include_obs_exprs=True)155 sim2 = SimulationResult.load(buff)156 assert len(sim2.observables) == len(tspan)157 # Tyson oscillator doesn't have expressions158 assert_raises(ValueError, lambda: sim2.expressions)159def _check_resultsets_equal(res1, res2):160 try:161 assert np.allclose(res1.species, res2.species)162 except ValueError:163 # Network free simulations don't have species164 pass165 assert np.allclose(res1.tout, res2.tout)166 assert np.allclose(res1.param_values, res2.param_values)167 168 if isinstance(res1.initials, np.ndarray):169 assert np.allclose(res1.initials, res2.initials)170 else:171 for k, v in res1.initials.items():172 assert np.allclose(res1.initials[k], v)173 assert np.allclose(res1._yobs_view, res2._yobs_view)174 if res1._model.expressions_dynamic():175 assert np.allclose(res1._yexpr_view, res2._yexpr_view)176 assert res1.squeeze == res2.squeeze177 assert res1.simulator_class == res2.simulator_class178 assert res1.init_kwargs == res2.init_kwargs179 assert res1.run_kwargs == res2.run_kwargs180 assert res1.n_sims_per_parameter_set == \181 res2.n_sims_per_parameter_set182 assert res1._model.name == res2._model.name183 assert res1.timestamp == res2.timestamp184 assert res1.pysb_version == res2.pysb_version...

Full Screen

Full Screen

test_fonts.py

Source:test_fonts.py Github

copy

Full Screen

...9 with ZipFile(os.path.join(os.path.dirname(__file__),10 'unicode_font.zip'), 'r') as myzip:11 myzip.extractall(path=os.path.dirname(__file__))12 print(self.font_name)13 def test_unicode_name(self):14 from kivy.core.text import Label15 lbl = Label(font_name=self.font_name)16 lbl.refresh()17 self.assertNotEqual(lbl.get_extents(''), None)18 def tearDown(self):19 import os20 if os.path.exists(self.font_name):...

Full Screen

Full Screen

test_utils_script.py

Source:test_utils_script.py Github

copy

Full Screen

1import os2import unittest3from avocado.utils import script4class TestTemporary(unittest.TestCase):5 def test_unicode_name(self):6 path = u'\u00e1 \u00e9 \u00ed \u00f3 \u00fa'7 content = "a e i o u"8 with script.TemporaryScript(path, content) as temp_script:9 self.assertTrue(os.path.exists(temp_script.path))10 with open(temp_script.path) as temp_script_file:11 self.assertEqual(content, temp_script_file.read())12if __name__ == "__main__":...

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 avocado 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