Skip to content

Commit

Permalink
Merge pull request #49 from nexB/48-correctly-assign-codebase-attributes
Browse files Browse the repository at this point in the history
Do not assign None to codebase attributes #48
JonoYang authored Feb 23, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 9131627 + 3ea8548 commit a31199f
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
# this is used populated when creating a git archive
# and when there is .git dir and/or there is no git installed
fallback_version = "9999.$Format:%h-%cs$"
fallback_version = "9999.dev99"

[tool.pytest.ini_options]
norecursedirs = [
2 changes: 2 additions & 0 deletions src/commoncode/resource.py
Original file line number Diff line number Diff line change
@@ -1840,6 +1840,8 @@ def _populate(self, scan_data):
##########################################################
for attr_name in self.codebase_attributes:
value = scan_data.get(attr_name)
if value == None:
continue
setattr(self.attributes, attr_name, value)

##########################################################
13 changes: 13 additions & 0 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@
from os.path import exists
from os.path import join

import attr

from commoncode.fileutils import parent_directory
from commoncode.resource import Codebase
from commoncode.resource import Resource
@@ -661,6 +663,17 @@ def test_VirtualCodebase_with_paths_works(self):
)
check_against_expected_json_file(results, expected_file, regen=False)

def test_VirtualCodebase_codebase_attributes_assignment(self):
test_codebase = self.get_test_loc('resource/with_path/virtual-codebase.json')
vc = VirtualCodebase(
location=test_codebase,
codebase_attributes=dict(
packages=attr.ib(default=attr.Factory(list))
),
)
self.assertNotEqual(vc.attributes.packages, None)
self.assertEqual(vc.attributes.packages, [])


class TestCodebaseCache(FileBasedTesting):
test_data_dir = join(dirname(__file__), 'data')

0 comments on commit a31199f

Please sign in to comment.