Skip to content

Commit

Permalink
feat: port util methods from oscar
Browse files Browse the repository at this point in the history
  • Loading branch information
hrz6976 committed Jun 6, 2024
1 parent 66da10c commit bc85dac
Show file tree
Hide file tree
Showing 8 changed files with 439 additions and 53 deletions.
Binary file modified tests/fixtures/commit_0.tch
Binary file not shown.
Binary file added tests/fixtures/commit_1.tch
Binary file not shown.
23 changes: 21 additions & 2 deletions tests/fixtures/create_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ def copy_content(self, obj: str, key: Union[bytes, str]):
if obj == 'tree':
_map_obj = self.config2['objects']['tree.tch']
print('writing to tch', key, _map_obj["sharding_bits"])
write_to_tch(bytes.fromhex(key), value, _map_obj['shards'], _map_obj['sharding_bits'], use_fnv_keys=True)
write_to_tch(bytes.fromhex(key), value, _map_obj['shards'], _map_obj['sharding_bits'], use_fnv_keys=False)

elif obj == 'commit':
_map_obj = self.config2['objects']['commit.tch']
print('writing to tch', key ,_map_obj["sharding_bits"])
write_to_tch(bytes.fromhex(key), value, _map_obj['shards'], _map_obj['sharding_bits'], use_fnv_keys=True)
write_to_tch(bytes.fromhex(key), value, _map_obj['shards'], _map_obj['sharding_bits'], use_fnv_keys=False)

elif obj == 'blob':
# read blob
Expand Down Expand Up @@ -174,3 +174,22 @@ def copy_content(self, obj: str, key: Union[bytes, str]):
cp.copy_content('commit', 'e4af89166a17785c1d741b8b1d5775f3223f510f')
cp.copy_content('blob', '05fe634ca4c8386349ac519f899145c75fff4169')
cp.copy_content('blob', '46aaf071f1b859c5bf452733c2583c70d92cd0c8')
# woc-hack_thebridge
cp.copy_values('p2c', 'woc-hack_thebridge')
cp.copy_content('commit', '0d8228bb25ce89c7e731c7410bc8c5a4e2636e52')
cp.copy_content('commit', '34a8662a4f31dacb923e39ae6792f6fc4476a939')
cp.copy_content('commit', '898d5a21241aaf16acf92566aa34103d06cf2ac6')
cp.copy_content('commit', '91f4da4c173e41ffbf0d9ecbe2f07f3a3296933c')
cp.copy_content('commit', 'ae6e15fa4d8d4d454977ddbb4e97e922ddecebf7')
cp.copy_content('commit', 'f249b14a111279faa8d65c29ecf46bb6ce59a139')
cp.copy_content('tree', '')
cp.copy_content('tree', '3ccf6f8320740a1afec68b38b3b9ba46cedef368')
cp.copy_content('tree' ,'e5798457aebae7c84eff7b80b50c3a938cc4cb63')
cp.copy_content('tree', '836f04d5b374033b1608269e2f3aaabae263a0db')
cp.copy_content('tree', 'f54cb5527226aa2096307c08e15c62248b98f763')
cp.copy_content('tree', 'da65e1401d11a955686b8a49e46b9a457f3febab')
cp.copy_content('tree', 'a28f1558be9867d35cc1fa17477565c08786cf83')
cp.copy_content('tree', '4db2ad30097924cbe5da9c0f2c49350fdc19c3a4')
cp.copy_content('tree', '1cf86145b4a9492ebbe0fa640638504946315ca6')
cp.copy_content('tree', '29a422c19251aeaeb907175e9b3219a9bed6c616')
cp.copy_content('tree', '51968a7a4e67fd2696ffd5ccc041560a4d804f5d')
Binary file modified tests/fixtures/p2cFullR.1.tch
Binary file not shown.
Binary file added tests/fixtures/tree_0.tch
Binary file not shown.
Binary file modified tests/fixtures/tree_1.tch
Binary file not shown.
71 changes: 66 additions & 5 deletions tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
def woc():
_test_pr = os.path.join(os.path.dirname(__file__), 'test_profile.json')
woc = WocMapsLocal(_test_pr)
init_woc(woc)
init_woc_objects(woc)
yield woc

