Best Python code snippet using lemoncheesecake
test_fixtures.py
Source:test_fixtures.py
...117 @lcc.fixture()118 def myfixture():119 return 42120 registry = FixtureRegistry()121 registry.add_fixtures(load_fixtures_from_func(myfixture))122 registry.check_dependencies()123def test_registry_fixture_with_params():124 @lcc.fixture()125 def foo():126 return 21127 @lcc.fixture()128 def bar(foo):129 return foo * 2130 registry = FixtureRegistry()131 registry.add_fixtures(load_fixtures_from_func(foo))132 registry.add_fixtures(load_fixtures_from_func(bar))133 registry.check_dependencies()134def test_registry_fixture_missing_dependency():135 @lcc.fixture()136 def bar(foo):137 return foo * 2138 registry = FixtureRegistry()139 registry.add_fixtures(load_fixtures_from_func(bar))140 with pytest.raises(exceptions.LemoncheesecakeException) as excinfo:141 registry.check_dependencies()142 assert "does not exist" in str(excinfo.value)143def test_registry_fixture_circular_dependency_direct():144 @lcc.fixture()145 def foo(bar):146 return bar * 2147 @lcc.fixture()148 def bar(foo):149 return foo * 2150 registry = FixtureRegistry()151 registry.add_fixtures(load_fixtures_from_func(foo))152 registry.add_fixtures(load_fixtures_from_func(bar))153 with pytest.raises(exceptions.LemoncheesecakeException) as excinfo:154 registry.get_fixture_dependencies("foo")155 assert 'circular' in str(excinfo.value)156def test_registry_fixture_circular_dependency_indirect():157 @lcc.fixture()158 def baz(foo):159 return foo * 2160 @lcc.fixture()161 def bar(baz):162 return baz * 2163 @lcc.fixture()164 def foo(bar):165 return bar * 2166 registry = FixtureRegistry()167 registry.add_fixtures(load_fixtures_from_func(foo))168 registry.add_fixtures(load_fixtures_from_func(bar))169 registry.add_fixtures(load_fixtures_from_func(baz))170 with pytest.raises(exceptions.LemoncheesecakeException) as excinfo:171 registry.get_fixture_dependencies("foo")172 assert 'circular' in str(excinfo.value)173def test_registry_fixture_circular_dependency_indirect_2():174 @lcc.fixture()175 def baz(bar):176 return bar * 2177 @lcc.fixture()178 def bar(baz):179 return baz * 2180 @lcc.fixture()181 def foo(bar):182 return bar * 2183 registry = FixtureRegistry()184 registry.add_fixtures(load_fixtures_from_func(foo))185 registry.add_fixtures(load_fixtures_from_func(bar))186 registry.add_fixtures(load_fixtures_from_func(baz))187 with pytest.raises(exceptions.LemoncheesecakeException) as excinfo:188 registry.get_fixture_dependencies("foo")189 assert 'circular' in str(excinfo.value)190def test_registry_fixture_name():191 @lcc.fixture()192 def foo(fixture_name):193 pass194 registry = FixtureRegistry()195 registry.add_fixtures(load_fixtures_from_func(foo))196 registry.check_dependencies()197def test_registry_get_fixture_without_param_dependency():198 @lcc.fixture()199 def foo():200 return 42201 registry = FixtureRegistry()202 registry.add_fixtures(load_fixtures_from_func(foo))203 assert registry.get_fixture_dependencies("foo") == []204def test_registry_get_fixture_with_param_dependency():205 @lcc.fixture()206 def bar():207 return 21208 @lcc.fixture()209 def foo(bar):210 return bar * 2211 registry = FixtureRegistry()212 registry.add_fixtures(load_fixtures_from_func(foo))213 registry.add_fixtures(load_fixtures_from_func(bar))214 assert registry.get_fixture_dependencies("foo") == ["bar"]215def test_registry_get_fixture_with_params_dependency():216 @lcc.fixture()217 def zoub():218 return 21219 @lcc.fixture()220 def baz(zoub):221 return zoub222 @lcc.fixture()223 def bar(baz):224 return baz * 2225 @lcc.fixture()226 def foo(bar, baz):227 return bar * baz228 registry = FixtureRegistry()229 registry.add_fixtures(load_fixtures_from_func(foo))230 registry.add_fixtures(load_fixtures_from_func(bar))231 registry.add_fixtures(load_fixtures_from_func(baz))232 registry.add_fixtures(load_fixtures_from_func(zoub))233 assert registry.get_fixture_dependencies("foo") == ["zoub", "baz", "bar"]234def test_registry_compatible_scope():235 @lcc.fixture(scope="session")236 def bar():237 return 21238 @lcc.fixture(scope="test")239 def foo(bar):240 return bar * 2241 registry = FixtureRegistry()242 registry.add_fixtures(load_fixtures_from_func(foo))243 registry.add_fixtures(load_fixtures_from_func(bar))244 registry.check_dependencies()245def test_registry_incompatible_scope():246 @lcc.fixture(scope="test")247 def bar():248 return 21249 @lcc.fixture(scope="session")250 def foo(bar):251 return bar * 2252 registry = FixtureRegistry()253 registry.add_fixtures(load_fixtures_from_func(foo))254 registry.add_fixtures(load_fixtures_from_func(bar))255 with pytest.raises(exceptions.LemoncheesecakeException) as excinfo:256 registry.check_dependencies()257 assert 'incompatible' in str(excinfo.value)258def test_registry_forbidden_fixture_name():259 @lcc.fixture(scope="test")260 def fixture_name():261 return 0262 registry = FixtureRegistry()263 registry.add_fixtures(load_fixtures_from_func(fixture_name))264 with pytest.raises(exceptions.FixtureConstraintViolation) as excinfo:265 registry.check_dependencies()266 assert "forbidden" in str(excinfo.value)267def build_registry():268 @lcc.fixture(scope="pre_run")269 def fix0():270 pass271 @lcc.fixture(scope="session")272 def fix1():273 pass274 @lcc.fixture(scope="suite")275 def fix2():276 pass277 @lcc.fixture(scope="test")278 def fix3():279 pass280 @lcc.fixture(names=["fix4", "fix5"])281 def fix_():282 pass283 registry = FixtureRegistry()284 for func in fix0, fix1, fix2, fix3, fix_:285 registry.add_fixtures(load_fixtures_from_func(func))286 return registry287def test_check_fixtures_in_suites_ok():288 @lcc.suite("MySuite")289 class MySuite:290 @lcc.suite("MySubSuite")291 class MySubSuite:292 @lcc.test("test")293 def sometest(self, fix1):294 pass295 suite = load_suite_from_class(MySuite)296 registry = build_registry()297 registry.check_fixtures_in_suites([suite])298def test_check_fixtures_in_suites_unknown_fixture_in_test():299 @lcc.suite("MySuite")...
test_poll.py
Source:test_poll.py
...15def pull_foreach_userid(list_of_userid):16 req_urls = []17 expected_urls = map(helpers.match_history_uri, list_of_userid)18 httpretty.enable()19 add_fixtures(lambda _, uri, __: req_urls.append(uri))20 Poll().match_tokens(list_of_userid)21 assert req_urls == expected_urls22 teardown()23@then('it should return the match tokens')24def return_tokens(list_of_userid):25 httpretty.enable()26 add_fixtures()27 result = Poll().match_tokens(list_of_userid)28 expected_tokens = [29 (u'136200860', u'2015-02-07'),30 (u'136199918', u'2015-02-07'),31 (u'136199362', u'2015-02-07'),32 (u'136198877', u'2015-02-07'),33 (u'136097421', u'2015-02-03'),34 (u'136095625', u'2015-02-03'),35 (u'136028023', u'2015-02-01'),36 (u'136026090', u'2015-02-01'),37 (u'136020720', u'2015-02-01'),38 (u'136023435', u'2015-01-01')39 ]40 assert result == expected_tokens41 teardown()42# --- polling matches ---43@scenario('poll.feature', 'Polling matches')44def test_polling_matches():45 pass46@given('a list of match tokens')47def list_of_token():48 return [49 ('136200860', '2015-03-15'),50 ('136199918', '2015-04-15')51 ]52@then('it should pull the matches')53def pull_matches(list_of_token):54 match_ids_slug = "136200860+136199918"55 req_urls = []56 expected_url = helpers.multi_match_uri(match_ids_slug)57 httpretty.enable()58 add_fixtures(lambda _, uri, __: req_urls.append(uri))59 Poll().matches(list_of_token)60 matches_url = req_urls[0]61 assert matches_url == expected_url62 teardown()63@then('it should return the match data')64def return_matches(list_of_token):65 httpretty.enable()66 add_fixtures()67 result = Poll().matches(list_of_token)68 first = result[0]69 assert first['date'] == '2015-04-15'70 teardown()71# --- polling matches ---72@scenario('poll.feature', 'Polling player stats')73def test_polling_player_stats():74 pass75@then('it should pull player stats for each userid')76def poll_player_stats(list_of_userid):77 req_urls = []78 expected_urls = map(helpers.player_stats_uri, list_of_userid)79 httpretty.enable()80 add_fixtures(lambda _, uri, __: req_urls.append(uri))81 Poll().player_stats(list_of_userid)82 assert req_urls == expected_urls83 teardown()84@then('it should return the player stats')85def return_player_stats(list_of_userid):86 httpretty.enable()87 add_fixtures()88 result = Poll().player_stats(list_of_userid)89 today = time.strftime("%Y-%m-%d")90 assert result['date'] == today91 assert result['data'] == {92 'Schln': {93 'nickname': 'Schln',94 'mmr': '1574.691',95 'games_played': '1843',96 'wins': '914',97 'losses': '929',98 'concedes': '851',99 'concedevotes': '174',100 'buybacks': '66',101 'wards': '8138',102 'consumables': '11549',103 'actions': '9068281',104 'bloodlust': '158',105 'doublekill': '523',106 'triplekill': '45',107 'quadkill': '3',108 'annihilation': '0',109 'ks3': '512',110 'ks4': '237',111 'ks5': '135',112 'ks6': '68',113 'ks7': '37',114 'ks8': '21',115 'ks9': '12',116 'ks10': '9',117 'ks15': '0',118 'seconds_played': '4045284',119 'seconds_dead': '439133',120 'seconds_earning_exp': '4040452',121 'disconnects': '6',122 'kicked': '0',123 'level': '39',124 'deaths': '10986',125 'herokills': '6935',126 'heroassists': '18994',127 'smackdown': '0',128 'humiliation': '10',129 'nemesis': '5552',130 'retribution': '171',131 },132 'skepparn_': {133 'nickname': 'skepparn_',134 'mmr': '1550.637',135 'games_played': '1166',136 'wins': '585',137 'losses': '581',138 'concedes': '529',139 'concedevotes': '142',140 'buybacks': '114',141 'wards': '4957',142 'consumables': '9805',143 'actions': '4586202',144 'bloodlust': '112',145 'doublekill': '404',146 'triplekill': '48',147 'quadkill': '8',148 'annihilation': '0',149 'ks3': '345',150 'ks4': '183',151 'ks5': '74',152 'ks6': '37',153 'ks7': '24',154 'ks8': '12',155 'ks9': '11',156 'ks10': '7',157 'ks15': '0',158 'seconds_played': '2531580',159 'seconds_dead': '400039',160 'seconds_earning_exp': '2525213',161 'disconnects': '3',162 'kicked': '0',163 'level': '31',164 'deaths': '7535',165 'herokills': '4717',166 'heroassists': '12061',167 'smackdown': '0',168 'humiliation': '1',169 'nemesis': '3617',170 'retribution': '143',171 }172 }173 teardown()174 pass175# --- helpers ---176def add_fixtures(response_cb=None):177 def cb(req, uri, headers):178 if response_cb is not None:179 response_cb(req, uri, headers)180 body = helpers.fixture_for(uri)181 return (200, headers, body)182 httpretty.register_uri(httpretty.GET,183 re.compile("(.*)"),184 body=cb,185 content_type="application/json")186def teardown():187 httpretty.disable()...
0002_fixtures.py
Source:0002_fixtures.py
...9 fixtures_file = os.path.join(FIXTURE_DIR, 'fixtures.json')10 with open(fixtures_file) as fixtures_data:11 fixtures = json.loads(fixtures_data.read()) 12 # Create tutorial project13 add_fixtures(apps, fixtures, "Tutorials")14 # Create example project15 add_fixtures(apps, fixtures, "Examples")16def add_fixtures(apps, fixtures, title):17 Project = apps.get_model("frontend", "Project")18 File = apps.get_model("frontend", "File")19 20 project = Project(name=title, example=True)21 project.save()22 for fixture in fixtures.get(title, []):23 figure = File(**fixture)24 code_path = os.path.join(FIXTURE_DIR, title, figure.name)25 with open(code_path, 'r') as code:26 figure.code = code.read()27 figure.project = project28 figure.save()29class Migration(migrations.Migration):30 dependencies = [...
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!!