Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests that mistakenly used assertTrue(a,b) instead of assertEqual(a,b) #103

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions tests/test_bandit.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,44 +46,44 @@ def test_analyze_details(self):
result = bandit.analyze(**kwargs)

self.assertIn('loc_analyzed', result)
self.assertTrue(type(result['loc_analyzed']), int)
self.assertEqual(type(result['loc_analyzed']), int)
self.assertIn('num_vulns', result)
self.assertTrue(type(result['num_vulns']), int)
self.assertEqual(type(result['num_vulns']), int)
self.assertIn('by_severity', result)
self.assertTrue(type(result['by_severity']), dict)
self.assertEqual(type(result['by_severity']), dict)
self.assertIn('undefined', result['by_severity'])
self.assertTrue(type(result['by_severity']['undefined']), int)
self.assertEqual(type(result['by_severity']['undefined']), int)
self.assertIn('low', result['by_severity'])
self.assertTrue(type(result['by_severity']['low']), int)
self.assertEqual(type(result['by_severity']['low']), int)
self.assertIn('medium', result['by_severity'])
self.assertTrue(type(result['by_severity']['medium']), int)
self.assertEqual(type(result['by_severity']['medium']), int)
self.assertIn('high', result['by_severity'])
self.assertTrue(type(result['by_severity']['high']), int)
self.assertEqual(type(result['by_severity']['high']), int)

self.assertIn('by_confidence', result)
self.assertTrue(type(result['by_confidence']), dict)
self.assertEqual(type(result['by_confidence']), dict)
self.assertIn('undefined', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['undefined']), int)
self.assertEqual(type(result['by_confidence']['undefined']), int)
self.assertIn('low', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['low']), int)
self.assertEqual(type(result['by_confidence']['low']), int)
self.assertIn('medium', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['medium']), int)
self.assertEqual(type(result['by_confidence']['medium']), int)
self.assertIn('high', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['high']), int)
self.assertEqual(type(result['by_confidence']['high']), int)

self.assertIn('vulns', result)

vd = result['vulns'][0]
self.assertIn('file', vd)
self.assertTrue(type(vd['file']), str)
self.assertEqual(type(vd['file']), str)
self.assertIn('line', vd)
self.assertTrue(type(vd['line']), int)
self.assertEqual(type(vd['line']), int)
self.assertIn('severity', vd)
self.assertTrue(type(vd['severity']), str)
self.assertEqual(type(vd['severity']), str)
self.assertIn('confidence', vd)
self.assertTrue(type(vd['confidence']), str)
self.assertEqual(type(vd['confidence']), str)
self.assertIn('descr', vd)
self.assertTrue(type(vd['descr']), str)
self.assertEqual(type(vd['descr']), str)

def test_analyze_no_details(self):
"""Test whether bandit returns the expected fields data"""
Expand All @@ -96,30 +96,30 @@ def test_analyze_no_details(self):
result = bandit.analyze(**kwargs)

self.assertIn('loc_analyzed', result)
self.assertTrue(type(result['loc_analyzed']), int)
self.assertEqual(type(result['loc_analyzed']), int)
self.assertIn('num_vulns', result)
self.assertTrue(type(result['num_vulns']), int)
self.assertEqual(type(result['num_vulns']), int)
self.assertIn('by_severity', result)
self.assertTrue(type(result['by_severity']), dict)
self.assertEqual(type(result['by_severity']), dict)
self.assertIn('undefined', result['by_severity'])
self.assertTrue(type(result['by_severity']['undefined']), int)
self.assertEqual(type(result['by_severity']['undefined']), int)
self.assertIn('low', result['by_severity'])
self.assertTrue(type(result['by_severity']['low']), int)
self.assertEqual(type(result['by_severity']['low']), int)
self.assertIn('medium', result['by_severity'])
self.assertTrue(type(result['by_severity']['medium']), int)
self.assertEqual(type(result['by_severity']['medium']), int)
self.assertIn('high', result['by_severity'])
self.assertTrue(type(result['by_severity']['high']), int)
self.assertEqual(type(result['by_severity']['high']), int)

self.assertIn('by_confidence', result)
self.assertTrue(type(result['by_confidence']), dict)
self.assertEqual(type(result['by_confidence']), dict)
self.assertIn('undefined', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['undefined']), int)
self.assertEqual(type(result['by_confidence']['undefined']), int)
self.assertIn('low', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['low']), int)
self.assertEqual(type(result['by_confidence']['low']), int)
self.assertIn('medium', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['medium']), int)
self.assertEqual(type(result['by_confidence']['medium']), int)
self.assertIn('high', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['high']), int)
self.assertEqual(type(result['by_confidence']['high']), int)

