Skip to content

Commit 3438cdd

Browse files
committed
Use assert command for tests
Also use proper name for var: test_envt confuse test discovery Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 58ef3a9 commit 3438cdd

File tree

5 files changed

+31
-57
lines changed

5 files changed

+31
-57
lines changed

tests/packagedcode/test_gemfile_lock.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def test_Gem_as_nv_tree(self):
274274
}
275275
}
276276
}
277-
self.assertEqual(expected, a.as_nv_tree())
277+
assert a.as_nv_tree() == expected
278278

279279
def test_Gem_flatten(self):
280280
Gem = gemfile_lock.Gem
@@ -320,7 +320,6 @@ def test_Gem_as_nv_tree_with_no_deps(self):
320320
results = a.as_nv_tree()
321321
assert results == expected
322322

323-
324323
def test_Gem_to_dict(self):
325324
Gem = gemfile_lock.Gem
326325
a = Gem('a', '1')

tests/packagedcode/test_maven.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ def test_maven_unknown_reference_to_license_in_manifest(self):
250250
run_scan_click(['--package', '--license', '--license-diagnostics', '--processes', '-1', test_dir, '--json', result_file])
251251
check_json_scan(expected_file, result_file, remove_uuid=True, regen=REGEN_TEST_FIXTURES)
252252

253-
254253
def test_package_dependency_not_missing(self):
255254
test_file = self.get_test_loc('maven2/log4j/log4j-pom.xml')
256255
self.check_parse_to_package(test_file, regen=REGEN_TEST_FIXTURES)
@@ -275,7 +274,7 @@ def test_get_top_level_resources(self):
275274
pom_resource = codebase.get_resource(
276275
'activiti-image-generator-7-201802-EA-sources.jar-extract/META-INF/maven/org.activiti/activiti-image-generator/pom.xml'
277276
)
278-
self.assertTrue(pom_resource)
277+
assert pom_resource is True
279278
top_level_resources_paths = [
280279
r.path for r in maven.MavenPomXmlHandler.get_top_level_resources(pom_resource, codebase)
281280
]
@@ -288,7 +287,7 @@ def test_get_top_level_resources(self):
288287
'activiti-image-generator-7-201802-EA-sources.jar-extract/META-INF/maven/org.activiti/activiti-image-generator/pom.properties',
289288
'activiti-image-generator-7-201802-EA-sources.jar-extract/META-INF/maven/org.activiti/activiti-image-generator/pom.xml',
290289
]
291-
self.assertEquals(expected_resource_paths, top_level_resources_paths)
290+
assert top_level_resources_paths == expected_resource_paths
292291

293292

294293
class TestPomProperties(testcase.FileBasedTesting):

tests/packagedcode/test_pypi.py

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,10 @@ def test_parse_metadata_prefer_pkg_info_from_egg_info_from_command_line(self):
282282
# `celery/celery.egg-info/PKG-INFO`
283283
vc = VirtualCodebase(location=result_file)
284284
for dep in vc.attributes.dependencies:
285-
self.assertEqual(dep['datafile_path'], 'celery/celery.egg-info/PKG-INFO')
285+
assert dep['datafile_path'] == 'celery/celery.egg-info/PKG-INFO'
286286
for pkg in vc.attributes.packages:
287287
for path in pkg['datafile_paths']:
288-
self.assertEqual(path, 'celery/celery.egg-info/PKG-INFO')
288+
assert path == 'celery/celery.egg-info/PKG-INFO'
289289

290290

291291
class TestPipRequirementsFileHandler(PackageTester):
@@ -417,47 +417,23 @@ def test_parse_dependency_file_with_invalid_does_not_fail(self):
417417
expected_loc = self.get_test_loc('pypi/requirements_txt/invalid_spec/output.expected.json')
418418
self.check_packages_data(package, expected_loc, regen=REGEN_TEST_FIXTURES)
419419

420-
def test_PipRequirementsFileHandler_is_datafile(self):
421-
self.assertEqual(
422-
pypi.PipRequirementsFileHandler.is_datafile('dev-requirements.txt', _bare_filename=True),
423-
True
424-
)
425-
self.assertEqual(
426-
pypi.PipRequirementsFileHandler.is_datafile('requirements.txt', _bare_filename=True),
427-
True
428-
)
429-
self.assertEqual(
430-
pypi.PipRequirementsFileHandler.is_datafile('requirement.txt', _bare_filename=True),
431-
True
432-
)
433-
self.assertEqual(
434-
pypi.PipRequirementsFileHandler.is_datafile('requirements.in', _bare_filename=True),
435-
True
436-
)
437-
self.assertEqual(
438-
pypi.PipRequirementsFileHandler.is_datafile('requirements.pip', _bare_filename=True),
439-
True
440-
)
441-
self.assertEqual(
442-
pypi.PipRequirementsFileHandler.is_datafile('requirements-dev.txt', _bare_filename=True),
443-
True
444-
)
445-
self.assertEqual(
446-
pypi.PipRequirementsFileHandler.is_datafile('some-requirements-dev.txt', _bare_filename=True),
447-
True
448-
)
449-
self.assertEqual(
450-
pypi.PipRequirementsFileHandler.is_datafile('requires.txt', _bare_filename=True),
451-
True
452-
)
453-
self.assertEqual(
454-
pypi.PipRequirementsFileHandler.is_datafile('requirements/base.txt', _bare_filename=True),
455-
True
456-
)
457-
self.assertEqual(
458-
pypi.PipRequirementsFileHandler.is_datafile('reqs.txt', _bare_filename=True),
459-
True
460-
)
420+
@pytest.mark.parametrize(
421+
'filename',
422+
[
423+
'dev-requirements.txt',
424+
'reqs.txt',
425+
'requirements/base.txt',
426+
'requirements-dev.txt',
427+
'requirements.in',
428+
'requirements.pip',
429+
'requirements.txt',
430+
'requirement.txt',
431+
'requires.txt',
432+
'some-requirements-dev.txt',
433+
]
434+
)
435+
def test_PipRequirementsFileHandler_is_datafile(self, filename):
436+
assert pypi.PipRequirementsFileHandler.is_datafile(filename, _bare_filename=True)
461437

462438

463439
class TestPyPiPipfile(PackageTester):
@@ -607,36 +583,36 @@ def check_setup_py_parsing(test_loc):
607583

608584
expected_loc2 = f'{test_loc}-expected.json'
609585
packages_data = pypi.PythonSetupPyHandler.parse(test_loc)
610-
test_envt.check_packages_data(
586+
env.check_packages_data(
611587
packages_data=packages_data,
612588
expected_loc=expected_loc2,
613589
regen=REGEN_TEST_FIXTURES,
614590
must_exist=False,
615591
)
616592

617593

618-
test_envt = PackageTester()
594+
env = PackageTester()
619595

620596

621597
@pytest.mark.parametrize(
622598
'test_loc',
623-
get_setup_py_test_files(os.path.abspath(os.path.join(test_envt.test_data_dir, 'pypi', 'setup.py-versions'))),
599+
get_setup_py_test_files(os.path.abspath(os.path.join(env.test_data_dir, 'pypi', 'setup.py-versions'))),
624600
)
625601
def test_parse_setup_py_with_computed_versions(test_loc):
626602
check_setup_py_parsing(test_loc)
627603

628604

629605
@pytest.mark.parametrize(
630606
'test_loc',
631-
get_setup_py_test_files(os.path.abspath(os.path.join(test_envt.test_data_dir, 'pypi', 'setup.py')))
607+
get_setup_py_test_files(os.path.abspath(os.path.join(env.test_data_dir, 'pypi', 'setup.py')))
632608
)
633609
def test_parse_setup_py(test_loc):
634610
check_setup_py_parsing(test_loc)
635611

636612

637613
@pytest.mark.parametrize(
638614
'test_loc',
639-
get_setup_py_test_files(os.path.abspath(os.path.join(test_envt.test_data_dir, 'pypi', 'more_setup.py'))),
615+
get_setup_py_test_files(os.path.abspath(os.path.join(env.test_data_dir, 'pypi', 'more_setup.py'))),
640616
)
641617
def test_parse_more_setup_py(test_loc):
642618
check_setup_py_parsing(test_loc)

tests/packagedcode/test_win_reg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ def test_win_reg_remove_drive_letter(self):
6060
test_path = 'C:\\Users\\Test\\Desktop'
6161
expected_path = 'Users/Test/Desktop'
6262
result = remove_drive_letter(test_path)
63-
self.assertEqual(result, expected_path)
63+
assert result == expected_path
6464

6565
def test_win_reg_create_absolute_installed_file_path(self):
6666
root_dir = '/home/test/c/'
6767
test_path = 'C:\\Program Files\\Test Program\\'
6868
result = create_absolute_installed_file_path(root_dir, test_path)
6969
expected_path = '/home/test/c/Program Files/Test Program'
70-
self.assertEqual(result, expected_path)
70+
assert result == expected_path
7171

7272
def test_scan_system_package_end_to_end_installed_win_reg(self):
7373
test_dir = self.get_test_loc('win_reg/get_installed_packages_docker/layer')

tests/textcode/test_strings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ def test_strings_in_all_bin(self):
162162
def test_is_relative_path(self):
163163
# Win Path
164164
path = "c:\\usr\\lib\\librt.so.1."
165-
self.assertFalse(strings.is_relative_path(path))
165+
assert strings.is_relative_path(path) is False
166166

167167
# Relative Posix Path
168168
path = "usr/lib/librt.so.1"
169-
self.assertTrue(strings.is_relative_path(path))
169+
assert strings.is_relative_path(path) is True
170170

171171
def test_strings_with_lf(self):
172172
test_file = 'strings/with-lf/strings.exe'

0 commit comments

Comments
 (0)