How to use fixture0 method in Slash

Best Python code snippet using slash

test_fixture_mechanism.py

Source:test_fixture_mechanism.py Github

copy

Full Screen

...24 for i in [1, 2, 3]:25 assert d['fixture{}'.format(i)] == i26def test_fixture_id_remains_even_when_context_popped(store):27 @slash.fixture28 def fixture0():29 pass30 store.push_namespace()31 store.add_fixture(fixture0)32 store.resolve()33 fixture_obj = store.get_fixture_by_name('fixture0')34 assert fixture_obj.fixture_func is fixture035 fixture_id = fixture_obj.info.id36 assert store.get_fixture_by_id(fixture_id) is fixture_obj37 store.pop_namespace()38 with pytest.raises(UnknownFixtures):39 store.get_fixture_by_name('fixture0')40 assert store.get_fixture_by_id(fixture_id) is fixture_obj41def test_namespace_get_fixture_by_name_default(store):42 obj = object()43 assert store.get_current_namespace().get_fixture_by_name('nonexisting', default=obj) is obj44def test_namespace_get_fixture_by_name_no_default(store):45 ns = store.get_current_namespace()46 with pytest.raises(UnknownFixtures):47 ns.get_fixture_by_name('nonexisting')48def test_variations_no_names(store):49 assert list(store.iter_parametrization_variations([])) == [{}]50def test_adding_fixture_twice_to_store(store):51 @slash.fixture52 def fixture0():53 pass54 store.add_fixture(fixture0)55 fixtureobj = store.get_fixture_by_name('fixture0')56 store.add_fixture(fixture0)57 assert store.get_fixture_by_name('fixture0') is fixtureobj58def test_fixture_store_namespace_repr(store):59 @store.add_fixture60 @slash.fixture61 def fixture0():62 pass63 ns = store.get_current_namespace()64 assert str(ns) == repr(ns)65 assert repr(ns) == 'Fixture NS#0: fixture0'66def test_fixture_parameters(store):67 @store.add_fixture68 @slash.fixture69 def value(x, a):70 assert a == 'a', 'Fixture got unexpectedly overriden by parameter'71 return x72 @store.add_fixture73 @slash.fixture74 def a():75 return 'a'76 @store.add_fixture77 @slash.fixture78 @slash.parametrize('a', [1, 2, 3])79 def x(a, b):80 return (a, b)81 @store.add_fixture82 @slash.parametrize('b', [4, 5, 6])83 @slash.fixture84 def b(b):85 return b86 store.resolve()87 with slash.Session():88 variations = list(_get_all_values(store, 'value'))89 assert set(variations) == set(itertools.product([1, 2, 3], [4, 5, 6]))90def test_fixture_tuple_parameters(store):91 @store.add_fixture92 @slash.fixture93 @slash.parametrize(('a', 'b'), [(1, 2), (3, 4)])94 def x(a, b):95 return a + b96 store.resolve()97 with slash.Session():98 variations = list(_get_all_values(store, 'x'))99 assert variations == [3, 7]100def test_variation_equality(store):101 @store.add_fixture102 @slash.fixture103 @slash.parametrize('a', [1, 2, 3])104 def fixture(a):105 pass106 store.resolve()107 prev_variation = None108 for variation in store.iter_parametrization_variations(fixture_ids=[store.get_fixture_by_name('fixture').info.id]):109 assert variation == variation110 assert not (variation != variation) # pylint: disable=superfluous-parens111 assert variation != prev_variation112 assert not (variation == prev_variation) # pylint: disable=superfluous-parens113 prev_variation = variation114def _get_all_values(store, fixture_name):115 returned = []116 for variation in store.iter_parametrization_variations(fixture_ids=[store.get_fixture_by_name(fixture_name).info.id]):117 store.push_scope('test')118 with bound_parametrizations_context(variation, store, store.get_current_namespace()):119 returned.append(120 store.get_fixture_dict([fixture_name])[fixture_name])121 store.pop_scope('test')122 return returned123@pytest.mark.parametrize('scopes', [('module', 'test'), ('session', 'module'), ('session', 'test')])124def test_wrong_scoping(store, scopes):125 @store.add_fixture126 @slash.fixture(scope=scopes[0])127 def fixture1(fixture2):128 pass129 @store.add_fixture130 @slash.fixture(scope=scopes[1])131 def fixture2():132 pass133 with pytest.raises(InvalidFixtureScope):134 store.resolve()135def test_this_argument(store):136 @store.add_fixture137 @slash.fixture138 def sample(this, other):139 assert this.name == 'sample'140 assert other == 'ok_other'141 return 'ok_sample'142 @store.add_fixture143 @slash.fixture144 def other(this):145 assert this.name == 'other'146 return 'ok_other'147 store.resolve()148 assert store.get_fixture_dict(['sample']) == {149 'sample': 'ok_sample',150 }151def test_fixture_store_unresolved(store):152 @store.add_fixture153 @slash.fixture154 def some_fixture(a, b, c):155 return a + b + c156 with pytest.raises(UnresolvedFixtureStore):157 store.get_fixture_dict(['some_fixture'])158def test_fixture_store_resolve_missing_fixtures(store):159 @store.add_fixture160 @slash.fixture161 def some_fixture(a, b, c):162 return a + b + c163 with pytest.raises(UnknownFixtures):164 store.resolve()165def test_get_all_needed_fixture_ids(store):166 @store.add_fixture167 @slash.fixture168 @slash.parametrize('param', [1, 2, 3])169 def fixture1(param): # pylint: disable=unused-argument170 pass171 @store.add_fixture172 @slash.fixture173 def fixture2(fixture1): # pylint: disable=unused-argument174 pass175 @store.add_fixture176 @slash.fixture177 @slash.parametrize('param', [4, 5, 6])178 def fixture3(fixture2, param): # pylint: disable=unused-argument179 pass180 fixtureobj = store.get_fixture_by_id(fixture3.__slash_fixture__.id)181 with pytest.raises(UnresolvedFixtureStore):182 store.get_all_needed_fixture_ids(fixtureobj)183 store.resolve()184 assert len(set(store.get_all_needed_fixture_ids(fixtureobj))) == 2185def test_get_all_needed_fixture_ids_of_parametrization(store):186 @store.add_fixture187 @slash.fixture188 @slash.parametrize('param', [1, 2, 3])189 def fixture1(param): # pylint: disable=unused-argument190 pass191 fixtureobj = store.get_fixture_by_id(fixture1.__slash_fixture__.id)192 [(_, param_fixtureobj)] = iter_parametrization_fixtures(fixture1)193 with pytest.raises(UnresolvedFixtureStore):194 store.get_all_needed_fixture_ids(fixtureobj)195 store.resolve()196 needed = set(store.get_all_needed_fixture_ids(param_fixtureobj))197 assert len(needed) == 1198 assert needed == set([param_fixtureobj.info.id])199def test_fixture_store_iter_parametrization_variations_missing_fixtures(store):200 def test_func(needed_fixture):201 pass202 with pytest.raises(UnknownFixtures):203 list(store.iter_parametrization_variations(funcs=[test_func]))204def test_fixture_store_iter_parametrization_variations_unresolved(store):205 @store.add_fixture206 @slash.fixture207 @slash.parametrize('x', [1, 2, 3])208 def needed_fixture(x):209 pass210 def test_func(needed_fixture):211 pass212 with pytest.raises(UnresolvedFixtureStore):213 list(store.iter_parametrization_variations(funcs=[test_func]))214def test_fixture_dependency(store):215 counter = itertools.count()216 @store.add_fixture217 @slash.fixture218 def fixture1(fixture2):219 assert fixture2 == 'fixture2_value_0'220 return 'fixture1_value_{}'.format(next(counter))221 @store.add_fixture222 @slash.fixture223 def fixture2():224 return 'fixture2_value_{}'.format(next(counter))225 store.resolve()226 assert store.get_fixture_dict(['fixture1', 'fixture2']) == {227 'fixture1': 'fixture1_value_1',228 'fixture2': 'fixture2_value_0',229 }230def test_nested_store_resolution_activation(store):231 store.push_namespace()232 @store.add_fixture233 @slash.fixture234 def fixture0():235 return '0'236 store.push_namespace()237 @store.add_fixture238 @slash.fixture239 def fixture1(fixture0):240 assert fixture0 == '0'241 return '1'242 store.push_namespace()243 @store.add_fixture244 @slash.fixture245 def fixture2(fixture1, fixture0):246 assert fixture0 == '0'247 assert fixture1 == '1'248 return '2'...

