How to use _create_config method in avocado

Best Python code snippet using avocado_python

test_config.py

Source: test_config.py Github

copy

Full Screen

...6 self._file = "a_file_path.ini"7 self._mock_file_manager = MagicMock()8 def test_new_config_has_no_items(self):9 # Act10 conf = self._create_config()11 # Assert12 items = conf.get_items()13 self.assertEqual(len(items), 0)14 def test_an_item_of_given_class_tag_and_default_value_can_be_added_to_config(self):15 # Arrange16 conf = self._create_config()17 tag = "Camera Number"18 default = -119 expected_value = None20 # Act21 conf.add(IntConfigItem, tag, default);22 # Assert23 item = conf.get_items()[0]24 self.assertTrue(isinstance(item, IntConfigItem))25 self.assertEqual(item.tag(), tag)26 self.assertEqual(item._default, default)27 self.assertEqual(item.value(), expected_value)28 def test_an_item_of_given_class_tag_default_value_and_extra_arg_can_be_added_to_config(self):29 # Arrange30 conf = self._create_config()31 tag = "Length"32 default = 10133 expected_value = None34 units = "m"35 # Act36 conf.add(IntConfigItem, tag, default, units)37 # Assert38 item = conf.get_items()[0]39 self.assertTrue(isinstance(item, IntConfigItem))40 self.assertEqual(item.tag(), tag)41 self.assertEqual(item._default, default)42 self.assertEqual(item.units(), units)43 self.assertEqual(item.value(), expected_value)44 def test_reset_all_sets_value_of_all_items_to_default(self):45 # Arrange46 conf = self._create_config()47 default_number = 048 default_width = 10049 new_number = 15550 new_width = 1551 conf.add(IntConfigItem, "Camera Number", default_number);52 conf.add(IntConfigItem, "Puck Camera Width", default_width)53 number_item = conf.get_items()[0]54 width_item = conf.get_items()[1]55 number_item.set(new_number)56 width_item.set(new_width)57 self.assertEqual(number_item.value(), new_number)58 self.assertEqual(width_item.value(), new_width)59 # Act60 conf.reset_all()61 # Assert62 self.assertEqual(number_item.value(), default_number)63 self.assertEqual(width_item.value(), default_width)64 def test_config_can_be_saved_to_file(self):65 # Arrange66 conf = self._create_config()67 conf.add(IntConfigItem, "Camera Number", -1, "m");68 conf.add(IntConfigItem, "Puck Camera Width", 100, "m")69 conf.add(IntConfigItem, "Puck Camera Height", 50, "m")70 camera_number_item = conf.get_items()[0]71 camera_w_item = conf.get_items()[1]72 camera_h_item = conf.get_items()[2]73 camera_number_item.set(155)74 camera_w_item.set(15)75 camera_h_item.set(3)76 expected_lines = []77 expected_lines.append(camera_number_item.to_file_string())78 expected_lines.append(camera_w_item.to_file_string())79 expected_lines.append(camera_h_item.to_file_string())80 # Act81 conf.save_to_file()82 # Assert83 self._mock_file_manager.write_lines.assert_called_once_with(self._file, expected_lines)84 def test_initialise_from_file_creates_new_file_using_default_values_if_the_given_file_does_not_exist(self):85 # Arrange86 self._mock_file_manager.is_file.return_value = False87 conf = self._create_config()88 default_value = 23489 conf.add(IntConfigItem, "Camera Number", default_value, "m");90 camera_number_item = conf.get_items()[0]91 self.assertIsNone(camera_number_item.value())92 # Act93 conf.initialize_from_file()94 # Assert95 self.assertEqual(camera_number_item.value(), default_value)96 expected_file_content = [camera_number_item.to_file_string()]97 self._mock_file_manager.write_lines.assert_called_once_with(self._file, expected_file_content)98 def test_initialise_from_file_does_not_write_to_file_if_the_given_file_exists(self):99 # Arrange100 self._mock_file_manager.is_file.return_value = True101 conf = self._create_config()102 conf.add(IntConfigItem, "Camera Number", 22, "m");103 # Act104 conf.initialize_from_file()105 # Assert106 self._mock_file_manager.write_lines.assert_not_called()107 def test_initialise_from_file_sets_default_if_pattern_broken_in_the_file(self):108 # Arrange109 self._mock_file_manager.is_file.return_value = True110 self._mock_file_manager.read_lines.return_value = ["Side Camera Number===1\n"]111 conf = self._create_config()112 default = 33113 conf.add(IntConfigItem, "Side Camera Number", default)114 item = conf.get_items()[0]115 self.assertIsNone(item.value())116 # Act117 conf.initialize_from_file()118 # Assert119 self.assertEqual(item.value(), default)120 def test_initialise_from_file_sets_default_if_tags_dont_match(self):121 # Arrange122 self._mock_file_manager.is_file.return_value = True123 self._mock_file_manager.read_lines.return_value = ["BadTagg=60\n"]124 conf = self._create_config()125 default = 500126 conf.add(IntConfigItem, "BadTag", default)127 item = conf.get_items()[0]128 self.assertIsNone(item.value())129 # Act130 conf.initialize_from_file()131 # Assert132 self.assertEqual(item.value(), default)133 def test_initialize_from_file_sets_value_from_file_if_tags_match(self):134 # Arrange135 expected_value = 10136 self._mock_file_manager.is_file.return_value = True137 self._mock_file_manager.read_lines.return_value = ["Camera Number=" + str(expected_value) + "\n"]138 conf = self._create_config()139 conf.add(IntConfigItem, "Camera Number", -1)140 # Act141 conf.initialize_from_file()142 # Assert143 item = conf.get_items()[0]144 self.assertEqual(item.value(), expected_value)145 def _create_config(self):...

