コード例 #1
0
    def test_subcommand_ghostwrite(self) -> None:
        # fmt: off
        argv = [
            "ghostwrite",
            "--module", "some_module",
            "--include", "include-something",
            "--exclude", "exclude-something",
            "--explicit",
            "--bare",
        ]
        # fmt: on
        parser = main._make_argument_parser()
        args, out, err = main._parse_args(parser=parser, argv=argv)
        assert args is not None, "Failed to parse argv {!r}: {}".format(argv, err)

        general, errs = _general.parse_params(args=args)

        self.assertListEqual([], errs)
        assert general is not None
        self.assertListEqual(
            [re.compile(pattern) for pattern in ["include-something"]], general.include
        )
        self.assertListEqual(
            [re.compile(pattern) for pattern in ["exclude-something"]], general.exclude
        )

        ghostwrite, errs = _ghostwrite.parse_params(args=args)

        self.assertListEqual([], errs)
        assert ghostwrite is not None
        self.assertEqual("some_module", ghostwrite.module_name)
        self.assertTrue(ghostwrite.explicit)
        self.assertTrue(ghostwrite.bare)
コード例 #2
0
    def test_invalid_settings(self) -> None:
        # fmt: off
        argv = [
            "test",
            "--path",
            "some_module.py",
            "--setting",
            "max_examples=-1",
        ]
        # fmt: on

        parser = main._make_argument_parser()
        args, out, err = main._parse_args(parser=parser, argv=argv)
        assert args is not None, "Failed to parse argv {!r}: {}".format(
            argv, err)

        general, errs = _general.parse_params(args=args)
        self.assertListEqual([], errs)

        test, errs = _test.parse_params(args=args)
        self.assertListEqual(
            [
                "Invalid Hypothesis settings: max_examples=-1 should be at least one. You can "
                "disable example generation with the `phases` setting instead."
            ],
            errs,
        )
コード例 #3
0
    def test_subcommand_test(self) -> None:
        # fmt: off
        argv = [
            "test",
            "--path",
            "some_module.py",
            "--include",
            "include-something",
            "--exclude",
            "exclude-something",
            "--setting",
            'suppress_health_check=["too_slow"]',
            'verbosity="verbose"',
        ]
        # fmt: on

        parser = main._make_argument_parser()
        args, out, err = main._parse_args(parser=parser, argv=argv)
        assert args is not None, "Failed to parse argv {!r}: {}".format(
            argv, err)

        general, errs = _general.parse_params(args=args)

        self.assertListEqual([], errs)
        assert general is not None
        self.assertListEqual(
            [re.compile(pattern) for pattern in ["include-something"]],
            general.include)
        self.assertListEqual(
            [re.compile(pattern) for pattern in ["exclude-something"]],
            general.exclude)

        test, errs = _test.parse_params(args=args)

        self.assertListEqual([], errs)
        assert test is not None
        self.assertEqual(pathlib.Path("some_module.py"), test.path)

        assert test.settings_parsing is not None

        self.assertListEqual(
            [hypothesis.HealthCheck.too_slow],
            test.settings_parsing.product.__dict__["suppress_health_check"],
        )

        self.assertEqual(
            hypothesis.Verbosity.verbose,
            test.settings_parsing.product.__dict__["verbosity"],
        )
コード例 #4
0
    def test_unknown_settings(self) -> None:
        # fmt: off
        argv = [
            "test",
            "--path",
            "some_module.py",
            "--setting",
            "totally_invalid=[2, 3]",
        ]
        # fmt: on

        parser = main._make_argument_parser()
        args, out, err = main._parse_args(parser=parser, argv=argv)
        assert args is not None, "Failed to parse argv {!r}: {}".format(
            argv, err)

        general, errs = _general.parse_params(args=args)
        self.assertListEqual([], errs)

        test, errs = _test.parse_params(args=args)
        self.assertListEqual(["Invalid Hypothesis setting: 'totally_invalid'"],
                             errs)
コード例 #5
0
    def test_path_as_input(self) -> None:
        # fmt: off
        argv = [
            "ghostwrite",
            "--path", "path/to/some_module.py"
        ]
        # fmt: on
        parser = main._make_argument_parser()
        args, out, err = main._parse_args(parser=parser, argv=argv)
        assert args is not None, "Failed to parse argv {!r}: {}".format(argv, err)

        general, errs = _general.parse_params(args=args)

        self.assertListEqual([], errs)
        assert general is not None

        ghostwrite, errs = _ghostwrite.parse_params(args=args)

        self.assertListEqual([], errs)
        assert ghostwrite is not None
        assert ghostwrite.path is not None
        assert ghostwrite.module_name is None

        self.assertEqual("path/to/some_module.py", ghostwrite.path.as_posix())