Full Screen

Full Screen

perf_process.py

Source:perf_process.py Github

copy

Full Screen

1""""""2from __future__ import division # 1/2 == 0.5, as in Py33from __future__ import absolute_import # avoid hiding global modules with locals4from __future__ import print_function # force use of print("hello")5from __future__ import unicode_literals # force unadorned strings "" to be unicode without prepending u""6import subprocess7import unittest8import os9FIXTURE0 = """ 0.100167119 3,183 cache-misses """10ANSWER0 = 318311FIXTURE1 = """# time counts events\n 0.100167119 3,183 cache-misses \n 0.200354348 4,045 cache-misses \n """12ANSWER1 = [3183, 4045]13FIXTURE2 = """ 3.501390851 471,219,787 stalled-cycles-frontend\n 14.005319456 2,249,115 stalled-cycles-frontend """14ANSWER2 = [471219787, 2249115]15EVENT_TYPE_CM = "cache-misses"16EVENT_TYPE_SCF = "stalled-cycles-frontend"17EVENT_TYPE_I = "instructions"18EVENT_TYPES = set([EVENT_TYPE_CM, EVENT_TYPE_SCF, EVENT_TYPE_I])19EVENT_TYPE = EVENT_TYPE_CM20def process_line(line):21 """Process a single output line from perf-stat, extract only a value (skip help lines)"""22 line_bits = line.split()23 #print(line_bits)24 try:25 value = float(line_bits[1].replace(',', ''))26 except ValueError:27 if line_bits[2] in EVENT_TYPES:28 # we only get here if we've got a value and a key29 key = line_bits[2]30 value = None31 except IndexError:32 value = None33 return value34def process_lines(lines):35 """Process many lines of perf-stat output, extract the values"""36 # we're assuming we have \n as line endings in this long string37 values = []38 for line in lines.split('\n'):39 value = process_line(line)40 if value:41 values.append(value)42 return values43class Test(unittest.TestCase):44 def test1(self):45 answer0 = process_line(FIXTURE0)46 self.assertEqual(ANSWER0, answer0)47 def test_process_lines(self):48 values = process_lines(FIXTURE0)49 self.assertEqual(values, [ANSWER0])50 def test_process_lines2(self):51 # check we can process the cache-misses messages52 values = process_lines(FIXTURE1)53 self.assertEqual(values, ANSWER1)54 # check that if we have repeated help messages, we still extract the55 # values we expect56 values = process_lines(FIXTURE1+FIXTURE1)57 self.assertEqual(values, ANSWER1+ANSWER1)58 def test_process_lines3(self):59 # check we can process stalled-cycles-frontend messages60 values = process_lines(FIXTURE2)61 self.assertEqual(values, ANSWER2)62def run_capture_perf(pid):63 """Start a perf stat process monitoring pid every 100ms"""64 cmd = "perf stat --pid {pid} --event {event_type} -I 100".format(pid=pid, event_type=EVENT_TYPE)65 #print("run_capture_perf running:", cmd) # debug message66 proc = subprocess.Popen(cmd.split(), stderr=subprocess.PIPE)67 return proc68def finish_perf(proc):69 """Finish collecting data, parse and return"""70 # once the job has finished, kill recording71 proc.kill()72 # now block to gather all output data73 (stdoutdata, stderrdata) = proc.communicate()74 # example stderrdata output:75 # # time counts events76 # 0.100173796 2,761 cache-misses77 # 0.200387519 4,232 cache-misses78 # 0.300540762 5,277 cache-misses79 # 0.400778748 3,916 cache-misses80 stderrdata = stderrdata.decode('ascii') # assume ascii81 values = process_lines(stderrdata)82 return values83if __name__ == "__main__":84 # simple test for a hardcoded pid gathered over 0.5 seconds85 pid = os.getpid()86 print("Using pid:", pid)87 proc = run_capture_perf(pid)88 import time89 time.sleep(0.5)90 values = finish_perf(proc)...

Full Screen

Full Screen

test0.py

Source:test0.py Github

copy

Full Screen

1import pytest2from django.contrib.auth.models import User3@pytest.fixture(scope='class')4def fixture0():5 alto = User.objects.create_user('foo', password='foo')6 return7@pytest.mark.django_db8def test0(fixture0):...

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