def test_argparse(): # Clear args sys.argv.clear() # First is program name sys.argv.append("parseMyPSA") # Then positional arguments sys.argv.append("aa.trip") args = main.option_parser() assert args.input_file == "aa.trip"
def test_input_file_not_specified(): # Clear args sys.argv.clear() # First is program name sys.argv.append("parseMyPSA") # No positional arguments args = main.option_parser() assert args.input_file == None with pytest.raises(SystemExit): _ = main.file_opener(args)
def test_input_file_not_found(): # Clear args sys.argv.clear() # First is program name sys.argv.append("parseMyPSA") # Then positional arguments sys.argv.append("test.trip") args = main.option_parser() assert args.input_file == "test.trip" with pytest.raises(FileNotFoundError): _ = main.file_opener(args)
def test_setup_logging(): # Clear args sys.argv.clear() # First is program name sys.argv.append("parseMyPSA") # Then positional arguments sys.argv.append("aa.trip") # Then optional arguments sys.argv.append("--log-level=DEBUG") args = main.option_parser() assert args.log_level == "DEBUG" main.setup_logging(args)
def test_setup_logging_invalid_value(): # Clear args sys.argv.clear() # First is program name sys.argv.append("parseMyPSA") # Then positional arguments sys.argv.append("aa.trip") # Then optional argiments sys.argv.append("--log-level=DUMMY") args = main.option_parser() assert args.log_level == "DUMMY" with pytest.raises(ValueError): main.setup_logging(args) assert not logging.getLogger().isEnabledFor(logging.DEBUG)
def test_input_file(): input_file = "tests/trips.test" # Clear args sys.argv.clear() # First is program name sys.argv.append("parseMyPSA") # Then positional arguments sys.argv.append(input_file) args = main.option_parser() assert args.input_file == input_file parsed_file = main.file_opener(args) with test_database(test_db, model_list): vin, trips, info = input_parser.parse_input_file(parsed_file) assert vin == "AA" assert objects.Trip.get(objects.Trip.id == 38).distance == 16500 assert objects.Alert.get(objects.Alert.vin == "AA").id == 108