Skip to content

Commit

Permalink
Merge 8d7a879 into 204c1d3
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhub committed Dec 1, 2019
2 parents 204c1d3 + 8d7a879 commit 16d8dfe
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
3 changes: 2 additions & 1 deletion docs/reference/item.md
Expand Up @@ -390,4 +390,5 @@ reviewed attributes to the document configuration does not change the
fingerprint of existing items of the document, if they do not have them,
otherwise the fingerprint changes. Removing a reviewed attribute from the
document configuration changes the fingerprint of all items of the document
with such an attribute.
with such an attribute. The type of the values, empty strings, lists, and
dictionaries affect the fingerprint.
10 changes: 7 additions & 3 deletions doorstop/core/item.py
Expand Up @@ -57,22 +57,25 @@ def _convert_to_str(value, result):
This function is independent of the YAML format and may be used for data
which should be independent of the actual item storage format. It depends
only on the Python sorting function and string representation.
only on the Python sorting function, type information, and string
representation.
:param value: the value to convert
:param result: the current result of the string serialization
:return: the updated result of the string serialization
"""
if isinstance(value, list):
result += "\\L"
for v in value:
result = _convert_to_str(v, result)
return result
if isinstance(value, dict):
result += "\\D"
for k in sorted(value.keys()):
result = _convert_to_str(value[k], result)
return result
return result + str(value)
return result + "\\T" + str(type(value)) + "\\V" + str(value).replace("\\", "\\\\")


def requires_tree(func):
Expand Down Expand Up @@ -761,7 +764,8 @@ def stamp(self, links=False):
if links:
values.extend(self.links)
for key in self.document.extended_reviewed:
values.append(_convert_to_str(self._data.get(key, ""), ""))
if key in self._data:
values.append(_convert_to_str(self._data[key], ""))
return Stamp(*values)

@auto_save
Expand Down
64 changes: 57 additions & 7 deletions doorstop/core/tests/test_item.py
Expand Up @@ -799,33 +799,83 @@ def test_stamp_with_one_extended_reviewed(self):
"""Verify fingerprint with one extended reviewed attribute."""
self.item._data['type'] = 'functional'
self.item.document.extended_reviewed = ['type']
stamp = 'HViLqscmSeVfv2jYBFhXdceTcEWWc0r9uchEmX7xSTY='
stamp = 'MmcvtzB20PHv0IBhxpNtpZCa0CfYwHnPr3Jk8W-TRxk='
self.assertEqual(stamp, self.item.stamp())
self.item.document.extended_reviewed = []
stamp = 'OoHOpBnrt8us7ph8DVnz5KrQs6UBqj_8MEACA0gWpjY='
self.assertEqual(stamp, self.item.stamp())

def test_stamp_with_complex_extended_reviewed(self):
"""Verify fingerprint with complex extended reviewed attribute."""
self.item.document.extended_reviewed = ['attr']
self.item._data['attr'] = ['a', 'b', ['c', {'d': 'e', 'f': ['g']}]]
stamp = 'JcCRKBgLLTOatY8OpAMabblP7Mu24JZRn3WgoXwjmSk='
self.assertEqual(stamp, self.item.stamp())

def test_stamp_with_none_extended_reviewed(self):
"""Verify fingerprint with None extended reviewed attribute."""
self.item.document.extended_reviewed = ['attr']
self.item._data['attr'] = None
stamp = 'e0qDli7ZJwhf161b_v7AdGNNl7xHx-bs28aFFk7aqT4='
self.assertEqual(stamp, self.item.stamp())

def test_stamp_with_value_one_extended_reviewed(self):
"""Verify fingerprint with value one extended reviewed attribute."""
self.item.document.extended_reviewed = ['attr']
self.item._data['attr'] = 1
stamp = '0s4QQh2AZXSoZNYGcfybCGLHAgO4EWY9gxK_LVNiqOA='
self.assertEqual(stamp, self.item.stamp())
self.item._data['attr'] = '1'
stamp = 'GWlkpsRSzT_lgE4CNvE4wrUZZwM3iHKHOa6idcHUSUw='
self.assertEqual(stamp, self.item.stamp())

def test_stamp_with_empty_string_extended_reviewed(self):
"""Verify fingerprint with empty string extended reviewed attribute."""
self.item.document.extended_reviewed = ['attr']
self.item._data['attr'] = ''
stamp = 'H70VgWPTH89Q9KfIJBfeilC7-wYAtWigxZ2iUcZ9j-8='
self.assertEqual(stamp, self.item.stamp())

def test_stamp_with_list_extended_reviewed(self):
"""Verify fingerprint with list extended reviewed attributes."""
self.item.document.extended_reviewed = ['attr']
self.item._data['attr'] = []
stamp = 'qwUP7VgUbHWIdj-T2ZfGhROfJQwSHDhsC6WR9vUTk1U='
self.assertEqual(stamp, self.item.stamp())
self.item._data['attr'] = [None]
stamp = 'GHDRiY4C3twnXDTCqoCAD_iymfe892ZzQuYjuccFBT0='
self.assertEqual(stamp, self.item.stamp())
self.item._data['attr'] = ['']
stamp = 'Rfwtl2j56CdQLtE4b5StEa0ECVTqlOpABLdhEa1avyo='
self.assertEqual(stamp, self.item.stamp())
self.item._data['attr'] = [[]]
stamp = 'AXWIEp9CYI4UWzIw4NinvDrUFzQl_8rCL9B_PmGisYk='
self.assertEqual(stamp, self.item.stamp())
self.item._data['attr'] = [{}]
stamp = 'C5Bm5ej09zaJxbtbE9PIcno8M9lIBIC6sJOmNJkrJH8='
self.assertEqual(stamp, self.item.stamp())

def test_stamp_with_empty_dict_extended_reviewed(self):
"""Verify fingerprint with empty dict extended reviewed attribute."""
self.item.document.extended_reviewed = ['attr']
stamp = 'H1frEDRLk8y7eaNQPpGbgpKlWLqXc3_QfiCq1qvrUtA='
self.item._data['attr'] = {}
stamp = '5Yv0vWG2h5rAQt_1LujZuD9X6udWO52KVaSA5SJ3Emc='
self.assertEqual(stamp, self.item.stamp())

def test_stamp_with_two_extended_reviewed(self):
"""Verify fingerprint with two extended reviewed attributes."""
self.item._data['type'] = 'functional'
self.item._data['verification-method'] = 'test'
self.item.document.extended_reviewed = ['type', 'verification-method']
stamp = 'S_yJkuwMTVG70Pcr3R6zdSR1VdviwxVWgG7q5b5NpjU='
stamp = 'TF_q0ofVwjaJI1RYu9jtDeSCm5gAQWIqsxpPxAW5D64='
self.assertEqual(stamp, self.item.stamp())

def test_stamp_with_reversed_extended_reviewed(self):
"""Verify fingerprint with reversed extended reviewed attributes."""
self.item._data['type'] = 'functional'
self.item._data['verification-method'] = 'test'
self.item.document.extended_reviewed = ['verification-method', 'type']
stamp = 'OhVM3nMW4mensMfWA-VIcbn5XYbxpPI_ZEDVcCjoGo0='
stamp = 'dMWAazlLoeZSwlD87nEwQtAFq32WQuX_Bd_8kehaKJg='
self.assertEqual(stamp, self.item.stamp())

def test_stamp_with_missing_extended_reviewed_reverse(self):
Expand All @@ -837,22 +887,22 @@ def test_stamp_with_missing_extended_reviewed_reverse(self):
'type',
'verification-method',
]
stamp = 'S_yJkuwMTVG70Pcr3R6zdSR1VdviwxVWgG7q5b5NpjU='
stamp = 'TF_q0ofVwjaJI1RYu9jtDeSCm5gAQWIqsxpPxAW5D64='
self.assertEqual(stamp, self.item.stamp())
self.item.document.extended_reviewed = [
'missing',
'type',
'verification-method',
'missing-2',
]
stamp = 'S_yJkuwMTVG70Pcr3R6zdSR1VdviwxVWgG7q5b5NpjU='
stamp = 'TF_q0ofVwjaJI1RYu9jtDeSCm5gAQWIqsxpPxAW5D64='
self.assertEqual(stamp, self.item.stamp())
self.item.document.extended_reviewed = [
'type',
'verification-method',
'missing-2',
]
stamp = 'S_yJkuwMTVG70Pcr3R6zdSR1VdviwxVWgG7q5b5NpjU='
stamp = 'TF_q0ofVwjaJI1RYu9jtDeSCm5gAQWIqsxpPxAW5D64='
self.assertEqual(stamp, self.item.stamp())

def test_stamp_links(self):
Expand Down

0 comments on commit 16d8dfe

Please sign in to comment.