Ejemplo n.º 1
0
 def test_alignment_bad(self) -> None:
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--alignment"])
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--alignment", "1"])
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--alignment", "1", "nope"])
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--alignment", "1", "2"])
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--alignment", "1", "-1"])
Ejemplo n.º 2
0
 def test_empty(self) -> None:
     args = parse_arguments([""])
     assert args.page_width == 210
     assert args.page_height == 297
     assert args.margin == 5
     assert args.pictures == []
     assert args.output_filename == "out.pdf"
Ejemplo n.º 3
0
    def test_alignment(self) -> None:
        args = parse_arguments([
            "",
            "--picture-dimensions",
            "1",
            "2",
            TEST_JPEG_PORTRAIT,
            "--alignment",
            "0.5",
            "0.5",
            TEST_JPEG_PORTRAIT,
            "--alignment",
            "0.0",
            "0.0",
            TEST_JPEG_PORTRAIT,
        ])

        assert len(args.pictures) == 3

        assert args.pictures[0].x_offset or args.pictures[0].y_offset

        assert args.pictures[0].x_offset == args.pictures[1].x_offset
        assert args.pictures[0].y_offset == args.pictures[1].y_offset

        assert args.pictures[2].x_offset == 0
        assert args.pictures[2].y_offset == 0
Ejemplo n.º 4
0
 def test_page_dimensions_bad_args(self) -> None:
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--page-dimensions"])
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--page-dimensions", "100"])
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--page-dimensions", "100", "nope"])
Ejemplo n.º 5
0
    def test_picture_dimensions(self) -> None:
        args = parse_arguments([
            "",
            "--picture-dimensions",
            "10",
            "20",
            TEST_JPEG_SQUARE,
            "--picture-dimensions",
            "30",
            "40",
            TEST_JPEG_SQUARE,
        ])

        assert len(args.pictures) == 2
        assert args.pictures[0].width == 10
        assert args.pictures[0].height == 20
        assert args.pictures[1].width == 30
        assert args.pictures[1].height == 40
Ejemplo n.º 6
0
    def test_rotate_for_best_fit(self) -> None:
        args = parse_arguments([
            "",
            "--scale",
            "--picture-dimensions",
            "60",
            "90",
            TEST_JPEG_LANDSCAPE,
            "--rotate-for-best-fit",
            TEST_JPEG_LANDSCAPE,
            "--no-rotate-for-best-fit",
            TEST_JPEG_LANDSCAPE,
        ])

        assert len(args.pictures) == 3
        assert args.pictures[0].rotate_image
        assert args.pictures[1].rotate_image
        assert not args.pictures[2].rotate_image
Ejemplo n.º 7
0
    def test_dpi(self) -> None:
        args = parse_arguments([
            "",
            "--picture-dimensions",
            "100",
            "100",
            "--max-dpi",
            "25.4",  # 1 dot per mm
            TEST_JPEG_SQUARE,
            "--max-dpi",
            "0",  # unlimited dpi
            TEST_JPEG_SQUARE,
        ])

        assert len(args.pictures) == 2

        assert args.pictures[0].image_width == 100
        assert args.pictures[0].image_height == 100

        assert args.pictures[1].image_width == 256
        assert args.pictures[1].image_height == 256
Ejemplo n.º 8
0
    def test_scale_or_crop(self) -> None:
        args = parse_arguments([
            "",
            "--picture-dimensions",
            "10",
            "20",
            TEST_JPEG_SQUARE,
            "--scale",
            TEST_JPEG_SQUARE,
            "--crop",
            TEST_JPEG_SQUARE,
        ])

        assert len(args.pictures) == 3

        assert args.pictures[0].width == 10
        assert args.pictures[0].height == 20

        assert args.pictures[1].width == 10
        assert args.pictures[1].height == 10

        assert args.pictures[2].width == 10
        assert args.pictures[2].height == 20
Ejemplo n.º 9
0
 def test_page_dimensions(self) -> None:
     args = parse_arguments(["", "--page-dimensions", "100", "200"])
     assert args.page_width == 100
     assert args.page_height == 200
Ejemplo n.º 10
0
 def test_unknown_argument(self) -> None:
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "-?"])
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--foo"])
Ejemplo n.º 11
0
 def test_dpi_bad(self) -> None:
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--max-dpi"])
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--max-dpi", "nope"])
Ejemplo n.º 12
0
 def test_margin_after_picture(self) -> None:
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", TEST_JPEG_SQUARE, "--margin", "100"])
Ejemplo n.º 13
0
 def test_output_missing(self) -> None:
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--output"])
Ejemplo n.º 14
0
 def test_output(self) -> None:
     args = parse_arguments(["", "--output", "foo.pdf"])
     assert args.output_filename == "foo.pdf"
Ejemplo n.º 15
0
 def test_page_dimensions_after_picture(self) -> None:
     with pytest.raises(ArgumentParserError):
         parse_arguments(
             ["", TEST_JPEG_SQUARE, "--page-dimensions", "100", "200"])
Ejemplo n.º 16
0
 def test_margin(self) -> None:
     args = parse_arguments(["", "--margin", "12"])
     assert args.margin == 12
Ejemplo n.º 17
0
 def test_margin_bad_args(self) -> None:
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--margin"])
     with pytest.raises(ArgumentParserError):
         parse_arguments(["", "--margin", "nope"])