def test_greentea_update_kettle(self): uuid = "001" mbed_greentea_dlm.greentea_update_kettle(uuid) data = mbed_greentea_dlm.get_json_data_from_file( mbed_greentea_dlm.GREENTEA_KETTLE_PATH) self.assertIsNotNone(data) self.assertIn("start_time", data[uuid]) self.assertIn("cwd", data[uuid]) self.assertIn("locks", data[uuid]) self.assertEqual(data[uuid]["cwd"], os.getcwd()) self.assertEqual(data[uuid]["locks"], []) # Check greentea_kettle_info() output = mbed_greentea_dlm.greentea_kettle_info().splitlines() line = output[3] self.assertIn(os.getcwd(), line) self.assertIn(uuid, line) # Test greentea_acquire_target_id target_id = "999" mbed_greentea_dlm.greentea_acquire_target_id(target_id, uuid) data = mbed_greentea_dlm.get_json_data_from_file( mbed_greentea_dlm.GREENTEA_KETTLE_PATH) self.assertIn(uuid, data) self.assertIn("locks", data[uuid]) self.assertIn(target_id, data[uuid]["locks"]) # Test greentea_release_target_id mbed_greentea_dlm.greentea_release_target_id(target_id, uuid) data = mbed_greentea_dlm.get_json_data_from_file( mbed_greentea_dlm.GREENTEA_KETTLE_PATH) self.assertIn(uuid, data) self.assertIn("locks", data[uuid]) self.assertNotIn(target_id, data[uuid]["locks"]) # Test greentea_acquire_target_id_from_list target_id = "999" result = mbed_greentea_dlm.greentea_acquire_target_id_from_list( [target_id], uuid) data = mbed_greentea_dlm.get_json_data_from_file( mbed_greentea_dlm.GREENTEA_KETTLE_PATH) self.assertEqual(result, target_id) self.assertIn(uuid, data) self.assertIn("locks", data[uuid]) self.assertIn(target_id, data[uuid]["locks"]) # Check greentea_clean_kettle() mbed_greentea_dlm.greentea_clean_kettle(uuid) data = mbed_greentea_dlm.get_json_data_from_file( mbed_greentea_dlm.GREENTEA_KETTLE_PATH) self.assertEqual(data, {})
def test_get_json_data_from_file_valid_file(self): path = os.path.join(mbed_greentea_dlm.HOME_DIR, "test") with open(path, "w") as f: f.write("{}") result = mbed_greentea_dlm.get_json_data_from_file(path) self.assertEqual(result, {}) os.remove(path)
def test_get_json_data_from_file_invalid_file(self): result = mbed_greentea_dlm.get_json_data_from_file("null_file") self.assertIsNone(result)