def test_random_clusters(): """Test contamination rate of clustered arrangement with random distribution""" random_seed(42) config = load_configuration_yaml_from_text(RANDOM_CONFIG)["contamination"] num_items = 550 consignment = get_consignment(num_items) add_contaminant_clusters(config, consignment) contamination_rate = 0.12 contaminated_items = int(num_items * contamination_rate) assert np.count_nonzero(consignment.items) == contaminated_items
def test_inspect_not_in_program(): """Check inspection is requested when consignment is not in the program""" program = FixedComplianceLevelSkipLot( load_configuration_yaml_from_text(CONFIG)["release_programs"]["fixed_skip_lot"] ) consignment = simple_consignment(flower="Rosa", origin="Netherlands") for seed in range(10): random_seed(seed) inspect, program_name = program(consignment, consignment.date) assert inspect assert program_name == "Skip Lot"
def test_never_inspect_in_program(): """Inspection is not requested when consignment is in a zero inspections level""" program = FixedComplianceLevelSkipLot( load_configuration_yaml_from_text(CONFIG)["release_programs"]["fixed_skip_lot"] ) consignment = simple_consignment(flower="Gerbera", origin="Mexico") for seed in range(10): random_seed(seed) inspect, program_name = program(consignment, consignment.date) assert ( not inspect ), "We disabled inspections completely for this inspection level" assert program_name == "Skip Lot"
def test_sometimes_inspect_in_program(): """Inspection is requested at least sometimes when consignment is in the program""" program = FixedComplianceLevelSkipLot( load_configuration_yaml_from_text(CONFIG)["release_programs"]["fixed_skip_lot"] ) consignment = simple_consignment(flower="Hyacinthus", origin="Netherlands") inspected = 0 for seed in range(10): random_seed(seed) inspect, program_name = program(consignment, consignment.date) inspected += int(inspect) assert program_name == "Skip Lot" assert inspected, "With the seeds, we expect at least one inspection to happen"
def test_naive_cfrp(): """Check that naive CFRP program is accepted and gives expected results""" consignment_generator = get_consignment_generator( load_configuration_yaml_from_text(BASE_CONSIGNMENT_CONFIG) ) is_needed_function = get_inspection_needed_function( load_configuration_yaml_from_text(NAIVE_CFRP_CONFIG) ) # The following assumes what is the default returned by the get function, # i.e., it relies on its internals, not the interface. # pylint: disable=comparison-with-callable assert is_needed_function != inspect_always for seed in range(10): # We run with different, but fixed seeded so we can know which seed fails. random_seed(seed) consignment = consignment_generator.generate_consignment() inspect, program = is_needed_function(consignment, consignment.date) assert isinstance(inspect, bool) assert program == "naive_cfrp" or program is None
def test_cfrp(tmp_path): """Check that CFRP program is accepted and gives expected results""" schedule_file = tmp_path / "schedule_file.csv" schedule_file.write_text(SCHEDULE_CSV_TEXT) consignment_generator = get_consignment_generator( load_configuration_yaml_from_text(BASE_CONSIGNMENT_CONFIG)) is_needed_function = get_inspection_needed_function( load_configuration_yaml_from_text( CFRP_CONFIG.format(schedule_file=schedule_file))) # The following assumes what is the default returned by the get function, # i.e., it relies on its internals, not the interface. # pylint: disable=comparison-with-callable assert is_needed_function != inspect_always for seed in range(10): # We run with different, but fixed seeded so we can know which seed fails. random_seed(seed) consignment = consignment_generator.generate_consignment() inspect, program = is_needed_function(consignment, consignment.date) assert isinstance(inspect, bool) # Testing custom name assert program == "CFRP" or program is None