# Test cases
def test_equal(woc):
assert Author('1') == Author('1')
assert Blob('05fe634ca4c8386349ac519f899145c75fff4169') == Blob('05fe634ca4c8386349ac519f899145c75fff4169')
assert Author('1') != Project('2')

def test_author_commits(woc):
author = Author('Audris Mockus <[email protected]>')
commits = author.commits
Expand Down Expand Up @@ -180,11 +184,10 @@ def test_tree_blobs(woc):
assert Blob('05fe634ca4c8386349ac519f899145c75fff4169') in blobs

def test_tree_traverse(woc):
tree = Tree('f1b66dcca490b5c4455af319bc961a34f69c72c2')
tree = Tree('706aa4dedb560358bff21c3120a0b09532d3484d')
traverse = list(tree.traverse())
assert all(isinstance(t[0], File) for t in traverse)
assert all(isinstance(t[1], Blob) for t in traverse)
assert traverse[0][0].key == 'README.md'

def test_project_authors(woc):
project = Project('ArtiiQ_PocketMine-MP')
Expand All @@ -196,4 +199,62 @@ def test_project_commits(woc):
project = Project('ArtiiQ_PocketMine-MP')
commits = project.commits
assert all(isinstance(c, Commit) for c in commits)
assert commits[0].key == '0000000bab11354f9a759332065be5f066c3398f'
assert commits[0].key == '0000000bab11354f9a759332065be5f066c3398f'

def test_project_url(woc):
project = Project('ArtiiQ_PocketMine-MP')
assert project.url == 'https://github.com/ArtiiQ/PocketMine-MP'
project = Project('sourceforge.net_peazip') # <- How does sourceforge repos looks like in woc?
assert project.url == 'https://git.code.sf.net/p/peazip'
project = Project("gitlab.com_openRGB_openRGB")
assert project.url == 'https://gitlab.com/openRGB/openRGB'

def test_project_head(woc):
project = Project('woc-hack_thebridge')
head = project.head
assert isinstance(head, Commit)
assert head.key == 'f249b14a111279faa8d65c29ecf46bb6ce59a139'

def test_project_tail(woc):
project = Project('woc-hack_thebridge')
tail = project.tail
assert isinstance(tail, Commit)
assert tail.key == 'ae6e15fa4d8d4d454977ddbb4e97e922ddecebf7'

def test_project_earliest(woc):
project = Project('woc-hack_thebridge')
earliest = project.earliest_commit
assert isinstance(earliest, Commit)
assert earliest.key == 'ae6e15fa4d8d4d454977ddbb4e97e922ddecebf7'

def test_project_latest(woc):
project = Project('woc-hack_thebridge')
latest = project.latest_commit
assert isinstance(latest, Commit)
assert latest.key == 'f249b14a111279faa8d65c29ecf46bb6ce59a139'

def test_project_walk(woc):
project = Project('woc-hack_thebridge')
commits = list(project.commits_fp())
assert all(isinstance(c, Commit) for c in commits)
assert len(commits) == 6

def test_commit_compare(woc):
c1 = Commit('91f4da4c173e41ffbf0d9ecbe2f07f3a3296933c')
c2 = Commit('ae6e15fa4d8d4d454977ddbb4e97e922ddecebf7')

# We can't test fuzz matching because blob storage is broken :(
diff = list(c1.compare(c2, threshold=1))
modified_files = set(f[0].key for f in diff if f[0] is not None) | \
set(f[1].key for f in diff if f[1] is not None)
assert all(len(d) == 4 for d in diff)
assert all(isinstance(d[0], File) for d in diff if d[0] is not None)
assert all(isinstance(d[1], File) for d in diff if d[1] is not None)
assert all(isinstance(d[2], Blob) for d in diff if d[2] is not None)
assert all(isinstance(d[3], Blob) for d in diff if d[3] is not None)
assert modified_files == {
'README.md', 'woc_service/requirements.txt', 'woc_service/app.py',
'woc_service/static/.keep', 'woc_service/oscar.py'
}


Loading

0 comments on commit bc85dac

Please sign in to comment.