Exemple #1
0
    def test_no_default_matcher_if_no_layers_match(self, plot_mode):
        svg = ElementTree.fromstring(
            """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <svg
              xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape">
            <g
               inkscape:groupmode="layer"
               id="layer1"
               inkscape:label="Background">
            </g>
            <g
               inkscape:groupmode="layer"
               id="layer2"
               inkscape:label="Drawing">
            </g>
            </svg>
        """)

        parser = make_argument_parser()
        args = parser.parse_args(["-"])

        args.svg = svg
        args.plot_mode = plot_mode

        parse_visibility_arguments(parser, args)

        assert args.visible_object_matchers is None
Exemple #2
0
    def test_disable_regmarks(self):
        parser = make_argument_parser()
        args = parser.parse_args(["-", "--no-regmarks"])

        parse_regmarks(parser, args)

        assert args.regmarks is None
Exemple #3
0
    def test_default_matcher(self, plot_mode, layer_name):
        svg = ElementTree.fromstring(
            """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <svg
              xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape">
            <g
               inkscape:groupmode="layer"
               id="layer1"
               inkscape:label="{}">
            </g>
            <g
               inkscape:groupmode="layer"
               id="layer2"
               inkscape:label="Drawing">
            </g>
            </svg>
        """.format(layer_name))

        parser = make_argument_parser()
        args = parser.parse_args(["-"])

        args.svg = svg
        args.plot_mode = plot_mode

        parse_visibility_arguments(parser, args)

        assert len(args.visible_object_matchers) == 1

        m = args.visible_object_matchers[0]
        assert m(svg) is False
        assert m(svg.find(".//*[@id='layer1']")) is True
        assert m(svg.find(".//*[@id='layer2']")) is False
Exemple #4
0
    def test_automatic_regmarks_none_on_page(self, svg):
        parser = make_argument_parser()
        args = parser.parse_args(["-"])
        args.svg = svg

        parse_regmarks(parser, args)

        assert args.regmarks is None
Exemple #5
0
    def test_automatic_regmarks(self, svg, find_regmarks, force):
        parser = make_argument_parser()
        args = parser.parse_args(["-"] + force)
        args.svg = svg

        parse_regmarks(parser, args)

        assert args.regmarks == find_regmarks()
Exemple #6
0
    def test_pass_through_matchers(self):
        svg = ElementTree.fromstring(
            """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
            <svg
              xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape">
            <g
               inkscape:groupmode="layer"
               id="layer1"
               inkscape:label="Foo bar">
            </g>
            <g
               inkscape:groupmode="layer"
               id="layer2"
               inkscape:label="Baz qux">
            </g>
            <g
               inkscape:groupmode="layer"
               id="layer3"
               class="hello there"
               inkscape:label="Quo arb">
            </g>
            </svg>
        """)

        parser = make_argument_parser()
        args = parser.parse_args([
            "-",
            "--layer",
            "Foo bar",
            "--id",
            "layer2",
            "--class",
            "hello",
        ])

        parse_visibility_arguments(parser, args)

        assert len(args.visible_object_matchers) == 3

        m = args.visible_object_matchers[0]
        assert m(svg) is False
        assert m(svg.find(".//*[@id='layer1']")) is True
        assert m(svg.find(".//*[@id='layer2']")) is False
        assert m(svg.find(".//*[@id='layer3']")) is False

        m = args.visible_object_matchers[1]
        assert m(svg) is False
        assert m(svg.find(".//*[@id='layer1']")) is False
        assert m(svg.find(".//*[@id='layer2']")) is True
        assert m(svg.find(".//*[@id='layer3']")) is False

        m = args.visible_object_matchers[2]
        assert m(svg) is False
        assert m(svg.find(".//*[@id='layer1']")) is False
        assert m(svg.find(".//*[@id='layer2']")) is False
        assert m(svg.find(".//*[@id='layer3']")) is True
Exemple #7
0
    def test_conflicts(self, arg, capsys):
        parser = make_argument_parser()
        args = parser.parse_args(["-", "--all"] + arg)

        with pytest.raises(SystemExit):
            parse_visibility_arguments(parser, args)

        out, err = capsys.readouterr()

        assert "--all cannot be used with" in err
Exemple #8
0
    def test_specify_missing_device(self, mock_devices, arg, capsys):
        parser = make_argument_parser()
        args = parser.parse_args(["-"] + arg)

        with pytest.raises(SystemExit):
            parse_device_arguments(parser, args)

        out, err = capsys.readouterr()

        assert "Device {!r} not found".format(arg[-1]) in err
Exemple #9
0
    def test_automatic_regmarks_none_on_page_forced(self, svg, capsys):
        parser = make_argument_parser()
        args = parser.parse_args(["-", "--regmarks"])
        args.svg = svg

        with pytest.raises(SystemExit):
            parse_regmarks(parser, args)

        out, err = capsys.readouterr()

        assert "--regmarks" in err
Exemple #10
0
    def test_invalid_force(self, capsys):
        parser = make_argument_parser()
        args = parser.parse_args(["-", "--force", "101%"])
        args.device = DummyDevice()

        with pytest.raises(SystemExit):
            parse_speed_and_force(parser, args)

        out, err = capsys.readouterr()

        assert "--force" in err
Exemple #11
0
    def test_invalid_manual_regmarks(self, svg, capsys):
        parser = make_argument_parser()
        args = parser.parse_args(
            ["-", "--manual-regmarks", "10furlongs", "20mm", "30mm", "40mm"])
        args.svg = svg

        with pytest.raises(SystemExit):
            parse_regmarks(parser, args)

        out, err = capsys.readouterr()

        assert "--manual-regmarks" in err
Exemple #12
0
    def test_manual_regmarks(self, svg):
        parser = make_argument_parser()
        args = parser.parse_args(
            ["-", "--manual-regmarks", "10mm", "20mm", "30mm", "40mm"])
        args.svg = svg

        parse_regmarks(parser, args)

        assert args.regmarks.x == 10
        assert args.regmarks.y == 20
        assert args.regmarks.width == 30
        assert args.regmarks.height == 40
Exemple #13
0
    def test_no_devices(self, enumerate_devices, capsys):
        enumerate_devices.return_value = []

        parser = make_argument_parser()
        args = parser.parse_args(["-"])

        with pytest.raises(SystemExit):
            parse_device_arguments(parser, args)

        out, err = capsys.readouterr()

        assert "No connected devices found" in err
Exemple #14
0
    def test_use_first_by_default(self, mock_devices):
        parser = make_argument_parser()
        args = parser.parse_args(["-"])

        parse_device_arguments(parser, args)
        assert args.device == 100
Exemple #15
0
    def test_specify_device(self, mock_devices, arg, exp):
        parser = make_argument_parser()
        args = parser.parse_args(["-"] + arg)

        parse_device_arguments(parser, args)
        assert args.device == exp
Exemple #16
0
 def parser(self):
     return make_argument_parser()
Exemple #17
0
 def test_valid_force(self):
     parser = make_argument_parser()
     args = parser.parse_args(["-", "--force", "100%"])
     args.device = DummyDevice()
     parse_speed_and_force(parser, args)
     assert args.force == args.device.params.tool_force_max