Пример #1
0
    def test_visit_FunctionDef_mismatch_decs(self):
        variants = test_mock.Variants(
            ["foo", "foo_bar", "pkg_foo_bar", "a"]
        )
        self.visitor._get_mock_decorators_variants = mock.Mock(
            return_value=[variants]
        )
        self.visitor._get_mock_args = mock.Mock(
            return_value=[]
        )

        self.assertIsNone(self.visitor.visit_FunctionDef(self.tree))
        self.assertEqual(
            [
                {
                    "lineno": 2,
                    "messages": [
                        "Missing or malformed argument for {'mock_foo', "
                        "'mock_foo_bar', 'mock_pkg_foo_bar', ...} decorator."
                    ],
                    "args": self.visitor._get_mock_args.return_value,
                    "decs": [variants]
                }
            ],
            self.visitor.errors)

        self.visitor._get_mock_decorators_variants.assert_called_once_with(
            self.tree
        )
        self.visitor._get_mock_args.assert_called_once_with(
            self.tree
        )
Пример #2
0
    def test_visit_FunctionDef_mismatch_args(self):
        variants = test_mock.Variants(
            ["foo", "foo_bar", "pkg_foo_bar", "a"]
        )
        self.visitor._get_mock_decorators_variants = mock.Mock(
            return_value=[variants]
        )
        self.visitor._get_mock_args = mock.Mock(
            return_value=["bar_foo_misnamed", "mismatched"]
        )

        self.assertIsNone(self.visitor.visit_FunctionDef(self.tree))
        self.assertEqual(
            [
                {
                    "lineno": 2,
                    "messages": [
                        "Argument 'bar_foo_misnamed' misnamed; should be "
                        "either of %s that is derived from the mock decorator "
                        "args.\n" % variants,
                        "Missing or malformed decorator for 'mismatched' "
                        "argument."
                    ],
                    "args": self.visitor._get_mock_args.return_value,
                    "decs": [variants]
                }
            ],
            self.visitor.errors)

        self.visitor._get_mock_decorators_variants.assert_called_once_with(
            self.tree
        )
        self.visitor._get_mock_args.assert_called_once_with(
            self.tree
        )
Пример #3
0
    def test_visit_FunctionDef_mismatch_decs(self):
        variants = test_mock.Variants(["foo", "foo_bar", "pkg_foo_bar", "a"])
        self.visitor._get_mock_decorators_variants = mock.Mock(
            return_value=[variants])
        self.visitor._get_mock_args = mock.Mock(return_value=[])

        self.assertIsNone(self.visitor.visit_FunctionDef(self.tree))
        if sys.version_info < (3, 8):
            # https://github.com/python/cpython/pull/9731
            lineno = 2
        else:
            lineno = 7
        self.assertEqual([{
            "lineno":
            lineno,
            "messages": [
                "Missing or malformed argument for {'mock_foo', "
                "'mock_foo_bar', 'mock_pkg_foo_bar', ...} decorator."
            ],
            "args":
            self.visitor._get_mock_args.return_value,
            "decs": [variants]
        }], self.visitor.errors)

        self.visitor._get_mock_decorators_variants.assert_called_once_with(
            self.tree)
        self.visitor._get_mock_args.assert_called_once_with(self.tree)
Пример #4
0
    def test_visit_FunctionDef_mismatch_args(self):
        variants = test_mock.Variants(["foo", "foo_bar", "pkg_foo_bar", "a"])
        self.visitor._get_mock_decorators_variants = mock.Mock(
            return_value=[variants])
        self.visitor._get_mock_args = mock.Mock(
            return_value=["bar_foo_misnamed", "mismatched"])

        self.assertIsNone(self.visitor.visit_FunctionDef(self.tree))
        if sys.version_info < (3, 8):
            # https://github.com/python/cpython/pull/9731
            lineno = 2
        else:
            lineno = 7
        self.assertEqual([{
            "lineno":
            lineno,
            "messages": [
                "Argument 'mock_bar_foo_misnamed' misnamed; should be "
                "either of %s that is derived from the mock decorator "
                "args.\n" % variants,
                "Missing or malformed decorator for 'mock_mismatched' "
                "argument."
            ],
            "args":
            self.visitor._get_mock_args.return_value,
            "decs": [variants]
        }], self.visitor.errors)

        self.visitor._get_mock_decorators_variants.assert_called_once_with(
            self.tree)
        self.visitor._get_mock_args.assert_called_once_with(self.tree)
Пример #5
0
 def test_print_long(self):
     variants = test_mock.Variants(["test", "foo", "bar", "buz"])
     self.assertEqual(
         "{'mock_test', 'mock_foo', 'mock_bar', ...}",
         repr(variants)
     )
Пример #6
0
 def setUp(self):
     self.variants = test_mock.Variants(["test", "foo", "bar"])
     super(VariantsTestCase, self).setUp()