Best Python code snippet using molecule_python
test_cli.py
Source:test_cli.py
...14port = int(port) if port else 920015class TestCLIMethods(CuratorTestCase):16 def test_bad_client_config(self):17 self.create_indices(10)18 self.write_config(19 self.args['configfile'],20 testvars.bad_client_config.format(host, port)21 )22 self.write_config(self.args['actionfile'],23 testvars.disabled_proto.format('close', 'delete_indices'))24 test = clicktest.CliRunner()25 result = test.invoke(26 curator.cli,27 [28 '--config', self.args['configfile'],29 '--dry-run',30 self.args['actionfile']31 ],32 )33 self.assertEqual(-1, result.exit_code)34 def test_no_config(self):35 # This test checks whether localhost:9200 is provided if no hosts or36 # port are in the configuration. But in testing, sometimes37 # TEST_ES_SERVER is set to something other than localhost:9200. In this38 # case, the test here would fail. The if statement at the end now39 # compensates. See https://github.com/elastic/curator/issues/84340 localtest = False41 if (host == 'localhost' or host == '127.0.0.1') and \42 port == 9200:43 localtest = True44 self.create_indices(10)45 self.write_config(46 self.args['configfile'],47 ' \n'48 )49 self.write_config(self.args['actionfile'],50 testvars.disabled_proto.format('close', 'delete_indices'))51 test = clicktest.CliRunner()52 result = test.invoke(53 curator.cli,54 [55 '--config', self.args['configfile'],56 '--dry-run',57 self.args['actionfile']58 ],59 )60 if localtest:61 self.assertEqual(0, result.exit_code)62 else:63 self.assertEqual(-1, result.exit_code)64 def test_no_logging_config(self):65 self.create_indices(10)66 self.write_config(67 self.args['configfile'],68 testvars.no_logging_config.format(host, port)69 )70 self.write_config(self.args['actionfile'],71 testvars.disabled_proto.format('close', 'delete_indices'))72 test = clicktest.CliRunner()73 result = test.invoke(74 curator.cli,75 [76 '--config', self.args['configfile'],77 '--dry-run',78 self.args['actionfile']79 ],80 )81 self.assertEqual(0, result.exit_code)82 def test_logging_none(self):83 self.create_indices(10)84 self.write_config(85 self.args['configfile'],86 testvars.none_logging_config.format(host, port)87 )88 self.write_config(self.args['actionfile'],89 testvars.disabled_proto.format('close', 'delete_indices'))90 test = clicktest.CliRunner()91 result = test.invoke(92 curator.cli,93 [94 '--config', self.args['configfile'],95 '--dry-run',96 self.args['actionfile']97 ],98 )99 self.assertEqual(0, result.exit_code)100 def test_invalid_action(self):101 self.write_config(102 self.args['configfile'], testvars.client_config.format(host, port))103 self.write_config(self.args['actionfile'],104 testvars.optionless_proto.format('invalid_action'))105 test = clicktest.CliRunner()106 result = test.invoke(107 curator.cli,108 [109 '--config', self.args['configfile'],110 self.args['actionfile']111 ],112 )113 self.assertEqual(-1, result.exit_code)114 def test_action_is_None(self):115 self.write_config(116 self.args['configfile'], testvars.client_config.format(host, port))117 self.write_config(self.args['actionfile'],118 testvars.optionless_proto.format(' '))119 test = clicktest.CliRunner()120 result = test.invoke(121 curator.cli,122 [123 '--config', self.args['configfile'],124 self.args['actionfile']125 ],126 )127 self.assertEqual(128 type(curator.ConfigurationError()), type(result.exception))129 def test_no_action(self):130 self.write_config(131 self.args['configfile'], testvars.client_config.format(host, port))132 self.write_config(self.args['actionfile'],133 testvars.actionless_proto)134 test = clicktest.CliRunner()135 result = test.invoke(136 curator.cli,137 [138 '--config', self.args['configfile'],139 self.args['actionfile']140 ],141 )142 self.assertEqual(143 type(curator.ConfigurationError()), type(result.exception))144 def test_dry_run(self):145 self.create_indices(10)146 self.write_config(147 self.args['configfile'], testvars.client_config.format(host, port))148 self.write_config(self.args['actionfile'],149 testvars.delete_proto.format(150 'age', 'name', 'older', '\'%Y.%m.%d\'', 'days', 5, ' ', ' ', ' '151 )152 )153 test = clicktest.CliRunner()154 result = test.invoke(155 curator.cli,156 [157 '--config', self.args['configfile'],158 '--dry-run',159 self.args['actionfile']160 ],161 )162 self.assertEquals(10, len(curator.get_indices(self.client)))163 def test_action_disabled(self):164 self.create_indices(10)165 self.write_config(166 self.args['configfile'], testvars.client_config.format(host, port))167 self.write_config(self.args['actionfile'],168 testvars.disabled_proto.format('close', 'delete_indices'))169 test = clicktest.CliRunner()170 result = test.invoke(171 curator.cli,172 [173 '--config', self.args['configfile'],174 self.args['actionfile']175 ],176 )177 self.assertEquals(0, len(curator.get_indices(self.client)))178 self.assertEqual(0, result.exit_code)179 # I'll have to think up another way to create an exception.180 # The exception that using "alias" created, a missing argument,181 # is caught too early for this to actually run the test now :/182 #183 def test_continue_if_exception(self):184 name = 'log1'185 self.create_index(name)186 self.create_index('log2')187 self.write_config(188 self.args['configfile'], testvars.client_config.format(host, port))189 self.write_config(self.args['actionfile'],190 testvars.continue_proto.format(191 name, True, 'delete_indices', False192 )193 )194 test = clicktest.CliRunner()195 result = test.invoke(196 curator.cli,197 [198 '--config', self.args['configfile'],199 self.args['actionfile']200 ],201 )202 self.assertEquals(0, len(curator.get_indices(self.client)))203 self.assertEqual(0, result.exit_code)204 def test_continue_if_exception_False(self):205 name = 'log1'206 self.create_index(name)207 self.create_index('log2')208 self.write_config(209 self.args['configfile'], testvars.client_config.format(host, port))210 self.write_config(self.args['actionfile'],211 testvars.continue_proto.format(212 name, False, 'delete_indices', False213 )214 )215 test = clicktest.CliRunner()216 result = test.invoke(217 curator.cli,218 [219 '--config', self.args['configfile'],220 self.args['actionfile']221 ],222 )223 self.assertEquals(2, len(curator.get_indices(self.client)))224 self.assertEqual(1, result.exit_code)225 def test_no_options_in_action(self):226 self.create_indices(10)227 self.write_config(228 self.args['configfile'], testvars.client_config.format(host, port))229 self.write_config(self.args['actionfile'],230 testvars.no_options_proto.format('delete_indices'))231 test = clicktest.CliRunner()232 result = test.invoke(233 curator.cli,234 [235 '--config', self.args['configfile'],236 '--dry-run',237 self.args['actionfile']238 ],239 )...
test_config.py
Source:test_config.py
...7 data = {"order": []}8 data.update(kwargs)9 return data10@pytest.fixture11def write_config(tmp_path):12 def func(data):13 config_file = tmp_path / "config.toml"14 open(config_file, "w").write(toml.dumps(data))15 return config_file16 return func17def test_config_dict():18 assert isinstance(Config(), dict)19def test_config_order_required(write_config):20 with pytest.raises(SchemaMissingKeyError, match="order"):21 Config().read_file(write_config({}))22def test_config_order_is_list(write_config):23 with pytest.raises(SchemaError, match=r"foo.*list"):24 Config().read_file(write_config({"order": "foo"}))25def test_config_order_is_list_of_str(write_config):26 with pytest.raises(SchemaError, match=r"0.*str"):27 Config().read_file(write_config({"order": [0]}))28def test_config_order_valid(write_config):29 config = Config()30 config.read_file(write_config({"order": ["foo"]}))31 assert "order" in config32def test_config_click_events_is_bool(write_config):33 with pytest.raises(SchemaError, match=r"foo.*bool"):34 Config().read_file(write_config(min_config(click_events="foo")))35def test_config_click_events_valid(write_config):36 config = Config()37 config.read_file(write_config(min_config(click_events=True)))38 assert "click_events" in config39def test_config_include_is_list(write_config):40 with pytest.raises(SchemaError, match=r"foo.*list"):41 Config().read_file(write_config(min_config(include="foo")))42def test_config_include_is_list_of_str(write_config):43 with pytest.raises(SchemaError, match=r"0.*str"):44 Config().read_file(write_config(min_config(include=[0])))45def test_config_include_valid(write_config):46 config = Config()47 config.read_file(write_config(min_config(include=["foo"])))48 assert "include" in config49def test_config_interval_is_float(write_config):50 with pytest.raises(SchemaError, match=r"foo.*float"):51 Config().read_file(write_config(min_config(interval="foo")))52def test_config_interval_valid(write_config):53 config = Config()54 config.read_file(write_config(min_config(interval=0)))55 assert "interval" in config56def test_config_settings_is_dict(write_config):57 with pytest.raises(SchemaError, match=r"foo.*dict"):58 Config().read_file(write_config(min_config(settings="foo")))59def test_config_settings_valid_empty(write_config):60 config = Config()61 config.read_file(write_config(min_config(settings={})))62 assert "settings" in config63def test_config_settings_is_dict_of_dicts(write_config):64 with pytest.raises(SchemaError, match=r"bar.*dict"):65 Config().read_file(write_config(min_config(settings={"foo": "bar"})))66@pytest.mark.parametrize("value", any_value)67def test_config_settings_valid(write_config, value):68 config = Config()69 config.read_file(70 write_config(min_config(settings={"foo": {"bar": value}}))71 )72 assert "settings" in config73def test_config_on_click_is_dict(write_config):74 with pytest.raises(SchemaError, match=r"foo.*dict"):75 Config().read_file(write_config(min_config(on_click="foo")))76def test_config_on_click_empty(write_config):77 config = Config()78 config.read_file(write_config(min_config(on_click={})))79 assert "on_click" in config80def test_config_on_click_is_dict_of_dicts(write_config):81 with pytest.raises(SchemaError, match=r"bar.*dict"):82 Config().read_file(write_config(min_config(on_click={"foo": "bar"})))83def test_config_on_click_dict_empty(write_config):84 config = Config()85 config.read_file(write_config(min_config(on_click={"foo": {}})))86 assert "on_click" in config87def test_config_on_click_int_keys(write_config):88 with pytest.raises(SchemaError, match=r"bar"):89 Config().read_file(90 write_config(min_config(on_click={"foo": {"bar": "baz"}}))91 )92def test_config_on_click_positive_keys(write_config):93 with pytest.raises(SchemaError, match=r"Wrong key.*0"):94 Config().read_file(95 write_config(min_config(on_click={"foo": {"0": "bar"}}))96 )97def test_config_on_click_valid(write_config):98 config = Config()99 config.read_file(100 write_config(101 min_config(102 on_click={103 "foo": {"1": "x", "2": ["y", "z"]},104 "bar": {"3": "x", "4": ["y", "z"]},105 }106 )107 )108 )...
old_data_display.py
Source:old_data_display.py
...53 self.CONFIG_DICT =json.load(f)54 f.close()55 def send_modify(self, data):56 self.CONFIG_DICT['instruction_send'] = data57 self.write_config()58 def write_modify(self, data):59 self.CONFIG_DICT['instruction_write'] = data60 self.write_config()61 def auto_modify(self, data):62 self.CONFIG_DICT['auto_on_off_valve'] = data63 self.write_config()64 def open_modify(self, data):65 self.CONFIG_DICT['force_open_valve'] = data66 self.write_config()67 def close_modify(self, data):68 self.CONFIG_DICT['force_close_valve'] = data69 self.write_config()70 def adjtime_modify(self, data):71 self.CONFIG_DICT['instruction_adjtime'] = data72 self.write_config()73 def CCA_modify(self, data):74 self.CONFIG_DICT['CCA'] = data75 self.write_config()76 def PANID_modify(self, data):77 self.CONFIG_DICT['PANID'] = data78 self.write_config()79 def emitpower_modify(self, data):80 self.CONFIG_DICT['emitpower'] = data81 self.write_config()82 def CCAcheckingperiod_modify(self, data):83 self.CONFIG_DICT['CCAcheckingperiod'] = data84 self.write_config()85 def inactive_modify(self, data):86 self.CONFIG_DICT['inactive'] = data87 self.write_config()88 def channel_modify(self, data):89 self.CONFIG_DICT['channel'] = data90 self.write_config()91 def DIO_minlen_modify(self, data):92 self.CONFIG_DICT['DIO_minlen'] = data93 self.write_config()94 def DIO_max_modify(self, data):95 self.CONFIG_DICT['DIO_max'] = data96 self.write_config()97 98 def monitor_update_period_modify(self, data):99 self.CONFIG_DICT['monitor_update_period'] = data100 self.write_config()101 def write_config(self):102 with open(self.Config_FILE, 'w') as f:103 f.write(json.dumps(self.CONFIG_DICT))...
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!!