Best Python code snippet using gabbi_python
test_deterministic_cache.py
Source: test_deterministic_cache.py
1import os2import pathlib3import pickle4import unittest5import axelrod as axl6from axelrod.load_data_ import axl_filename7C, D = axl.Action.C, axl.Action.D8class TestDeterministicCache(unittest.TestCase):9 @classmethod10 def setUpClass(cls):11 cls.test_key = (axl.TitForTat(), axl.Defector())12 cls.test_value = [(C, D), (D, D), (D, D)]13 save_path = pathlib.Path("test_outputs/test_cache_save.txt")14 cls.test_save_file = axl_filename(save_path)15 load_path = pathlib.Path("test_outputs/test_cache_load.txt")16 cls.test_load_file = axl_filename(load_path)17 test_data_to_pickle = {18 ("Tit For Tat", "Defector"): [(C, D), (D, D), (D, D)]19 }20 cls.test_pickle = pickle.dumps(test_data_to_pickle)21 with open(cls.test_load_file, "wb") as f:22 f.write(cls.test_pickle)23 @classmethod24 def tearDownClass(cls):25 os.remove(cls.test_save_file)26 os.remove(cls.test_load_file)27 def setUp(self):28 self.cache = axl.DeterministicCache()29 def test_basic_init(self):30 self.assertTrue(self.cache.mutable)31 def test_init_from_file(self):32 loaded_cache = axl.DeterministicCache(file_name=self.test_load_file)33 self.assertEqual(loaded_cache[self.test_key], self.test_value)34 def test_setitem(self):35 self.cache[self.test_key] = self.test_value36 self.assertEqual(self.cache[self.test_key], self.test_value)37 def test_setitem_invalid_key_not_tuple(self):38 invalid_key = "test"39 with self.assertRaises(ValueError):40 self.cache[invalid_key] = self.test_value41 def test_setitem_invalid_key_first_two_elements_not_player(self):42 invalid_key = ("test", "test")43 with self.assertRaises(ValueError):44 self.cache[invalid_key] = self.test_value45 invalid_key = (axl.TitForTat(), "test")46 with self.assertRaises(ValueError):47 self.cache[invalid_key] = self.test_value48 invalid_key = ("test", axl.TitForTat())49 with self.assertRaises(ValueError):50 self.cache[invalid_key] = self.test_value51 def test_setitem_invalid_key_too_many_players(self):52 invalid_key = (axl.TitForTat(), axl.TitForTat(), axl.TitForTat())53 with self.assertRaises(ValueError):54 self.cache[invalid_key] = self.test_value55 def test_setitem_invalid_key_stochastic_player(self):56 invalid_key = (axl.Random(), axl.TitForTat())57 with self.assertRaises(ValueError):58 self.cache[invalid_key] = self.test_value59 invalid_key = (axl.TitForTat(), axl.Random())60 with self.assertRaises(ValueError):61 self.cache[invalid_key] = self.test_value62 def test_setitem_invalid_value_not_list(self):63 with self.assertRaises(ValueError):64 self.cache[self.test_key] = 565 def test_setitem_with_immutable_cache(self):66 self.cache.mutable = False67 with self.assertRaises(ValueError):68 self.cache[self.test_key] = self.test_value69 def test_save(self):70 self.cache[self.test_key] = self.test_value71 self.cache.save(self.test_save_file)72 with open(self.test_save_file, "rb") as f:73 text = f.read()74 self.assertEqual(text, self.test_pickle)75 def test_load(self):76 self.cache.load(self.test_load_file)77 self.assertEqual(self.cache[self.test_key], self.test_value)78 def test_load_error_for_inccorect_format(self):79 path = pathlib.Path("test_outputs/test.cache")80 filename = axl_filename(path)81 with open(filename, "wb") as io:82 pickle.dump(range(5), io)83 with self.assertRaises(ValueError):84 self.cache.load(filename)85 def test_del_item(self):86 self.cache[self.test_key] = self.test_value87 self.assertTrue(self.test_key in self.cache)88 del self.cache[self.test_key]...
serializer.py
Source: serializer.py
...28 with open(file_path, 'w') as f:29 d = list(map(lambda obj: obj.to_dict(), l))30 text = json.dumps(d, default=serialize_instance)31 f.write(text)32def test_load_file():33 a = Toppic()34 a.toppic_id = 135 a.link = "https://www.douban.com/group/topic/105114253"36 a.score = 137 b = Toppic()38 b.toppic_id = 239 b.link = "https://www.douban.com/group/topic/2354"40 b.score = 1041 b.time = datetime.datetime.now()42 tempfile = '._temp'43 save_data_file([a, b], tempfile)44 result = load_data_file(tempfile)45 os.remove(tempfile)46 assert result[0] == a and result[1] == b47if __name__ == '__main__':...
test_url_utilities.py
Source: test_url_utilities.py
1import unittest2from utilities.url_utilities import load_urls_from_file3#4# def test_load_file():5# test_urls = load_urls_from_file("input.txt")6# assert (len(test_urls) > 1)7class UrlUtilitiesTest(unittest.TestCase):8 def setUp(self) -> None:9 pass10 def tearDown(self) -> None:11 pass12 def test_load_file(self):13 test_urls = load_urls_from_file("../../input.txt")...
Check out the latest blogs from LambdaTest on this topic:
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
Have you ever struggled with handling hidden elements while automating a web or mobile application? I was recently automating an eCommerce application. I struggled with handling hidden elements on the web page.
Agile has unquestionable benefits. The mainstream method has assisted numerous businesses in increasing organizational flexibility as a result, developing better, more intuitive software. Distributed development is also an important strategy for software companies. It gives access to global talent, the use of offshore outsourcing to reduce operating costs, and round-the-clock development.
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.
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!!