Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-model
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nicolas Dandrimont
swh-model
Commits
a91bf69b
Verified
Commit
a91bf69b
authored
8 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
Add tests about new use cases
Combination of: - validation on files - ignore empty folder
parent
22b9fca9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
swh/model/tests/test_git.py
+97
-6
97 additions, 6 deletions
swh/model/tests/test_git.py
with
97 additions
and
6 deletions
swh/model/tests/test_git.py
+
97
−
6
View file @
a91bf69b
...
...
@@ -149,17 +149,17 @@ class GitHashWalkArborescenceTree(unittest.TestCase):
self
.
maxDiff
=
None
start_path
=
os
.
path
.
dirname
(
__file__
).
encode
(
'
utf-8
'
)
pkg_doc_linux_r11
=
os
.
path
.
join
(
start_path
,
b
'
../../../..
'
,
b
'
swh-storage-testdata
'
,
b
'
dir-folders
'
,
b
'
sample-folder.tgz
'
)
sample_folder
=
os
.
path
.
join
(
start_path
,
b
'
../../../..
'
,
b
'
swh-storage-testdata
'
,
b
'
dir-folders
'
,
b
'
sample-folder.tgz
'
)
self
.
root_path
=
os
.
path
.
join
(
self
.
tmp_root_path
,
b
'
sample-folder
'
)
# uncompress the sample folder
subprocess
.
check_output
(
[
'
tar
'
,
'
xvf
'
,
pkg_doc_linux_r11
,
'
-C
'
,
self
.
tmp_root_path
])
[
'
tar
'
,
'
xvf
'
,
sample_folder
,
'
-C
'
,
self
.
tmp_root_path
])
def
tearDown
(
self
):
if
os
.
path
.
exists
(
self
.
tmp_root_path
):
...
...
@@ -276,6 +276,97 @@ class GitHashUpdate(GitHashWalkArborescenceTree):
self
.
assertEquals
(
expected_dict
,
actual_dict
)
@istest
def
update_checksums_from_add_new_file_with_validation
(
self
):
# make a temporary arborescence tree to hash without ignoring anything
# update the disk in some way (add a new file)
# update the actual git checksums from the deeper tree modified
# + Add some validation on some file to ignore
def
dir_ok_fn
(
dirpath
):
return
b
'
empty-folder
'
not
in
dirpath
# when
objects
=
git
.
walk_and_compute_sha1_from_directory
(
self
.
tmp_root_path
,
dir_ok_fn
=
dir_ok_fn
)
# update the existing file
changed_path
=
os
.
path
.
join
(
self
.
tmp_root_path
,
b
'
sample-folder/bar/barfoo/new
'
)
with
open
(
changed_path
,
'
wb
'
)
as
f
:
f
.
write
(
b
'
new line
'
)
# walk1 (this will be our expectation)
expected_dict
=
git
.
walk_and_compute_sha1_from_directory
(
self
.
tmp_root_path
,
dir_ok_fn
=
dir_ok_fn
)
# then
actual_dict
=
git
.
update_checksums_from
(
[{
'
path
'
:
changed_path
,
'
action
'
:
'
A
'
}],
objects
)
self
.
assertEquals
(
expected_dict
,
actual_dict
)
@istest
def
update_checksums_from_add_new_file_remove_empty_folder
(
self
):
# make a temporary arborescence tree to hash without ignoring anything
# update the disk in some way (add a new file)
# update the actual git checksums from the deeper tree modified
# + Add some validation on some file to ignore
# when
objects
=
git
.
walk_and_compute_sha1_from_directory
(
self
.
tmp_root_path
,
remove_empty_folder
=
True
)
# update the existing file
changed_path
=
os
.
path
.
join
(
self
.
tmp_root_path
,
b
'
sample-folder/bar/barfoo/new
'
)
with
open
(
changed_path
,
'
wb
'
)
as
f
:
f
.
write
(
b
'
new line
'
)
# walk1 (this will be our expectation)
expected_dict
=
git
.
walk_and_compute_sha1_from_directory
(
self
.
tmp_root_path
,
remove_empty_folder
=
True
)
# then
actual_dict
=
git
.
update_checksums_from
(
[{
'
path
'
:
changed_path
,
'
action
'
:
'
A
'
}],
objects
)
self
.
assertEquals
(
expected_dict
,
actual_dict
)
@istest
def
update_checksums_new_file_with_validation_and_ignore_empty_dir
(
self
):
# make a temporary arborescence tree to hash without ignoring anything
# update the disk in some way (add a new file)
# update the actual git checksums from the deeper tree modified
# + Add some validation on some file to ignore
# + ignore empty folder
def
dir_ok_fn
(
dirpath
):
return
b
'
some-binary
'
not
in
dirpath
# when
objects
=
git
.
walk_and_compute_sha1_from_directory
(
self
.
tmp_root_path
,
dir_ok_fn
=
dir_ok_fn
,
remove_empty_folder
=
True
)
# update the existing file
changed_path
=
os
.
path
.
join
(
self
.
tmp_root_path
,
b
'
sample-folder/bar/barfoo/new
'
)
with
open
(
changed_path
,
'
wb
'
)
as
f
:
f
.
write
(
b
'
new line
'
)
# walk1 (this will be our expectation)
expected_dict
=
git
.
walk_and_compute_sha1_from_directory
(
self
.
tmp_root_path
,
dir_ok_fn
=
dir_ok_fn
,
remove_empty_folder
=
True
)
# then
actual_dict
=
git
.
update_checksums_from
(
[{
'
path
'
:
changed_path
,
'
action
'
:
'
A
'
}],
objects
)
self
.
assertEquals
(
expected_dict
,
actual_dict
)
@istest
def
update_checksums_from_modify_existing_file
(
self
):
# make a temporary arborescence tree to hash without ignoring anything
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment