Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_is_super_path(self):
# # True
path1 = ('authors', 1, 'name')
path2 = ('authors', 1, 'name')
self.assertTrue(is_super_path(path1, path2))
path1 = ('authors', 1)
path2 = ('authors', 1, 'name')
self.assertTrue(is_super_path(path1, path2))
path1 = ('authors',)
path2 = ('authors', 1, 'name')
self.assertTrue(is_super_path(path1, path2))
# # False
path1 = ('authors', 1, 'name')
path2 = ('authors', 1, 'surname')
self.assertFalse(is_super_path(path1, path2))
path1 = ('authors', 2)
path2 = ('authors', 1, 'surname')
self.assertFalse(is_super_path(path1, path2))
path1 = ('author',)
path2 = ('authors', 1, 'surname')
path1 = ('authors', 1)
path2 = ('authors', 1, 'name')
self.assertTrue(is_super_path(path1, path2))
path1 = ('authors',)
path2 = ('authors', 1, 'name')
self.assertTrue(is_super_path(path1, path2))
# # False
path1 = ('authors', 1, 'name')
path2 = ('authors', 1, 'surname')
self.assertFalse(is_super_path(path1, path2))
path1 = ('authors', 2)
path2 = ('authors', 1, 'surname')
self.assertFalse(is_super_path(path1, path2))
path1 = ('author',)
path2 = ('authors', 1, 'surname')
self.assertFalse(is_super_path(path1, path2))
The conditions are:
1. The paths are identical
2. On of the paths is the super path of the other
:param patch1: First patch tuple
:param patch2: First patch tuple
"""
path1 = get_path(patch1)
path2 = get_path(patch2)
if path1 == path2:
return True
elif is_super_path(path1, path2) and patch1[0] == 'remove':
return True
elif is_super_path(path2, path1) and patch2[0] == 'remove':
return True
return False
def _is_conflict(self, patch1, patch2):
"""Decide on a conflict between two patches.
The conditions are:
1. The paths are identical
2. On of the paths is the super path of the other
:param patch1: First patch tuple
:param patch2: First patch tuple
"""
path1 = get_path(patch1)
path2 = get_path(patch2)
if path1 == path2:
return True
elif is_super_path(path1, path2) and patch1[0] == 'remove':
return True
elif is_super_path(path2, path1) and patch2[0] == 'remove':
return True
return False