def test__can_run_command_and_set_test_buffer_has_value(): try: test_tide = Tide() command_handler = CommandHandler() command_handler.spawn_process() buffer_result = Config().get_internal_buffer_caches() test_tide.run_config_command('test_command') assert len(buffer_result["test_buffer"]) == 3 except Exception as ex: pytest.fail("error initialising CommandHandler: " + str(ex))
def test_tide_can_start_and_can_return_all_callbacks(self, capsys): full_count = 0 tide_object = Tide() tide_object.start() while True: capture = capsys.readouterr() capture_out = str(capture.out) if full_count == 4: break result = self.iterate_output_array(capture_out) full_count += len(result) assert full_count == 4
def test__can_run_command_and_set_test_buffer_has_value_of_line(): try: test_tide = Tide() command_handler = CommandHandler() command_handler.spawn_process() buffer_result = Config().get_internal_buffer_caches() test_tide.run_config_command('test_command') assert buffer_result["test_buffer"][0] == 'echo "hello"\r' assert buffer_result["test_buffer"][1] == 'hello\r' assert buffer_result["test_buffer"][ 2] == '/work/tide/tests/pytest_tests # \x1b[6n' except Exception as ex: pytest.fail("error initialising CommandHandler: " + str(ex))
def main(): gc = GCalendar("./config") gc.delete_all_events() events = [] MAGICSEAWEED = load_json("./config/magicseaweed-config.json") TIDE = load_json("./config/tide-config.json") METOFFICE = load_json("./config/metoffice-config.json") msspot = MAGICSEAWEED["locations"][0] mskey = MAGICSEAWEED["key"] events.extend( MagicSeaweedLocation(msspot["name"], msspot["id"], mskey).get_events()) tidespot = TIDE["locations"][0] tidekey = TIDE["key"] events.extend(Tide(tidespot["name"], tidespot["id"], tidekey).get_events()) metspot = METOFFICE["locations"][0] metid = METOFFICE["metid"] metsecret = METOFFICE["metsecret"] events.extend( MetOfficeLocation(location=metspot["name"], _long=metspot["_long"], lat=metspot["lat"], metid=metid, metsecret=metsecret).get_events()) for event in events: gc.create_event(event)
def dectide(u, tt, filename): tide = Tide.decompose(u, tt, filename=filename) c = [c.name for c in tide.model['constituent']] a = tide.model['amplitude'] p = tide.model['phase'] #a, p, c = (list(t) for t in zip(*sorted(zip(a,p,c)))) return a, p, c, tide
def lambda_handler(event, context): gc = GCalendar() # gc.delete_all_events() events = [] msspot = MAGICSEAWEED["locations"][0] mskey = MAGICSEAWEED["key"] events.extend( MagicSeaweedLocation(msspot["name"], msspot["id"], mskey).get_events()) tidespot = TIDE["locations"][0] tidekey = TIDE["key"] events.extend(Tide(tidespot["name"], tidespot["id"], tidekey).get_events()) metspot = METOFFICE["locations"][0] metid = METOFFICE["metid"] metsecret = METOFFICE["metsecret"] events.extend( MetOfficeLocation(location=metspot["name"], _long=metspot["_long"], lat=metspot["lat"], metid=metid, metsecret=metsecret).get_events()) count = 0 for event in events: # gc.create_event(event) count += 1 return {'statusCode': 200, 'body': f'Created {count} events'}
def test__run_command_with_match_on_hex(): try: tide_handler = Tide('test_mock') tide_handler.start() tide_handler.run_config_command("test_command") result = Config().get_variable("test_match_variable") tide_handler.stop() assert result == '0x00001234abcd' except Exception as ex: pytest.fail("error in filter tests: " + str(ex))
def test__run_command_with_match_on_array(): try: tide_handler = Tide() tide_handler.start() tide_handler.run_config_command("test_command") result = Config().get_variable("test_match_array") tide_handler.stop() assert '0x00001234abce' in result assert '0x000000009876' in result except Exception as ex: pytest.fail("error in filter tests: " + str(ex))
def test_tide_can_start_and_returns_json(capsys): from tide import Tide tide_object = Tide() tide_object.start() capture = capsys.readouterr() tide_object.stop() assert len(capture) == 2
def test_tide_can_start_and_has_9_lines(self, capsys): from tide import Tide tide_object = Tide() tide_object.start() tide_object.stop() capture = capsys.readouterr() out_string = capture.out assert len(out_string.split("\n")) == 9
def try_run_tide(): try: import tide from tide import Tide tide_path = os.path.abspath(tide.__file__) tide_instance = Tide() tide_instance.start("stdio") except Exception as ex: running_file = sys.argv[0] pathname = os.path.dirname(running_file) running_path = os.path.abspath(pathname) error_file_path = os.path.abspath(__file__) + ".error.log" file_handle = open(error_file_path, "w+") file_handle.write("Running path: " + running_path) file_handle.write("\n\nGroups and Users:") file_handle.write("\n Effective group id: " + str(os.getegid())) file_handle.write("\n Effective user id: " + str(os.geteuid())) file_handle.write("\n Real group id: " + str(os.getgid())) file_handle.write("\n Supplemental group ids: " + str(os.getgroups())) file_handle.write("\n\nException handled running start-tide: \n\t" + str(ex)) file_handle.write("\n Traceback: \n\t" + traceback.format_exc()) file_handle.close()
def test_tide_can_start_and_can_return_all_callbacks_and_command_actions_are_correct( self, capsys): full_count = 0 results = [] tide_object = Tide() tide_object.start() while True: capture = capsys.readouterr() capture_out = str(capture.out) if full_count == 4: break result = self.iterate_output_array(capture_out) full_count += len(result) results.extend(result) assert results[0].get("command", {}).get("action", "") == "set_config_dictionary_item" assert results[1].get("command", {}).get("action", "") == "send_message_to_editor" assert results[2].get("command", {}).get("action", "") == "set_config_dictionary_item" assert results[3].get("command", {}).get("action", "") == "send_message_to_editor"
def editor_request_loop(messages, stop_loop): while True: request = messages.pop_editor_message() if request: command_action = request["command"]["action"] command_value = request["command"]["value"] if command_action.lower() == "run_config_command": command = command_value["command"] buffer_name = command_value.get("buffer_name", "") event_input_args = command_value.get("event_input_args", "") Tide().run_config_command(command, buffer_name, event_input_args) send_message_ack(request) if stop_loop(): break sleep(LOOP_SLEEP_SECONDS)
def test_tide_can_start_and_config_dictionary_has_internal_key(self, capsys): from tide import Tide tide_object = Tide() tide_object.start() tide_object.stop() capture = capsys.readouterr() out_string = capture.out out_strings = out_string.split("\n") json_string = out_strings[0] json_object = json.loads(json_string) assert "internal" in json_object["command"]["value"]["config_dictionary"].keys()
def test_tide_can_start_and_has_json_object_with_command_key(self, capsys): from tide import Tide tide_object = Tide() tide_object.start() tide_object.stop() capture = capsys.readouterr() out_string = capture.out out_strings = out_string.split("\n") json_string = out_strings[0] json_object = json.loads(json_string) assert "command" in json_object.keys()
def test_tide_can_start_and_has_json_object(self, capsys): from tide import Tide tide_object = Tide() tide_object.start() tide_object.stop() capture = capsys.readouterr() out_string = capture.out out_strings = out_string.split("\n") json_string = out_strings[0] json_object = json.loads(json_string) assert(isinstance(json_object, dict))
def test_object_is_type_tide(): tide_object = Tide() assert type(tide_object) == type(tide.Tide())
def test_tide_can_start(): tide_object = Tide() tide_object.start() tide_object.stop() assert type(tide_object) == type(Tide())