def test_tracker_updates_records_with_missing_data(mock_formula_map, updatable_criteria_csv): # all tests from the fixture don't have any kind of data tracker = CriteriaTracker( formula_map=mock_formula_map, record_path=str(updatable_criteria_csv), webservice_rest_time=timedelta(seconds=0.0), ) tracker.load_records() # CSV has no criteria data initially for criteria_rec in tracker: assert criteria_rec.EngineerTraction == '' assert criteria_rec.FixRatio == '' assert criteria_rec.TotalAlerts == '' assert criteria_rec.LastUpdatedOn == '' assert criteria_rec.AllowSync is True tracker.update_records() del tracker # let's re read with a separate tracker # to ensure data was cached & correct separate_tracker = CriteriaTracker(record_path=str(updatable_criteria_csv)) separate_tracker.load_records() for criteria_rec in separate_tracker: assert criteria_rec.EngineerTraction == EXPECTED_VALUE assert criteria_rec.FixRatio == EXPECTED_VALUE assert criteria_rec.TotalAlerts == 0 assert criteria_rec.LastUpdatedOn == EXPECTED_LAST_UPDATE assert criteria_rec.AllowSync is True
def handle(self, *args, **options): if options.get('individually'): return self._handle_individually(options) quant_period = options['quantifying_period'] bug_cooldown = options['bug_cooldown'] multiprocessed = options['multiprocessing'] init_params = (None, quant_period, bug_cooldown) formula_map = { 'EngineerTraction': EngineerTractionFormula(*init_params), 'FixRatio': FixRatioFormula(*init_params), } tracker = CriteriaTracker(formula_map, multiprocessed=multiprocessed) tracker.load_records() start = time.time() tracker.update_records() duration = time.time() - start print(f'{self.INITIAL_PROMPT_MSG}', end='') for record in tracker: print(record) print(f"Took {duration:.1f} seconds")
def test_tracker_lets_web_service_rest(mock_formula_map, updatable_criteria_csv): tracker = CriteriaTracker( formula_map=mock_formula_map, record_path=str(updatable_criteria_csv), webservice_rest_time=timedelta(seconds=0.01), ) tracker.load_records() with should_take_more_than(0.01): tracker.update_records()
def test_tracker_has_a_list_of_records(): tracker = CriteriaTracker(record_path=RECORD_TEST_PATH) tracker.load_records() record_list = list(iter(tracker)) assert len(record_list) == 5
def test_tracker_throws_error_if_no_record_file_found(tmp_path): nonexistent_file = str(tmp_path / 'perf-sheriffing-criteria.csv') tracker = CriteriaTracker(record_path=nonexistent_file) with pytest.raises(FileNotFoundError): tracker.load_records()
def test_tracker_throws_error_for_invalid_formulas(invalid_formulas): with pytest.raises(TypeError): CriteriaTracker(formula_map=invalid_formulas)