Esempio n. 1
0
 def test_deserialization_rejects_non_object_json(self):
   bad_input = "[1, 2]"
   with six.assertRaisesRegex(
       self,
       ValueError,
       re.escape("not a JSON object: [1, 2]")):
     manager._info_from_string(bad_input)
Esempio n. 2
0
 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)
Esempio n. 3
0
 def test_deserialization_rejects_bad_json(self):
   bad_input = "parse me if you dare"
   with six.assertRaisesRegex(
       self,
       ValueError,
       "invalid JSON:"):
     manager._info_from_string(bad_input)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
 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)
Esempio n. 10
0
 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")
Esempio n. 11
0
 def test_write_remove_info_file(self):
     info = _make_info()
     self.assertEqual(self._list_info_dir(), [])
     manager.write_info_file(info)
     filename = "pid-76540.info"
     expected_filepath = os.path.join(self.info_dir, filename)
     self.assertEqual(self._list_info_dir(), [filename])
     with open(expected_filepath) as infile:
         self.assertEqual(manager._info_from_string(infile.read()), info)
     manager.remove_info_file()
     self.assertEqual(self._list_info_dir(), [])
Esempio n. 12
0
 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)
Esempio n. 13
0
 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)