Best Python code snippet using lemoncheesecake
test_core.py
Source:test_core.py
...90 @test91 def other_test():92 pass93 @test94 def yet_another_test():95 pass96 @test(runs_after=[yet_another_test])97 class ExampleTest(object):98 @test(runs_after=[other_test])99 def test_1(self):100 pass101 for t in self.registry.tests:102 if t.home is ExampleTest:103 assert_equal(1, len(t.info.runs_after))104 assert_true(yet_another_test in t.info.runs_after)105 elif t.home is get_method_function(ExampleTest.test_1):106 assert_equal(2, len(t.info.runs_after))107 expected_homes = {other_test:False, yet_another_test:False}108 for home in t.info.runs_after:...
test_read.py
Source:test_read.py
1import pytest2import fast_curator.read as fc_read3@pytest.fixture4def yaml_config_1(tmpdir):5 content = """6 datasets:7 - name: one8 eventtype: mc9 files: ["{prefix}one", "two"]10 prefix: SOME_prefix/11 """12 tmpfile = tmpdir / "curator_yaml_config_1.yml"13 tmpfile.write(content)14 return str(tmpfile)15@pytest.fixture16def yaml_config_2(yaml_config_1, tmpdir):17 content = """18 import:19 - "{this_dir}/curator_yaml_config_1.yml"20 datasets:21 - name: two22 eventtype: mc23 files: ["one", "two", "{prefix}three"]24 prefix:25 - default: SOME_prefix/26 - second: another_one_PREFIX/27 """28 tmpfile = tmpdir / "curator_yaml_config_2.yml"29 tmpfile.write(content)30 return str(tmpfile)31@pytest.fixture32def yaml_config_3(tmpdir):33 content = """34 datasets:35 - name: one36 eventtype: mc37 files: ["{prefix}one", "two"]38 prefix: SOME_prefix/39 nevents: !!int '77729'40 """41 tmpfile = tmpdir / "curator_yaml_config_3.yml"42 tmpfile.write(content)43 return str(tmpfile)44def test_from_yaml_1(yaml_config_1):45 datasets = fc_read.from_yaml(yaml_config_1)46 assert len(datasets) == 147def test_from_yaml_2(yaml_config_2):48 datasets = fc_read.from_yaml(yaml_config_2)49 assert len(datasets) == 250def test_from_yaml_3(yaml_config_3):51 datasets = fc_read.from_yaml(yaml_config_3)52 assert len(datasets) == 153def test__from_string():54 config = fc_read._from_string("dummy_data_1", {})55 assert len(config) == 156 assert config["name"] == "dummy_data_1"57 config = fc_read._from_string("dummy_data_2", default=dict(key="val"))58 assert len(config) == 259 assert config["name"] == "dummy_data_2"60 assert config["key"] == "val"61def test__from_dict():62 dataset = dict(one=1, two="2")63 with pytest.raises(RuntimeError) as e:64 fc_read._from_dict(dataset, {})65 assert "'name'" in str(e)66 dataset["name"] = "test__from_dict"67 config = fc_read._from_dict(dataset, dict(one="one", three=333))68 assert len(config.keys()) == 469 assert config["one"] == 170 assert config["two"] == "2"71 assert config["three"] == 33372def test_apply_prefix():73 files = ["{prefix}one", "{prefix}two/two", "three"]74 dataset = "test_apply_prefix"75 prefix = None76 result = fc_read.apply_prefix(prefix, files, None, dataset)77 assert len(result) == 378 assert result == files79 prefix = "testing/"80 result = fc_read.apply_prefix(prefix, files, None, dataset)81 assert len(result) == 382 assert result[0] == "testing/one"83 assert result[1] == "testing/two/two"84 assert result[2] == "three"85 prefix = [{"default": "another_test/"}, {"second": "yet_another_test/"}]86 result = fc_read.apply_prefix(prefix, files, None, dataset)87 assert len(result) == 388 assert result[0] == "another_test/one"89 assert result[1] == "another_test/two/two"90 assert result[2] == "three"91 result = fc_read.apply_prefix(prefix, files, "second", dataset)92 assert len(result) == 393 assert result[0] == "yet_another_test/one"94 assert result[1] == "yet_another_test/two/two"95 assert result[2] == "three"96 with pytest.raises(ValueError) as e:97 fc_read.apply_prefix(prefix, files, "invalid", dataset)98 assert "invalid" in str(e) and "not defined" in str(e)99 prefix = [dict(foo=1, bar=3)]100 with pytest.raises(ValueError) as e:101 fc_read.apply_prefix(prefix, files, None, dataset)102 assert "single-length dict" in str(e)103 prefix = dict(foo=1, bar=3)104 with pytest.raises(ValueError) as e:105 fc_read.apply_prefix(prefix, files, None, dataset)106 assert "string or a list" in str(e)107 prefix = [{"default": "another_test/"}, {"default": "yet_another_test/"}]108 with pytest.raises(ValueError) as e:109 fc_read.apply_prefix(prefix, files, "default", dataset)...
test_attributedict.py
Source:test_attributedict.py
1from tardis.utilities.attributedict import AttributeDict2from unittest import TestCase3class TestAttributeDict(TestCase):4 def setUp(self):5 self.test_dictionary = AttributeDict(test=1, another_test=2)6 def test_index_access(self):7 self.assertEqual(self.test_dictionary["test"], 1)8 self.assertEqual(self.test_dictionary["another_test"], 2)9 def test_access_via_attribute(self):10 self.assertEqual(self.test_dictionary.test, 1)11 self.assertEqual(self.test_dictionary.another_test, 2)12 def test_set_via_index(self):13 self.test_dictionary["test"] = 314 self.assertEqual(self.test_dictionary["test"], 3)15 self.test_dictionary["yet_another_test"] = 416 self.assertEqual(self.test_dictionary["yet_another_test"], 4)17 def test_set_via_attribute(self):18 self.test_dictionary.test = 319 self.assertEqual(self.test_dictionary.test, 3)20 self.test_dictionary.yet_another_test = 421 self.assertEqual(self.test_dictionary.yet_another_test, 4)22 def test_del_via_index(self):23 del self.test_dictionary["another_test"]24 with self.assertRaises(KeyError):25 self.test_dictionary["another_test"]26 def test_del_via_attribute(self):27 del self.test_dictionary.another_test28 with self.assertRaises(KeyError):29 self.test_dictionary["another_test"]30 with self.assertRaises(AttributeError):31 self.test_dictionary.another_test32 with self.assertRaises(AttributeError):...
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!!