Exemplo n.º 1
0
    def test_init_with_recursive_requirements(self):
        requirements_content = "foo >= 1.0.0\n-r inner.txt\nbar <= 1.0.0\n"
        inner_content = "# inner\nbaz\n\nqux\n"
        setup_content = ""

        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=requirements_content).return_value,
                    mock.mock_open(read_data=inner_content).return_value,
                    mock.mock_open(read_data=setup_content).return_value,
                )

                checker = Flake8Checker(None, None)
                self.assertEqual(
                    sorted(checker.requirements, key=lambda x: x.project_name),
                    sorted(parse_requirements([
                        "foo >= 1.0.0",
                        "baz",
                        "qux",
                        "bar <= 1.0.0",
                    ]),
                           key=lambda x: x.project_name),
                )
Exemplo n.º 2
0
 def test_init_with_no_requirements(self):
     with mock.patch("os.path.exists", return_value=False) as exists:
         with mock.patch(builtins_open, mock.mock_open()) as m:
             checker = Flake8Checker(None, None)
             self.assertEqual(checker.requirements, ())
             m.assert_called_once_with("setup.py")
         exists.assert_called_once_with("requirements.txt")
Exemplo n.º 3
0
 def test_init_misc(self):
     curdir = os.path.abspath(os.path.dirname(__file__))
     with open(os.path.join(curdir, "test_requirements.txt")) as f:
         requirements_content = f.read()
     with mock.patch(
             builtins_open,
             mock_open_multiple(
                 files=OrderedDict((("requirements.txt",
                                     requirements_content), )))):
         checker = Flake8Checker(None, None)
         self.assertEqual(
             checker.get_requirements_txt(),
             tuple(
                 parse_requirements([
                     "nose",
                     "apache == 0.6.9",
                     "coverage[graph,test] ~= 3.1",
                     "graph <2.0, >=1.2 ; python_version < '3.8'",
                     "foo-project >= 1.2",
                     "bar-project == 8.8",
                     "configuration",
                     "blackBox == 1.4.4",
                     "exPackage_paint == 1.4.8.dev1984+49a8814",
                     "package-one",
                     "package-two",
                     "whiteBox",
                 ])),
         )
Exemplo n.º 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",)]))
 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
 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",
             ])),
         )
Exemplo n.º 7
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",
                ])),
            )
Exemplo n.º 8
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",)]))
Exemplo n.º 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
    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),
                )
Exemplo n.º 11
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",
                 ])),
         )
Exemplo n.º 12
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",
                ])),
            )
Exemplo n.º 13
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
Exemplo n.º 14
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(), ())
 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")