Skip to content

Commit

Permalink
Staying the effects of mocked functions on filter-related test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
raimon49 committed May 3, 2021
1 parent a585b30 commit 6c5b54b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion test_piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def get_installed_distributions_mocked(*args, **kwargs):


get_installed_distributions_orig = piplicenses.get_installed_distributions
piplicenses.get_installed_distributions = get_installed_distributions_mocked


class CommandLineTestCase(unittest.TestCase):
Expand Down Expand Up @@ -406,6 +405,8 @@ def test_format_markdown(self):
@unittest.skipIf(sys.version_info < (3, 6, 0),
"To unsupport Python 3.5 in the near future")
def test_format_rst_without_filter(self):
piplicenses.get_installed_distributions = \
get_installed_distributions_mocked
format_rst_args = ['--format=rst']
args = self.parser.parse_args(format_rst_args)
table = create_licenses_table(args)
Expand All @@ -417,8 +418,12 @@ def test_format_rst_without_filter(self):
self.assertEqual(RULE_ALL, table.hrules)
with self.assertRaises(docutils.utils.SystemMessage):
self.check_rst(str(table))
piplicenses.get_installed_distributions = \
get_installed_distributions_orig

def test_format_rst_default_filter(self):
piplicenses.get_installed_distributions = \
get_installed_distributions_mocked
format_rst_args = ['--format=rst', '--filter-strings']
args = self.parser.parse_args(format_rst_args)
table = create_licenses_table(args)
Expand All @@ -429,6 +434,8 @@ def test_format_rst_default_filter(self):
self.assertEqual('+', table.junction_char)
self.assertEqual(RULE_ALL, table.hrules)
self.check_rst(str(table))
piplicenses.get_installed_distributions = \
get_installed_distributions_orig

def test_format_confluence(self):
format_confluence_args = ['--format=confluence']
Expand Down Expand Up @@ -534,20 +541,32 @@ def test_output_colored_bold(self):
self.assertTrue(actual.endswith('\033[0m'))

def test_without_filter(self):
piplicenses.get_installed_distributions = \
get_installed_distributions_mocked
args = self.parser.parse_args([])
packages = list(piplicenses.get_packages(args))
self.assertIn(UNICODE_APPENDIX, packages[-1]["name"])
piplicenses.get_installed_distributions = \
get_installed_distributions_orig

def test_with_default_filter(self):
piplicenses.get_installed_distributions = \
get_installed_distributions_mocked
args = self.parser.parse_args(["--filter-strings"])
packages = list(piplicenses.get_packages(args))
piplicenses.get_installed_distributions = \
get_installed_distributions_orig
self.assertNotIn(UNICODE_APPENDIX, packages[-1]["name"])

def test_with_specified_filter(self):
piplicenses.get_installed_distributions = \
get_installed_distributions_mocked
args = self.parser.parse_args(["--filter-strings",
"--filter-code-page=ascii"])
packages = list(piplicenses.get_packages(args))
self.assertNotIn(UNICODE_APPENDIX, packages[-1]["summary"])
piplicenses.get_installed_distributions = \
get_installed_distributions_orig


class MockStdStream(object):
Expand Down

0 comments on commit 6c5b54b

Please sign in to comment.