def test_exposure_parser_mandatory(capsys): """Check that either the exposure time or the number of images is required.""" with pytest.raises(SystemExit, match="2"): exposure_parser.parse_args([]) assert ( "error: one of the arguments -e/--exposure-time -n/--num-images is required" in capsys.readouterr().err)
def test_exposure_time_no_help(capsys): """Check that this parser does not introduce a help flag.""" for flag in "-h", "--help": with pytest.raises(SystemExit, match="2"): exposure_parser.parse_args(["-e", ".1", flag]) assert f"error: unrecognized arguments: {flag}" in capsys.readouterr( ).err
def test_exposure_parser_invalid_image_number(capsys): """Check that mal-formed image number values are rejected with a help message.""" for number in "100.", "a", "100s", "0", "-1": with pytest.raises(SystemExit, match="2"): exposure_parser.parse_args(["-n", number]) msg = f"error: argument -n/--num-images: invalid positive_int value: '{number}'" assert msg in capsys.readouterr().err
def test_exposure_parser_invalid_exposure_time(capsys): """Check that mal-formed exposure time values are rejected with a help message.""" for e in "foo", "1m", "0", "0s", "-1": with pytest.raises(SystemExit, match="2"): exposure_parser.parse_args(["-e", e]) assert ( f"error: argument -e/--exposure-time: invalid units_of_time value: '{e}'" in capsys.readouterr().err)
def test_exposure_parser_exposure_time(): """Test the behaviour of the exposure time/image number parser's exposure flag.""" for flag in "-e", "--exposure-time": args = exposure_parser.parse_args([flag, ".1"]) assert args.exposure_time == pint.Quantity(100, "ms") assert args.num_images is None for exposure in ".1s", "ms", "100µs": args = exposure_parser.parse_args(["-e", exposure]) assert args.exposure_time == pint.Quantity(exposure)
def test_exposure_time_mutually_exclusive(capsys): """Check that the exposure time and image number args are mutually exclusive.""" with pytest.raises(SystemExit, match="2"): exposure_parser.parse_args(["-e", ".1", "-n", "100"]) assert ( "error: argument -n/--num-images: not allowed with argument -e/--exposure-time" in capsys.readouterr().err) with pytest.raises(SystemExit, match="2"): exposure_parser.parse_args(["-n", "100", "-e", ".1"]) assert ( "error: argument -e/--exposure-time: not allowed with argument -n/--num-images" in capsys.readouterr().err)
def test_exposure_parser_image_number(): """Test the behaviour of the exposure time/image number parser's images flag.""" for flag in "-n", "--num-images": args = exposure_parser.parse_args([flag, "100"]) assert args.exposure_time is None assert args.num_images == 100