Skip to content

Commit a31199f

Browse files
authored
Merge pull request #49 from nexB/48-correctly-assign-codebase-attributes
Do not assign None to codebase attributes #48
2 parents 9131627 + 3ea8548 commit a31199f

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55
[tool.setuptools_scm]
66
# this is used populated when creating a git archive
77
# and when there is .git dir and/or there is no git installed
8-
fallback_version = "9999.$Format:%h-%cs$"
8+
fallback_version = "9999.dev99"
99

1010
[tool.pytest.ini_options]
1111
norecursedirs = [

src/commoncode/resource.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,8 @@ def _populate(self, scan_data):
18401840
##########################################################
18411841
for attr_name in self.codebase_attributes:
18421842
value = scan_data.get(attr_name)
1843+
if value == None:
1844+
continue
18431845
setattr(self.attributes, attr_name, value)
18441846

18451847
##########################################################

tests/test_resource.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from os.path import exists
1313
from os.path import join
1414

15+
import attr
16+
1517
from commoncode.fileutils import parent_directory
1618
from commoncode.resource import Codebase
1719
from commoncode.resource import Resource
@@ -661,6 +663,17 @@ def test_VirtualCodebase_with_paths_works(self):
661663
)
662664
check_against_expected_json_file(results, expected_file, regen=False)
663665

666+
def test_VirtualCodebase_codebase_attributes_assignment(self):
667+
test_codebase = self.get_test_loc('resource/with_path/virtual-codebase.json')
668+
vc = VirtualCodebase(
669+
location=test_codebase,
670+
codebase_attributes=dict(
671+
packages=attr.ib(default=attr.Factory(list))
672+
),
673+
)
674+
self.assertNotEqual(vc.attributes.packages, None)
675+
self.assertEqual(vc.attributes.packages, [])
676+
664677

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

0 commit comments

Comments
 (0)