Full Screen

Full Screen

test_utils_hydra_config.py

Source: test_utils_hydra_config.py Github

copy

Full Screen

...5from typing import List6from vissl.utils.hydra_config import compose_hydra_configuration, convert_to_attrdict7class TestUtilsHydraConfig(unittest.TestCase):8 @staticmethod9 def _create_config(overrides: List[str]):10 cfg = compose_hydra_configuration(overrides)11 args, config = convert_to_attrdict(cfg, dump_config=False)12 return config13 def test_composition_order(self):14 """15 Following Hydra 1.1 update, the composition order is modified:16 https:/​/​hydra.cc/​docs/​upgrades/​1.0_to_1.1/​default_composition_order/​17 This test verifies that the composition order is working on18 the hydra version installed by the user.19 """20 # Create a pre-training configuration for SwAV and21 # ensure that the composition was done correctly22 config = self._create_config(23 [24 "config=test/​integration_test/​quick_swav",25 "config.DATA.TRAIN.DATA_SOURCES=[synthetic]",26 "config.DATA.TRAIN.DATA_LIMIT=40",27 "config.DATA.TRAIN.BATCHSIZE_PER_REPLICA=4",28 "config.DISTRIBUTED.NUM_PROC_PER_NODE=2",29 ]30 )31 self.assertEqual("swav_loss", config.LOSS.name)32 self.assertEqual(2, config.DISTRIBUTED.NUM_PROC_PER_NODE)33 def test_inference_of_fsdp_settings_for_swav_pretraining(self):34 overrides = [35 "config=pretrain/​swav/​swav_8node_resnet",36 "+config/​pretrain/​swav/​models=regnet16Gf",37 "config.MODEL.AMP_PARAMS.USE_AMP=True",38 "config.OPTIMIZER.use_larc=True",39 ]40 cfg = self._create_config(overrides)41 self.assertEqual(cfg["MODEL"]["AMP_PARAMS"]["AMP_TYPE"], "apex")42 self.assertEqual(cfg.MODEL.HEAD.PARAMS[0][0], "swav_head")43 self.assertEqual(cfg.MODEL.TRUNK.NAME, "regnet")44 self.assertEqual(cfg.TRAINER.TASK_NAME, "self_supervision_task")45 self.assertEqual(cfg.OPTIMIZER.name, "sgd")46 cfg = self._create_config(47 overrides + ["config.MODEL.FSDP_CONFIG.AUTO_SETUP_FSDP=True"]48 )49 self.assertEqual(cfg["MODEL"]["AMP_PARAMS"]["AMP_TYPE"], "pytorch")50 self.assertEqual(cfg.MODEL.HEAD.PARAMS[0][0], "swav_head_fsdp")51 self.assertEqual(cfg.MODEL.TRUNK.NAME, "regnet_fsdp")52 self.assertEqual(cfg.TRAINER.TASK_NAME, "self_supervision_fsdp_task")53 self.assertEqual(cfg.OPTIMIZER.name, "sgd_fsdp")54 def test_inference_of_fsdp_settings_for_linear_evaluation(self):55 overrides = [56 "config=debugging/​benchmark/​linear_image_classification/​eval_resnet_8gpu_transfer_imagenette_160",57 "+config/​debugging/​benchmark/​linear_image_classification/​models=regnet16Gf_mlp",58 ]59 cfg = self._create_config(overrides)60 self.assertEqual(cfg.MODEL.HEAD.PARAMS[0][0], "mlp")61 self.assertEqual(cfg.MODEL.TRUNK.NAME, "regnet")62 self.assertEqual(cfg.TRAINER.TASK_NAME, "self_supervision_task")63 cfg = self._create_config(64 overrides + ["config.MODEL.FSDP_CONFIG.AUTO_SETUP_FSDP=True"]65 )66 self.assertEqual(cfg.MODEL.HEAD.PARAMS[0][0], "mlp_fsdp")67 self.assertEqual(cfg.MODEL.TRUNK.NAME, "regnet_fsdp")68 self.assertEqual(cfg.TRAINER.TASK_NAME, "self_supervision_fsdp_task")69 def test_inference_of_fsdp_settings_for_linear_evaluation_with_bn(self):70 overrides = [71 "config=debugging/​benchmark/​linear_image_classification/​eval_resnet_8gpu_transfer_imagenette_160",72 "+config/​debugging/​benchmark/​linear_image_classification/​models=regnet16Gf_eval_mlp",73 ]74 cfg = self._create_config(overrides)75 self.assertEqual(cfg.MODEL.HEAD.PARAMS[0][0], "eval_mlp")76 self.assertEqual(cfg.MODEL.TRUNK.NAME, "regnet")77 self.assertEqual(cfg.TRAINER.TASK_NAME, "self_supervision_task")78 cfg = self._create_config(79 overrides + ["config.MODEL.FSDP_CONFIG.AUTO_SETUP_FSDP=True"]80 )81 self.assertEqual(cfg.MODEL.HEAD.PARAMS[0][0], "eval_mlp_fsdp")82 self.assertEqual(cfg.MODEL.TRUNK.NAME, "regnet_fsdp")...

Full Screen

Full Screen

test-config.py

Source: test-config.py Github

copy

Full Screen

2import saplib3import unittest4class TestConfig(unittest.TestCase, fixtures.RepoFixture):5 def test_empty_config(self):6 self.assertEquals(0, len(self._create_config("splits = []").splits))7 self.assertEquals(0, len(self._create_config("").splits))8 self.assertEquals(0, len(self._create_config().splits))9 def test_invalid_split(self):10 self._assert_config_error("splits = [{}]")11 self._assert_config_error("splits = [{'paths': []}]")12 def test_simple_split(self):13 config = self._create_config("""14test = {15 'name': 'test',16 'paths': [17 'test',18 ]19}20splits = [ test ]""")21 self.assertTrue('test' in config.splits)22 split = config.splits['test']23 self.assertEquals('test', split.name)24 self.assertEquals(['test'], split.paths)25 def _assert_config_error(self, config):26 self.assertRaises(saplib.ConfigError, saplib.Config, self.repo(), config)27 def _create_config(self, config = None):...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Nov’22 Updates: Live With Automation Testing On OTT Streaming Devices, Test On Samsung Galaxy Z Fold4, Galaxy Z Flip4, & More

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.

Considering Agile Principles from a different angle

In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.

How To Choose The Best JavaScript Unit Testing Frameworks

JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.

How To Write End-To-End Tests Using Cypress App Actions

When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.

[LambdaTest Spartans Panel Discussion]: What Changed For Testing & QA Community And What Lies Ahead

The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.

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