def test_get_timepoint(self, timepoints): colony = Colony(1, timepoints) # Get timepoint assert colony.get_timepoint( timepoints[0].date_time) == timepoints[0] with pytest.raises(ValueError): colony.get_timepoint(None)
def test_remove_timepoint( self, timepoints, ): colony = Colony(1, timepoints) colony.remove_timepoint(timepoints[0].date_time) assert timepoints[0].date_time not in colony.timepoints
def test_growth_rate_average(self, timepoints, timepoint_empty): colony = Colony(id, timepoints) colony_empty = Colony(1, [timepoint_empty]) assert colony.growth_rate_average == ( (timepoints[-1].area - timepoints[0].area) **(1 / len(timepoints))) - 1 assert colony_empty.growth_rate_average == 0
def test_center(self, timepoints): from statistics import mean colony = Colony(1, timepoints) for i, coord in enumerate(colony.center): assert round(coord, 4) == round(mean([t.center[i] for t in timepoints]), 4)
def test_append_timepoint(self, timepoints, timepoint_empty): colony = Colony(1, timepoints) colony.append_timepoint(timepoint_empty) assert timepoint_empty in colony.timepoints with pytest.raises(ValueError): colony.append_timepoint(timepoints[0])
def timepoints(request): timepoints = list() for i, center in enumerate(centers, start=1): timepoints.append( Colony.Timepoint(timestamp=timedelta(seconds=i), area=i, center=center, diameter=i * 1.0, perimeter=i * 1.0, color_average=(0, 0, 0))) yield timepoints
def timepoints(request): timepoints = list() date_time = datetime.now() for i, center in enumerate(centers, start=1): timepoints.append( Colony.Timepoint(date_time=date_time + timedelta(seconds=i), elapsed_minutes=i, area=i, center=center, diameter=i * 1.0, perimeter=i * 1.0)) yield timepoints
def test_doubling_time(self, timepoints_iter, timepoint_empty, window, elapsed_minutes, expected, expected_minutes): colony = Colony(1, timepoints_iter) colony_empty = Colony(1, [timepoint_empty]) if timepoints_iter is not None: doubling_times = colony.get_doubling_times( window=window, elapsed_minutes=elapsed_minutes) if elapsed_minutes: doubling_times = [round(t, 2) for t in doubling_times] expected = expected_minutes assert max(doubling_times) == expected assert colony_empty.get_doubling_times() == list() else: with pytest.raises(ValueError): colony.get_doubling_times(window=window, elapsed_minutes=elapsed_minutes)
def test_doubling_time_average(self, timepoints_iter, timepoint_empty, window, elapsed_minutes, expected, expected_minutes): colony = Colony(1, timepoints_iter) colony_empty = Colony(1, [timepoint_empty]) if timepoints_iter is not None: doubling_time_average = colony.get_doubling_time_average( window=window, elapsed_minutes=elapsed_minutes) if elapsed_minutes: doubling_time_average = round(doubling_time_average, 2) expected = expected_minutes assert doubling_time_average == expected assert colony_empty.get_doubling_time_average() == 0 else: with pytest.raises(ValueError): colony.get_doubling_time_average( window=window, elapsed_minutes=elapsed_minutes)
def test_local_doubling_time(self, timepoint_empty): colony = Colony(1, [timepoint_empty]) assert colony._Colony__local_doubling_time(0, [0], [0], window=0) == 0
def test_empty(self): colony = Colony(1) assert colony.id == 1 with pytest.raises(ValueError): colony.timepoints
def test_iterable(self, timepoints_iter): with pytest.raises(ValueError): Colony(1, timepoints_iter)
def test_init(self, timepoints_iter): colony = Colony(1, timepoints_iter) assert isinstance(colony.timepoints, list) assert len(colony.timepoints) == len(timepoints_iter)
def timepoint_empty(self): yield Colony.Timepoint(timedelta.min, 0, (0, 0), 0, 0, (0, 0, 0))
def test_filter(self, timepoints): # It is very difficult to rigorously and exhaustively test the filtering # The results are also somewhat subjective and outside the scope of a unit test colonies = [Colony(1, timepoints)] assert colonies_filtered(colonies) == colonies
def test_update_timepoint(self, timepoints, timepoint_empty): colony = Colony(1, timepoints) colony.update_timepoint(timepoints[0], timepoint_empty) assert colony.timepoint_first == timepoint_empty
def test_remove_timepoint(self, timepoints): colony = Colony(1, timepoints) colony.remove_timepoint(timepoints[0].timestamp) assert timepoints[0] not in colony.timepoints
def test_get_timepoint(self, timepoints): colony = Colony(1, timepoints) assert colony.get_timepoint( timepoints[0].timestamp) == timepoints[0] assert colony.get_timepoint(timedelta(seconds=-1)) is None
def test_circularity(self, timepoints, timepoint_index, expected): colony = Colony(1, timepoints) circularity = colony.circularity_at_timepoint( timepoints[timepoint_index].date_time) assert round(circularity, 2) == expected
def timepoint_empty(self): yield Colony.Timepoint(datetime.now(), 0, 0, (0, 0), 0, 0)
def test_id(self, timepoints_iter, id): colony = Colony(id, timepoints_iter) assert colony.id == id
def colony(self, timepoints): yield Colony(1, timepoints)
def test_growth_rate(self, timepoints, timepoint_empty): colony = Colony(1, timepoints) colony_empty = Colony(1, [timepoint_empty]) assert colony.growth_rate == len(timepoints) - 1 assert colony_empty.growth_rate == 0