Merge pull request #2600 from fonttools/fix-deepcopyExceptFonts

[dsLib] Fix typo to actually transfer font references during deepcopy
This commit is contained in:
Cosimo Lupo 2022-04-26 10:43:07 +01:00 committed by GitHub
commit 2e0dd62836
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -2940,7 +2940,7 @@ class DesignSpaceDocument(LogMixin, AsDictMixin):
source.font = None source.font = None
res = copy.deepcopy(self) res = copy.deepcopy(self)
for source, font in zip(res.sources, fonts): for source, font in zip(res.sources, fonts):
res.font = font source.font = font
return res return res
finally: finally:
for source, font in zip(self.sources, fonts): for source, font in zip(self.sources, fonts):

View File

@ -1043,3 +1043,15 @@ def test_addRuleDescriptor(tmp_path):
# Test it doesn't crash. # Test it doesn't crash.
ds.write(tmp_path / "test.designspace") ds.write(tmp_path / "test.designspace")
def test_deepcopyExceptFonts():
ds = DesignSpaceDocument()
ds.addSourceDescriptor(font=object())
ds.addSourceDescriptor(font=object())
ds_copy = ds.deepcopyExceptFonts()
assert ds.tostring() == ds_copy.tostring()
assert ds.sources[0].font is ds_copy.sources[0].font
assert ds.sources[1].font is ds_copy.sources[1].font