def test_ts_image_path_assign_truncated(self): """Test TimeStreamImage path assignment with valid parameters""" img = TimeStreamImage() img.path = helpers.FILES["zeros_jpg"] self.assertEqual(img.path, helpers.FILES["zeros_jpg"]) self.assertEqual(img.datetime, helpers.ZEROS_DATETIME) np.testing.assert_array_equal(img.pixels, helpers.ZEROS_PIXELS)
def test_ts_image_path_assign_parent(self): """Test TimeStreamImage path assignment with valid parameters & parent""" ts = TimeStream() ts.load(helpers.FILES["timestream"]) img = TimeStreamImage() img.parent_timestream = ts img.path = helpers.TS_FILES_JPG[0] self.assertEqual(img.path, helpers.TS_FILES_JPG[0]) self.assertEqual(img.datetime, helpers.TS_DATES_PARSED[0])
def test_ts_image_clone(self): """Test TimeStreamImage.clone()""" img = TimeStreamImage() img.path = helpers.FILES["zeros_jpg"] cpy = img.clone() self.assertIsNot(cpy, img) self.assertIsNot(cpy.datetime, img.datetime) self.assertIsNot(cpy.data, img.data) self.assertEqual(cpy.data, img.data) self.assertIs(cpy._pixels, None) self.assertIs(cpy._timestream, None) self.assertIs(cpy._path, None)
def test_ts_image_clone_all(self): """Test TimeStreamImage.clone(), cloning all members""" ts = TimeStream() img = TimeStreamImage() img.parent_timestream = ts img.path = helpers.FILES["zeros_jpg"] cpy = img.clone(True, True, True) self.assertIsNot(cpy, img) self.assertIsNot(cpy.datetime, img.datetime) self.assertEqual(cpy.datetime, img.datetime) self.assertIsNot(cpy.data, img.data) self.assertEqual(cpy.data, img.data) self.assertIsNot(cpy.pixels, img.pixels) np.testing.assert_array_equal(cpy.pixels, img.pixels) # TS should be copied as a refernce, hence *Is*, not Is Not self.assertIs(cpy.parent_timestream, img.parent_timestream) self.assertEqual(cpy.parent_timestream, img.parent_timestream) # Strings are cached, so no assertIsNot for path self.assertEqual(cpy.path, img.path)
def test_timestream_write(self): ts = TimeStream() ts.version = 1 ts.create(self.tmp_path, ext="jpg") self.assertEqual(ts.path, self.tmp_path) self.assertDictEqual(ts.image_data, {}) self.assertDictEqual(ts.data, {}) for _ in range(10): img = TimeStreamImage() arr = np.arange(300, dtype="uint8") arr = arr.reshape((10, 10, 3)) date = dt.datetime.now() str_date = ts_format_date(date) img.pixels = arr img.datetime = date img.data["fake"] = True ts.write_image(img) self.assertIn(str_date, ts.image_data) self.assertDictEqual(img.data, ts.image_data[str_date]) self.assertTrue(path.exists, img.path)
def test_ts_image_path_assign(self): """Test TimeStreamImage. path assignment with valid parameters""" img = TimeStreamImage() img.path = helpers.TS_FILES_JPG[0] self.assertEqual(img.path, helpers.TS_FILES_JPG[0])
def __exec__(self, context, *args): img = TimeStreamImage(args[0]) img.pixels = self.createCompoundImage(args[0]) return [img]