self.assertNotIn('vulns', result)

Expand Down
20 changes: 10 additions & 10 deletions tests/test_cloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ def test_analyze(self):
result = cloc.analyze(**kwargs)

self.assertIn('blanks', result)
self.assertTrue(type(result['blanks']), int)
self.assertTrue(result['blanks'], 27)
self.assertEqual(type(result['blanks']), int)
self.assertEqual(result['blanks'], 27)
self.assertIn('comments', result)
self.assertTrue(type(result['comments']), int)
self.assertTrue(result['comments'], 31)
self.assertEqual(type(result['comments']), int)
self.assertEqual(result['comments'], 31)
self.assertIn('loc', result)
self.assertTrue(type(result['loc']), int)
self.assertTrue(result['loc'], 67)
self.assertEqual(type(result['loc']), int)
self.assertEqual(result['loc'], 67)

def test_analyze_repository_level(self):
"""Test whether cloc returns the expected fields data for repository level"""
Expand All @@ -74,13 +74,13 @@ def test_analyze_repository_level(self):
result = results[next(iter(results))]

self.assertIn('blanks', result)
self.assertTrue(type(result['blanks']), int)
self.assertEqual(type(result['blanks']), int)
self.assertIn('comments', result)
self.assertTrue(type(result['comments']), int)
self.assertEqual(type(result['comments']), int)
self.assertIn('loc', result)
self.assertTrue(type(result['loc']), int)
self.assertEqual(type(result['loc']), int)
self.assertIn('total_files', result)
self.assertTrue(type(result['total_files']), int)
self.assertEqual(type(result['total_files']), int)

@unittest.mock.patch('subprocess.check_output')
def test_analyze_error(self, check_output_mock):
Expand Down
18 changes: 9 additions & 9 deletions tests/test_codep.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ def test_fetch(self):
self.assertEqual(commit['category'], CATEGORY_CODEP_PYREVERSE)
result = commit['data']['analysis']
self.assertIn('classes', result)
self.assertTrue(type(result['classes']), dict)
self.assertEqual(type(result['classes']), dict)
self.assertIn('nodes', result['classes'])
self.assertTrue(type(result['classes']['nodes']), list)
self.assertEqual(type(result['classes']['nodes']), list)
self.assertIn('links', result['classes'])
self.assertTrue(type(result['classes']['links']), list)
self.assertEqual(type(result['classes']['links']), list)
self.assertIn('packages', result)
self.assertTrue(type(result['packages']), dict)
self.assertTrue(type(result['packages']['nodes']), list)
self.assertEqual(type(result['packages']), dict)
self.assertEqual(type(result['packages']['nodes']), list)
self.assertIn('links', result['packages'])
self.assertTrue(type(result['packages']['links']), list)
self.assertEqual(type(result['packages']['links']), list)

def test_fetch_not_existing_module(self):
"""Test whether warning messages are logged when a module is not found"""
Expand Down Expand Up @@ -294,11 +294,11 @@ def test_analyze_pyreverse(self):
result = dep_analyzer.analyze(module_path)

self.assertIn('classes', result)
self.assertTrue(type(result['classes']), dict)
self.assertEqual(type(result['classes']), dict)
self.assertIn('nodes', result['classes'])
self.assertTrue(type(result['classes']['nodes']), list)
self.assertEqual(type(result['classes']['nodes']), list)
self.assertIn('links', result['classes'])
self.assertTrue(type(result['classes']['links']), list)
self.assertEqual(type(result['classes']['links']), list)

def test_analyze_jadolint(self):
"""Test whether the analyze method works"""
Expand Down
18 changes: 9 additions & 9 deletions tests/test_colang.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ def test_fetch_cloc(self):
result = results[next(iter(results))]

self.assertIn('blanks', result)
self.assertTrue(type(result['blanks']), int)
self.assertEqual(type(result['blanks']), int)
self.assertIn('comments', result)
self.assertTrue(type(result['comments']), int)
self.assertEqual(type(result['comments']), int)
self.assertIn('loc', result)
self.assertTrue(type(result['loc']), int)
self.assertEqual(type(result['loc']), int)
self.assertIn('total_files', result)
self.assertTrue(type(result['total_files']), int)
self.assertEqual(type(result['total_files']), int)

def test_fetch_unknown(self):
"""Test whether commits are properly processed"""
Expand Down Expand Up @@ -187,20 +187,20 @@ def test_analyze(self):
result = repo_analyzer.analyze(self.origin_path)
self.assertNotIn('breakdown', result)
self.assertIn('Python', result)
self.assertTrue(type(result['Python']), float)
self.assertEqual(type(result['Python']), float)

repo_analyzer = RepositoryAnalyzer(kind=CLOC)
results = repo_analyzer.analyze(self.origin_path)
result = results[next(iter(results))]

self.assertIn('blanks', result)
self.assertTrue(type(result['blanks']), int)
self.assertEqual(type(result['blanks']), int)
self.assertIn('comments', result)
self.assertTrue(type(result['comments']), int)
self.assertEqual(type(result['comments']), int)
self.assertIn('loc', result)
self.assertTrue(type(result['loc']), int)
self.assertEqual(type(result['loc']), int)
self.assertIn('total_files', result)
self.assertTrue(type(result['total_files']), int)
self.assertEqual(type(result['total_files']), int)


class TestCoLangCommand(unittest.TestCase):
Expand Down
16 changes: 8 additions & 8 deletions tests/test_coqua.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ def test_fetch_pylint(self):
result = commit['data']['analysis']
self.assertNotIn('modules', result)
self.assertIn('quality', result)
self.assertTrue(type(result['quality']), str)
self.assertEqual(type(result['quality']), str)
self.assertIn('num_modules', result)
self.assertTrue(type(result['num_modules']), int)
self.assertEqual(type(result['num_modules']), int)
self.assertIn('warnings', result)
self.assertTrue(type(result['warnings']), int)
self.assertEqual(type(result['warnings']), int)

def test_fetch_flake8(self):
"""Test whether commits are properly processed"""
Expand All @@ -104,7 +104,7 @@ def test_fetch_flake8(self):
self.assertEqual(commit['category'], CATEGORY_COQUA_FLAKE8)
result = commit['data']['analysis']
self.assertIn('warnings', result)
self.assertTrue(type(result['warnings']), int)
self.assertEqual(type(result['warnings']), int)
self.assertNotIn('lines', result)

def test_fetch_error(self):
Expand Down Expand Up @@ -390,17 +390,17 @@ def test_analyze(self):
result = mod_analyzer.analyze(module_path, self.worktree_path)
self.assertNotIn('modules', result)
self.assertIn('quality', result)
self.assertTrue(type(result['quality']), str)
self.assertEqual(type(result['quality']), str)
self.assertIn('num_modules', result)
self.assertTrue(type(result['num_modules']), int)
self.assertEqual(type(result['num_modules']), int)
self.assertIn('warnings', result)
self.assertTrue(type(result['warnings']), int)
self.assertEqual(type(result['warnings']), int)

mod_analyzer = ModuleAnalyzer(kind=FLAKE8)
result = mod_analyzer.analyze(module_path, self.worktree_path)
self.assertNotIn('lines', result)
self.assertIn('warnings', result)
self.assertTrue(type(result['warnings']), int)
self.assertEqual(type(result['warnings']), int)


class TestCoDepCommand(unittest.TestCase):
Expand Down
48 changes: 24 additions & 24 deletions tests/test_covuln.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,30 @@ def test_fetch(self):
result = commit['data']['analysis']

self.assertIn('loc_analyzed', result)
self.assertTrue(type(result['loc_analyzed']), int)
self.assertEqual(type(result['loc_analyzed']), int)
self.assertIn('num_vulns', result)
self.assertTrue(type(result['num_vulns']), int)
self.assertEqual(type(result['num_vulns']), int)
self.assertIn('by_severity', result)
self.assertTrue(type(result['by_severity']), dict)
self.assertEqual(type(result['by_severity']), dict)
self.assertIn('undefined', result['by_severity'])
self.assertTrue(type(result['by_severity']['undefined']), int)
self.assertEqual(type(result['by_severity']['undefined']), int)
self.assertIn('low', result['by_severity'])
self.assertTrue(type(result['by_severity']['low']), int)
self.assertEqual(type(result['by_severity']['low']), int)
self.assertIn('medium', result['by_severity'])
self.assertTrue(type(result['by_severity']['medium']), int)
self.assertEqual(type(result['by_severity']['medium']), int)
self.assertIn('high', result['by_severity'])
self.assertTrue(type(result['by_severity']['high']), int)
self.assertEqual(type(result['by_severity']['high']), int)

