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),
Beispiel #2
0
 def test_resolve_requirement_with_file_content(self):
     content = "foo >= 1.0.0\nbar <= 1.0.0\n"
     with mock.patch(builtins_open, mock.mock_open(read_data=content)):
         self.assertEqual(
             Flake8Checker.resolve_requirement("-r requirements.txt", 1),
             ["foo >= 1.0.0", "bar <= 1.0.0"],
         )
Beispiel #3
0
 def test_resolve_requirement_with_file_empty(self):
     with mock.patch(builtins_open, mock.mock_open()) as m:
         self.assertEqual(
             Flake8Checker.resolve_requirement("-r requirements.txt", 1),
             [],
         )
         m.assert_called_once_with("requirements.txt")
Beispiel #4
0
 def test_resolve_requirement_with_file_content_line_continuation_2(self):
     content = "foo \\\n>= 1.0.0 \\\n# comment \\\nbar \\"
     with mock.patch(builtins_open, mock.mock_open(read_data=content)):
         self.assertEqual(
             Flake8Checker.resolve_requirement("-r requirements.txt", 1),
             ["foo", "bar"],
         )
 def test_resolve_requirement_with_file_content_line_continuation_2(self):
     with mock.patch(builtins_open, mock_open_multiple(files=OrderedDict((
         ("requirements.txt", "foo \\\n>= 1.0.0 \\\n# comment \\\nbar \\"),
     )))):
         self.assertEqual(
             Flake8Checker.resolve_requirement("-r requirements.txt", 1),
             ["foo", "bar"],
         )
 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"],
         )
 def test_resolve_requirement_with_file_content(self):
     with mock.patch(
             builtins_open,
             mock_open_multiple(
                 files=OrderedDict((("requirements.txt",
                                     "foo >= 1.0.0\nbar <= 1.0.0\n"), )))):
         self.assertEqual(
             Flake8Checker.resolve_requirement("-r requirements.txt", 1),
             ["foo >= 1.0.0", "bar <= 1.0.0"],
         )
Beispiel #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"],
            )
 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"),
         ])
Beispiel #10
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),
Beispiel #11
0
 def test_resolve_requirement_with_file_beyond_max_depth(self):
     with self.assertRaises(RuntimeError):
         Flake8Checker.resolve_requirement("-r requirements.txt")
Beispiel #12
0
 def test_resolve_requirement_with_simple(self):
     self.assertEqual(
         Flake8Checker.resolve_requirement("foo >= 1.0.0"),
         ["foo >= 1.0.0"],
     )
Beispiel #13
0
 def test_resolve_requirement_with_comment(self):
     self.assertEqual(
         Flake8Checker.resolve_requirement("#-r requirements.txt"),
         [],
     )
Beispiel #14
0
 def test_resolve_requirement_with_blank(self):
     self.assertEqual(Flake8Checker.resolve_requirement(""), [])
 def test_resolve_requirement_standalone_option(self):
     self.assertEqual(
         Flake8Checker.resolve_requirement("--extra-index-url"),
         [],
     )
 def test_resolve_requirement_with_option(self):
     self.assertEqual(
         Flake8Checker.resolve_requirement("foo-bar.v1==1.0 --option"),
         ["foo-bar.v1"],
     )