Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bitia-cli
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
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
Service Desk
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
bitia
bitia-cli
Commits
c4aa5d5a
Commit
c4aa5d5a
authored
2 years ago
by
dilawar
Browse files
Options
Downloads
Patches
Plain Diff
test: adds test to verify checksum
parent
13d06d53
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
version 0.2.0
Pipeline
#3758
failed with stages
Stage:
Stage:
in 2 minutes and 4 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bitia/checksumdir.py
+1
-4
1 addition, 4 deletions
bitia/checksumdir.py
tests/test_methods.py
+15
-2
15 additions, 2 deletions
tests/test_methods.py
with
16 additions
and
6 deletions
bitia/checksumdir.py
+
1
−
4
View file @
c4aa5d5a
...
...
@@ -59,10 +59,7 @@ def filehash(filepath: Path, hashfunc: str = "sha256"):
"""
Compute checksum of a file
"""
hasher
=
HASH_FUNCS
[
hashfunc
]()
blocksize
=
64
*
1024
if
not
filepath
.
is_file
():
return
hasher
.
hexdigest
()
assert
filepath
.
is_file
(),
f
"
{
filepath
}
is not a file
"
with
filepath
.
open
(
"
rb
"
)
as
fp
:
while
True
:
data
=
fp
.
read
(
blocksize
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_methods.py
+
15
−
2
View file @
c4aa5d5a
...
...
@@ -3,17 +3,30 @@ from pathlib import Path
from
bitia.common
import
sha256sum
_common_hashes
=
{
"
1
"
:
"
6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b
"
,
"
123
"
:
"
a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3
"
,
"
abcdxyz
"
:
"
bc5c610196f15a7e0d21a3af77b0e1740a4415a44d8a7ad4905d877825574bf9
"
,
}
def
test_filehash
():
tempdir
=
tempfile
.
gettempdir
()
t1
=
"
ls -ltrh /
"
t2
=
"
ls -ltrh
"
f1
=
Path
(
tempdir
)
/
"
a.txt
"
f2
=
Path
(
tempdir
)
/
"
b.txt
"
for
_c
,
_h
in
_common_hashes
.
items
():
f1
.
write_text
(
_c
)
assert
f1
.
read_text
()
==
_c
print
(
f
"
Computing hash of
{
f1
}
, content:
{
_c
}
"
)
assert
sha256sum
(
f1
)
==
_h
t1
=
"
ls -ltrh /
"
f1
.
write_text
(
t1
)
f2
.
write_text
(
t1
)
assert
sha256sum
(
f1
)
==
sha256sum
(
f2
)
t2
=
"
ls -ltrh
"
f2
.
write_text
(
t2
)
assert
sha256sum
(
f1
)
!=
sha256sum
(
f2
)
...
...
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