def test_serialization_rejects_wrong_version(self): info = _make_info()._replace(version="reversion") with six.assertRaisesRegex( self, ValueError, "expected 'version' to be '.*', but found: 'reversion'", ): manager._info_to_string(info)
def test_serialization_rejects_bad_types(self): bad_time = datetime.datetime.fromtimestamp(1549061116) # not an int info = _make_info()._replace(start_time=bad_time) with six.assertRaisesRegex( self, ValueError, r"expected 'start_time' of type.*int.*, but found: datetime\.", ): manager._info_to_string(info)
def test_deserialization_rejects_missing_version(self): info = _make_info() json_value = json.loads(manager._info_to_string(info)) del json_value["version"] bad_input = json.dumps(json_value) with six.assertRaisesRegex(self, ValueError, "incompatible version:"): manager._info_from_string(bad_input)
def test_deserialization_ignores_extra_keys(self): info = _make_info() json_value = json.loads(manager._info_to_string(info)) json_value["unlikely"] = "story" bad_input = json.dumps(json_value) result = manager._info_from_string(bad_input) self.assertIsInstance(result, manager.TensorBoardInfo)
def test_deserialization_accepts_future_version(self): info = _make_info() json_value = json.loads(manager._info_to_string(info)) json_value["version"] = "99.99.99a20991232" input_ = json.dumps(json_value) result = manager._info_from_string(input_) self.assertEqual(result.version, "99.99.99a20991232")
def test_deserialization_rejects_missing_keys(self): info = _make_info() json_value = json.loads(manager._info_to_string(info)) del json_value["start_time"] bad_input = json.dumps(json_value) with six.assertRaisesRegex(self, ValueError, "bad keys on TensorBoardInfo"): manager._info_from_string(bad_input)
def test_deserialization_rejects_extra_keys(self): info = _make_info() json_value = json.loads(manager._info_to_string(info)) json_value["unlikely"] = "story" bad_input = json.dumps(json_value) with six.assertRaisesRegex(self, ValueError, "bad keys on TensorBoardInfo"): manager._info_from_string(bad_input)
def test_deserialization_rejects_missing_keys(self): info = _make_info() json_value = json.loads(manager._info_to_string(info)) del json_value["start_time"] bad_input = json.dumps(json_value) with six.assertRaisesRegex(self, ValueError, re.escape("missing keys: ['start_time']")): manager._info_from_string(bad_input)
def test_deserialization_rejects_missing_version(self): info = _make_info() json_value = json.loads(manager._info_to_string(info)) del json_value["version"] bad_input = json.dumps(json_value) with self.assertRaisesRegex(ValueError, re.escape("missing keys: ['version']")): manager._info_from_string(bad_input)
def test_deserialization_rejects_bad_types(self): info = _make_info() json_value = json.loads(manager._info_to_string(info)) json_value["start_time"] = "2001-02-03T04:05:06" bad_input = json.dumps(json_value) with six.assertRaisesRegex( self, ValueError, "expected 'start_time' of type.*int.*, but found:.*" "'2001-02-03T04:05:06'"): manager._info_from_string(bad_input)
def test_roundtrip_serialization(self): # This is also tested indirectly as part of `manager` integration # tests, in `test_get_all`. info = _make_info() also_info = manager._info_from_string(manager._info_to_string(info)) self.assertEqual(also_info, info)
def test_roundtrip_serialization(self): # This will also be tested indirectly as part of `manager` # integration tests. info = _make_info() also_info = manager._info_from_string(manager._info_to_string(info)) self.assertEqual(also_info, info)