예제 #1
0
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"
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
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