コード例 #1
0
 def test_resolve_requirement_with_file_content_line_continuation(self):
     with mock.patch(
             builtins_open,
             mock_open_multiple(
                 files=OrderedDict((("requirements.txt",
                                     "foo[bar] \\\n>= 1.0.0\n"), )))):
         self.assertEqual(
             Flake8Checker.resolve_requirement("-r requirements.txt", 1),
             ["foo[bar] >= 1.0.0"],
         )
コード例 #2
0
 def test_init_with_recursive_requirements_beyond_max_depth(self):
     with mock.patch(builtins_open, mock_open_multiple(files=OrderedDict((
         ("requirements.txt", "foo >= 1.0.0\n-r inner.txt\nbar <= 1.0.0\n"),
         ("inner.txt", "# inner\nbaz\n\nqux\n"),
     )))):
         with self.assertRaises(RuntimeError):
             try:
                 Flake8Checker.requirements_max_depth = 0
                 checker = Flake8Checker(None, None)
                 checker.get_requirements_txt()
             finally:
                 Flake8Checker.requirements_max_depth = 1
コード例 #3
0
 def test_resolve_requirement_with_file_recursion(self):
     with mock.patch(
             builtins_open,
             mock_open_multiple(files=OrderedDict((
                 ("requirements.txt",
                  "--requirement inner.txt\nbar <= 1.0.0\n"),
                 ("inner.txt", "# inner\nbaz\n\nqux\n"),
             )))):
         self.assertEqual(
             Flake8Checker.resolve_requirement("-r requirements.txt", 2),
             ["baz", "qux", "bar <= 1.0.0"],
         )
コード例 #4
0
    def test_1st_party(self):
        content = "[tool.poetry]\nname='book'\n"

        with mock.patch(builtins_open, mock.mock_open()) as m:
            m.side_effect = (
                IOError("No such file or directory: 'setup.py'"),
                mock.mock_open(read_data=content).return_value,
            )

            checker = Flake8Checker(None, None)
            mods = checker.get_mods_1st_party()
            self.assertEqual(mods, set([("book",)]))
コード例 #5
0
    def test_init_with_simple_requirements(self):
        content = "foo >= 1.0.0\nbar <= 1.0.0\n"
        with mock.patch(builtins_open, mock.mock_open(read_data=content)):

            checker = Flake8Checker(None, None)
            self.assertEqual(
                checker.get_requirements_txt(),
                tuple(parse_requirements([
                    "foo",
                    "bar",
                ])),
            )
コード例 #6
0
 def test_init_with_simple_requirements(self):
     with mock.patch(builtins_open, mock_open_multiple(files=OrderedDict((
         ("requirements.txt", "foo >= 1.0.0\nbar <= 1.0.0\n"),
     )))):
         checker = Flake8Checker(None, None)
         self.assertEqual(
             checker.get_requirements_txt(),
             tuple(parse_requirements([
                 "foo",
                 "bar",
             ])),
         )
コード例 #7
0
    def test_3rd_party(self):
        content = "[tool.poetry.dependencies]\ntools='1.0'\n"
        content += "[tool.poetry.dev-dependencies]\ndev-tools='1.0'\n"

        with mock.patch(builtins_open, mock.mock_open()) as m:
            m.side_effect = (
                IOError("No such file or directory: 'setup.py'"),
                mock.mock_open(read_data=content).return_value,
            )

            checker = Flake8Checker(None, None)
            mods = checker.get_mods_3rd_party()
            self.assertEqual(mods, set([("tools",), ("dev_tools",)]))
コード例 #8
0
    def test_resolve_requirement_with_file_recursion(self):
        content = "foo >= 1.0.0\n-r inner.txt\nbar <= 1.0.0\n"
        inner_content = "# inner\nbaz\n\nqux\n"

        with mock.patch(builtins_open, mock.mock_open()) as m:
            m.side_effect = (
                mock.mock_open(read_data=content).return_value,
                mock.mock_open(read_data=inner_content).return_value,
            )

            self.assertEqual(
                Flake8Checker.resolve_requirement("-r requirements.txt", 2),
                ["foo >= 1.0.0", "baz", "qux", "bar <= 1.0.0"],
            )
コード例 #9
0
    def test_init_with_recursive_requirements_beyond_max_depth(self):
        content = "foo >= 1.0.0\n-r inner.txt\nbar <= 1.0.0\n"
        inner_content = "# inner\nbaz\n\nqux\n"

        with mock.patch(builtins_open, mock.mock_open()) as m:
            m.side_effect = (
                mock.mock_open(read_data=content).return_value,
                mock.mock_open(read_data=inner_content).return_value,
            )

            with self.assertRaises(RuntimeError):
                try:
                    Flake8Checker.requirements_max_depth = 0
                    checker = Flake8Checker(None, None)
                    checker.get_requirements_txt()
                finally:
                    Flake8Checker.requirements_max_depth = 1
コード例 #10
0
 def test_resolve_requirement_with_relative_include(self):
     with mock.patch(builtins_open, mock_open_multiple(files=OrderedDict((
         ("requirements.txt", "-r requirements/production.txt"),
         ("requirements/production.txt", "-r node/one.txt\nfoo"),
         ("requirements/node/one.txt", "-r common.txt\n-r /abs/path.txt"),
         ("requirements/node/common.txt", "bar"),
         ("/abs/path.txt", "bis"),
     )))) as m:
         self.assertEqual(
             Flake8Checker.resolve_requirement("-r requirements.txt", 5),
             ["bar", "bis", "foo"],
         )
         m.assert_has_calls([
             mock.call("requirements.txt"),
             mock.call("requirements/production.txt"),
             mock.call("requirements/node/one.txt"),
             mock.call("requirements/node/common.txt"),
             mock.call("/abs/path.txt"),
         ])