self.assertIn('by_confidence', result)
self.assertTrue(type(result['by_confidence']), dict)
self.assertEqual(type(result['by_confidence']), dict)
self.assertIn('undefined', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['undefined']), int)
self.assertEqual(type(result['by_confidence']['undefined']), int)
self.assertIn('low', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['low']), int)
self.assertEqual(type(result['by_confidence']['low']), int)
self.assertIn('medium', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['medium']), int)
self.assertEqual(type(result['by_confidence']['medium']), int)
self.assertIn('high', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['high']), int)
self.assertEqual(type(result['by_confidence']['high']), int)


class TestModuleAnalyzer(TestCaseAnalyzer):
Expand Down Expand Up @@ -135,30 +135,30 @@ def test_analyze(self):
result = vuln_analyzer.analyze(module_path)

self.assertIn('loc_analyzed', result)
self.assertTrue(type(result['loc_analyzed']), int)
self.assertEqual(type(result['loc_analyzed']), int)
self.assertIn('num_vulns', result)
self.assertTrue(type(result['num_vulns']), int)
self.assertEqual(type(result['num_vulns']), int)
self.assertIn('by_severity', result)
self.assertTrue(type(result['by_severity']), dict)
self.assertEqual(type(result['by_severity']), dict)
self.assertIn('undefined', result['by_severity'])
self.assertTrue(type(result['by_severity']['undefined']), int)
self.assertEqual(type(result['by_severity']['undefined']), int)
self.assertIn('low', result['by_severity'])
self.assertTrue(type(result['by_severity']['low']), int)
self.assertEqual(type(result['by_severity']['low']), int)
self.assertIn('medium', result['by_severity'])
self.assertTrue(type(result['by_severity']['medium']), int)
self.assertEqual(type(result['by_severity']['medium']), int)
self.assertIn('high', result['by_severity'])
self.assertTrue(type(result['by_severity']['high']), int)
self.assertEqual(type(result['by_severity']['high']), int)

self.assertIn('by_confidence', result)
self.assertTrue(type(result['by_confidence']), dict)
self.assertEqual(type(result['by_confidence']), dict)
self.assertIn('undefined', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['undefined']), int)
self.assertEqual(type(result['by_confidence']['undefined']), int)
self.assertIn('low', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['low']), int)
self.assertEqual(type(result['by_confidence']['low']), int)
self.assertIn('medium', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['medium']), int)
self.assertEqual(type(result['by_confidence']['medium']), int)
self.assertIn('high', result['by_confidence'])
self.assertTrue(type(result['by_confidence']['high']), int)
self.assertEqual(type(result['by_confidence']['high']), int)


class TestCoVulnCommand(unittest.TestCase):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def test_analyze_details(self):
result = flake8.analyze(**kwargs)

self.assertIn('lines', result)
self.assertTrue(type(result['lines']), list)
self.assertEqual(type(result['lines']), list)
self.assertIn('warnings', result)
self.assertTrue(type(result['warnings']), int)
self.assertEqual(type(result['warnings']), int)

def test_analyze_no_details(self):
"""Test whether flake8 returns the expected fields data"""
Expand All @@ -68,7 +68,7 @@ def test_analyze_no_details(self):

self.assertNotIn('lines', result)
self.assertIn('warnings', result)
self.assertTrue(type(result['warnings']), int)
self.assertEqual(type(result['warnings']), int)

@unittest.mock.patch('subprocess.check_output')
def test_analyze_error(self, check_output_mock):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_linguist.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def test_analyze_details(self):
result = linguist.analyze(**kwargs)

self.assertIn('breakdown', result)
self.assertTrue(type(result['breakdown']), dict)
self.assertEqual(type(result['breakdown']), dict)
self.assertIn('Python', result)
self.assertTrue(type(result['Python']), float)
self.assertEqual(type(result['Python']), float)

def test_analyze_no_details(self):
"""Test whether linguist returns the expected fields data"""
Expand All @@ -59,7 +59,7 @@ def test_analyze_no_details(self):

self.assertNotIn('breakdown', result)
self.assertIn('Python', result)
self.assertTrue(type(result['Python']), float)
self.assertEqual(type(result['Python']), float)

@unittest.mock.patch('subprocess.check_output')
def test_analyze_error(self, check_output_mock):
Expand Down
Loading