def test_frame(self): t1 = Timestamp() t1.set_frame(1) nose.tools.assert_equal(t1.get_frame(), 1) t2 = Timestamp(1234000000, 1) nose.tools.assert_equal(t2.get_frame(), 1)
def test_get_set_track_id(self): ti = TrackInterval() nt.assert_equals(ti.track, 0) ti.track = 5 nt.assert_equals(ti.track, 5) ti.track = -12 nt.assert_equals(ti.track, -12) ti.track = 0 nt.assert_equals(ti.track, 0) # Check initial id ti = TrackInterval(20, Timestamp(), Timestamp()) nt.assert_equals(ti.track, 20) ti.track = 5 nt.assert_equals(ti.track, 5) ti.track = -12 nt.assert_equals(ti.track, -12) ti.track = 0 nt.assert_equals(ti.track, 0)
def test_set_no_attribute(self): ti = TrackInterval() with nt.assert_raises(AttributeError): ti.nonexistant_attribute = 5 ti = TrackInterval(21, Timestamp(1234, 1), Timestamp(5678, 2)) with nt.assert_raises(AttributeError): ti.nonexistant_attribute = 5
def test_time(self): t1 = Timestamp() t1.set_time_seconds(1234) nose.tools.assert_equal(t1.get_time_seconds(), 1234) nose.tools.assert_equal(t1.get_time_usec(), 1234000000) t1.set_time_usec(4321000000) nose.tools.assert_equal(t1.get_time_seconds(), 4321) nose.tools.assert_equal(t1.get_time_usec(), 4321000000) t2 = Timestamp(1234000000, 1) nose.tools.assert_equal(t2.get_time_seconds(), 1234) nose.tools.assert_equal(t2.get_time_usec(), 1234000000)
def test_get_set_timestamps(self): ti = TrackInterval() nt.assert_false(ti.start.is_valid()) nt.assert_false(ti.stop.is_valid()) ts1, ts2 = Timestamp(1234, 1), Timestamp(5678, 2) ti.start = ts1 ti.stop = ts2 nt.ok_(ti.start == ts1) nt.ok_(ti.stop == ts2) # Confirm its a copy, not a reference ts1.set_frame(3) nt.ok_(ti.start != ts1) ti.start.set_frame(3) nt.ok_(ti.start == ts1) # Getting and setting with other constructor ti = TrackInterval(21, Timestamp(1234, 1), Timestamp(5678, 2)) nt.ok_(ti.start.is_valid()) nt.ok_(ti.stop.is_valid()) nt.ok_(ti.start == Timestamp(1234, 1)) nt.ok_(ti.stop == Timestamp(5678, 2)) ti.stop = Timestamp() nt.assert_false(ti.stop.is_valid()) ti.stop.set_time_seconds(4321) nt.assert_equals(ti.stop.get_time_seconds(), 4321) ts1 = Timestamp(8765, 4) ti.start = ts1 nt.ok_(ti.start == ts1)
def setUp(self): bbox = BoundingBox(10, 10, 20, 20) dot = DetectedObjectType("test", 0.4) do = DetectedObject(bbox, 0.4, dot) track = Track() for i in range(10): track.append(ObjectTrackState(i, i, do)) self.track_ = track self.time_1 = Timestamp() self.time_1.set_time_seconds(1234) self.time_2 = Timestamp() self.time_2.set_time_seconds(4321) self.obj_ts = ObjectTrackSet([self.track_]) self.act_type = ActivityType("self_act", 0.87) self.act = Activity(1, "self_act", 0.87, self.act_type, self.time_1, self.time_2, self.obj_ts)
def test_set_incorrect_type(self): ti = TrackInterval() with nt.assert_raises(TypeError): ti.track = "5" with nt.assert_raises(TypeError): ti.start = "5" with nt.assert_raises(TypeError): ti.stop = "5" ti = TrackInterval(21, Timestamp(1234, 1), Timestamp(5678, 2)) with nt.assert_raises(TypeError): ti.track = "5" with nt.assert_raises(TypeError): ti.start = "5" with nt.assert_raises(TypeError): ti.stop = "5"
def test_operators(self): t1 = Timestamp(100, 1) t2 = Timestamp(100, 1) t3 = Timestamp(200, 2) nose.tools.assert_true(t1 == t2) nose.tools.assert_true(t1 != t3) nose.tools.assert_true(t1 < t3) nose.tools.assert_true(t3 > t1) nose.tools.assert_true(t1 <= t2) nose.tools.assert_true(t1 <= t3) nose.tools.assert_true(t1 >= t2) nose.tools.assert_true(t3 >= t1) nose.tools.assert_false(t1 == t3) nose.tools.assert_false(t1 != t2) nose.tools.assert_false(t3 < t1) nose.tools.assert_false(t1 < t2) nose.tools.assert_false(t1 > t3) nose.tools.assert_false(t1 > t2) nose.tools.assert_false(t3 <= t1) nose.tools.assert_false(t1 >= t3)
def test_id(self): a = self.act self.assertEqual(a.id, 1) a.id = 10 self.assertEqual(a.id, 10) self.assertEqual(a.label, "self_act") a.label = "second_act" self.assertEqual(a.label, "second_act") self.assertEqual(a.activity_type.score("self_act"), 0.87) a.activity_type = ActivityType() self.assertEqual(a.confidence, 0.87) a.confidence = 1 self.assertEqual(a.confidence, 1) self.assertEqual(a.start_time.get_time_seconds(), 1234) tmp_time = Timestamp().set_time_seconds(1237) a.start_time = tmp_time self.assertEqual(a.start_time.get_time_seconds(), 1237) self.assertEqual(a.end_time.get_time_seconds(), 4321) tmp_time = Timestamp() tmp_time.set_time_seconds(4322) a.end_time = tmp_time self.assertEqual(a.end_time.get_time_seconds(), 4322) self.assertEqual(a.participants.all_frame_ids(), set(range(10))) bbox = BoundingBox(10, 10, 20, 20) dot = DetectedObjectType("test", 0.4) do = DetectedObject(bbox, 0.4, dot) track = Track() for i in range(5): track.append(ObjectTrackState(i, i, do)) new_t = track new_ots = ObjectTrackSet([new_t]) a.participants = new_ots self.assertEqual(a.participants.all_frame_ids(), set(range(5))) self.assertEqual(a.duration[0].get_time_seconds(), a.start_time.get_time_seconds()) self.assertEqual(a.duration[1].get_time_seconds(), a.end_time.get_time_seconds())
def test_valid(self): t1 = Timestamp() nose.tools.assert_false(t1.is_valid()) nose.tools.assert_false(t1.has_valid_time()) nose.tools.assert_false(t1.has_valid_frame()) t1.set_time_seconds(1234) nose.tools.assert_false(t1.is_valid()) t1.set_frame(1) nose.tools.assert_true(t1.is_valid()) nose.tools.assert_true(t1.has_valid_time()) nose.tools.assert_true(t1.has_valid_frame()) t1.set_invalid() nose.tools.assert_false(t1.is_valid()) nose.tools.assert_false(t1.has_valid_time()) nose.tools.assert_false(t1.has_valid_frame())
def test_timestamp(self): m = Metadata() self.populate_metadata(m) metadatas = [Metadata(), m] for m in metadatas: nt.assert_false(m.timestamp.is_valid()) t = Timestamp() t.set_time_seconds(1234) m.timestamp = t nt.assert_equals(m.timestamp.get_time_seconds(), 1234) nt.assert_false(m.timestamp.has_valid_frame()) t.set_frame(1) m.timestamp = t nt.ok_(m.timestamp == t)
def test_set_and_get_temporal_bounds(self): dq = self._create_database_query() # First check the defaults nt.assert_false(dq.temporal_lower_bound().is_valid()) nt.assert_false(dq.temporal_upper_bound().is_valid()) test_bounds = [(Timestamp(100, 1), Timestamp(100, 1)), (Timestamp(100, 1), Timestamp(200, 2)), (Timestamp(300, 5), Timestamp(400, 6))] for (t1, t2) in test_bounds: dq.set_temporal_bounds(t1, t2) nt.assert_equals(dq.temporal_lower_bound(), t1) nt.assert_equals(dq.temporal_upper_bound(), t2) # Set to default constructed timestamps dq.set_temporal_bounds(Timestamp(), Timestamp()) nt.assert_false(dq.temporal_lower_bound().is_valid()) nt.assert_false(dq.temporal_upper_bound().is_valid())
def test_set_and_get_temporal_bounds(self): dr = DescriptorRequest() # First check the defaults nt.assert_false(dr.temporal_lower_bound().is_valid()) nt.assert_false(dr.temporal_upper_bound().is_valid()) test_bounds = [ (Timestamp(100, 1), Timestamp(100, 1)), (Timestamp(100, 1), Timestamp(200, 2)), (Timestamp(300, 5), Timestamp(400, 6)), ] for (t1, t2) in test_bounds: dr.set_temporal_bounds(t1, t2) nt.assert_equals(dr.temporal_lower_bound(), t1) nt.assert_equals(dr.temporal_upper_bound(), t2) dr.set_temporal_bounds(Timestamp(), Timestamp()) nt.assert_false(dr.temporal_lower_bound().is_valid()) nt.assert_false(dr.temporal_upper_bound().is_valid())
def test_set_and_get_temporal_bounds(self): qr = self._create_query_result() # First check the defaults nt.assert_false(qr.start_time().is_valid()) nt.assert_false(qr.end_time().is_valid()) test_bounds = [ (Timestamp(100, 1), Timestamp(100, 1)), (Timestamp(100, 1), Timestamp(200, 2)), (Timestamp(300, 5), Timestamp(400, 6)), ] for (t1, t2) in test_bounds: qr.set_temporal_bounds(t1, t2) nt.assert_equals(qr.start_time(), t1) nt.assert_equals(qr.end_time(), t2) qr.set_temporal_bounds(Timestamp(), Timestamp()) nt.assert_false(qr.start_time().is_valid()) nt.assert_false(qr.end_time().is_valid())
def create_timestamp(): return Timestamp(10, 20)
def test_create(self): TrackInterval() TrackInterval(20, Timestamp(), Timestamp()) TrackInterval(21, Timestamp(1234, 1), Timestamp(5678, 2))
def test_bad_set_bounds_logic_error(self): dq = self._create_database_query() dq.set_temporal_bounds(Timestamp(200, 2), Timestamp(100, 1))
def test_new(self): Timestamp() Timestamp(1234000000, 1)