コード例 #11
0
    def test_init_with_simple_requirements(self):
        content = "foo >= 1.0.0\nbar <= 1.0.0\n"

        with mock.patch("os.path.exists", return_value=True):
            with mock.patch(builtins_open, mock.mock_open()) as m:
                m.side_effect = (
                    mock.mock_open(read_data=content).return_value,
                )

                checker = Flake8Checker(None, None)
                requirements = checker.get_requirements_txt()

                self.assertEqual(
                    sorted(requirements, key=lambda x: x.project_name),
                    sorted(parse_requirements([
                        "foo >= 1.0.0",
                        "bar <= 1.0.0",
                    ]), key=lambda x: x.project_name),
                )
コード例 #12
0
 def test_init_with_recursive_requirements(self):
     with mock.patch(
             builtins_open,
             mock_open_multiple(files=OrderedDict((
                 ("requirements.txt",
                  "foo >= 1.0.0\n-r inner.txt\nbar <= 1.0.0\n"),
                 ("inner.txt", "# inner\nbaz\n\nqux\n"),
             )))):
         checker = Flake8Checker(None, None)
         self.assertEqual(
             checker.get_requirements_txt(),
             tuple(
                 parse_requirements([
                     "foo >= 1.0.0",
                     "baz",
                     "qux",
                     "bar <= 1.0.0",
                 ])),
         )
コード例 #13
0
    def test_init_with_recursive_requirements(self):
        content = "foo >= 1.0.0\n-r inner.txt\nbar <= 1.0.0\n"
        inner_content = "# inner\nbaz\n\nqux\n"

        with mock.patch(builtins_open, mock.mock_open()) as m:
            m.side_effect = (
                mock.mock_open(read_data=content).return_value,
                mock.mock_open(read_data=inner_content).return_value,
            )

            checker = Flake8Checker(None, None)
            self.assertEqual(
                checker.get_requirements_txt(),
                tuple(parse_requirements([
                    "foo",
                    "baz",
                    "qux",
                    "bar",
                ])),
            )
コード例 #14
0
 def test_init_with_user_requirements(self):
     with mock.patch(
             builtins_open,
             mock_open_multiple(files=OrderedDict((
                 ("requirements/base.txt", "foo >= 1.0.0\n-r inner.txt\n"),
                 ("requirements/inner.txt", "bar\n"),
             )))) as m:
         try:
             Flake8Checker.requirements_file = "requirements/base.txt"
             checker = Flake8Checker(None, None)
             self.assertEqual(
                 checker.get_requirements_txt(),
                 tuple(parse_requirements([
                     "foo >= 1.0.0",
                     "bar",
                 ])),
             )
             m.assert_has_calls([
                 mock.call("requirements/base.txt"),
                 mock.call("requirements/inner.txt"),
             ])
         finally:
             Flake8Checker.requirements_file = None
コード例 #15
0
 def test_resolve_requirement_standalone_option(self):
     self.assertEqual(
         Flake8Checker.resolve_requirement("--extra-index-url"),
         [],
     )
コード例 #16
0
 def test_get_pyproject_toml_poetry(self):
     content = "[tool.poetry]\nname='x'\n[tool.poetry.tag]\nx=0\n"
     with mock.patch(builtins_open, mock.mock_open(read_data=content)):
         poetry = Flake8Checker.get_pyproject_toml_poetry()
         self.assertDictEqual(poetry, {'name': "x", 'tag': {'x': 0}})
コード例 #17
0
 def test_init_with_no_requirements(self):
     with mock.patch(builtins_open, mock.mock_open()) as m:
         m.side_effect = IOError("No such file or directory"),
         checker = Flake8Checker(None, None)
         self.assertEqual(checker.get_requirements_txt(), ())
コード例 #18
0
 def test_resolve_requirement_with_file_recursion_beyond_max_depth(self):
     content = "-r requirements.txt\n"
     with mock.patch(builtins_open, mock.mock_open(read_data=content)):
         with self.assertRaises(RuntimeError):
             Flake8Checker.resolve_requirement("-r requirements.txt", 1),
コード例 #19
0
 def test_resolve_requirement_with_file_beyond_max_depth(self):
     with self.assertRaises(RuntimeError):
         Flake8Checker.resolve_requirement("-r requirements.txt")
コード例 #20
0
 def test_resolve_requirement_with_simple(self):
     self.assertEqual(
         Flake8Checker.resolve_requirement("foo >= 1.0.0"),
         ["foo >= 1.0.0"],
     )
コード例 #21
0
 def test_resolve_requirement_with_comment(self):
     self.assertEqual(
         Flake8Checker.resolve_requirement("#-r requirements.txt"),
         [],
     )
コード例 #22
0
 def test_resolve_requirement_with_blank(self):
     self.assertEqual(Flake8Checker.resolve_requirement(""), [])
コード例 #23
0
 def test_resolve_requirement_with_file_recursion_beyond_max_depth(self):
     with mock.patch(builtins_open, mock_open_multiple(files=OrderedDict((
         ("requirements.txt", "-r requirements.txt\n"),
     )))):
         with self.assertRaises(RuntimeError):
             Flake8Checker.resolve_requirement("-r requirements.txt", 1),
コード例 #24
0
 def test_init_with_no_requirements(self):
     with mock.patch("os.path.exists", return_value=False) as exists:
         checker = Flake8Checker(None, None)
         requirements = checker.get_requirements_txt()
         self.assertEqual(requirements, ())
         exists.assert_called_once_with("requirements.txt")
コード例 #25
0
 def test_resolve_requirement_with_option(self):
     self.assertEqual(
         Flake8Checker.resolve_requirement("foo-bar.v1==1.0 --option"),
         ["foo-bar.v1"],
     )