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
34228c51
Commit
34228c51
authored
7 years ago
by
Nicolas Dandrimont
Browse files
Options
Downloads
Patches
Plain Diff
test_from_disk: use os.fsencode to consistently get tmpfile names as bytes
parent
2ab83604
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_from_disk.py
+27
-25
27 additions, 25 deletions
swh/model/tests/test_from_disk.py
with
27 additions
and
25 deletions
swh/model/tests/test_from_disk.py
+
27
−
25
View file @
34228c51
...
...
@@ -50,8 +50,10 @@ class DataMixin:
def
setUp
(
self
):
self
.
tmpdir
=
tempfile
.
TemporaryDirectory
(
prefix
=
b
'
swh.model.from_disk
'
prefix
=
'
swh.model.from_disk
'
)
self
.
tmpdir_name
=
os
.
fsencode
(
self
.
tmpdir
.
name
)
self
.
contents
=
{
b
'
file
'
:
{
'
data
'
:
b
'
42
\n
'
,
...
...
@@ -464,11 +466,11 @@ class DataMixin:
fn
(
path
)
def
make_from_tarball
(
self
,
directory
):
tarball
=
os
.
path
.
join
(
os
.
fsencode
(
os
.
path
.
dirname
(
__file__
)
)
,
b
'
../../../..
'
,
b
'
swh-storage-testdata
'
,
b
'
dir-folders
'
,
b
'
sample-folder.tgz
'
)
tarball
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
../../../..
'
,
'
swh-storage-testdata
'
,
'
dir-folders
'
,
'
sample-folder.tgz
'
)
with
tarfile
.
open
(
tarball
,
'
r:gz
'
)
as
f
:
f
.
extractall
(
os
.
fsdecode
(
directory
))
...
...
@@ -489,11 +491,11 @@ class TestContent(DataMixin, unittest.TestCase):
class
SymlinkToContent
(
DataMixin
,
unittest
.
TestCase
):
def
setUp
(
self
):
super
().
setUp
()
self
.
make_symlinks
(
self
.
tmpdir
.
name
)
self
.
make_symlinks
(
self
.
tmpdir
_
name
)
def
test_symlink_to_content
(
self
):
for
filename
,
symlink
in
self
.
symlinks
.
items
():
path
=
os
.
path
.
join
(
self
.
tmpdir
.
name
,
filename
)
path
=
os
.
path
.
join
(
self
.
tmpdir
_
name
,
filename
)
perms
=
0o120000
conv_content
=
Content
.
from_symlink
(
path
=
path
,
mode
=
perms
)
self
.
assertContentEqual
(
conv_content
,
symlink
)
...
...
@@ -502,32 +504,32 @@ class SymlinkToContent(DataMixin, unittest.TestCase):
class
FileToContent
(
DataMixin
,
unittest
.
TestCase
):
def
setUp
(
self
):
super
().
setUp
()
self
.
make_contents
(
self
.
tmpdir
.
name
)
self
.
make_symlinks
(
self
.
tmpdir
.
name
)
self
.
make_specials
(
self
.
tmpdir
.
name
)
self
.
make_contents
(
self
.
tmpdir
_
name
)
self
.
make_symlinks
(
self
.
tmpdir
_
name
)
self
.
make_specials
(
self
.
tmpdir
_
name
)
def
test_file_to_content
(
self
):
# Check whether loading the data works
for
data
in
[
True
,
False
]:
for
filename
,
symlink
in
self
.
symlinks
.
items
():
path
=
os
.
path
.
join
(
self
.
tmpdir
.
name
,
filename
)
path
=
os
.
path
.
join
(
self
.
tmpdir
_
name
,
filename
)
conv_content
=
Content
.
from_file
(
path
=
path
,
data
=
data
)
self
.
assertContentEqual
(
conv_content
,
symlink
,
check_data
=
data
)
for
filename
,
content
in
self
.
contents
.
items
():
path
=
os
.
path
.
join
(
self
.
tmpdir
.
name
,
filename
)
path
=
os
.
path
.
join
(
self
.
tmpdir
_
name
,
filename
)
conv_content
=
Content
.
from_file
(
path
=
path
,
data
=
data
)
self
.
assertContentEqual
(
conv_content
,
content
,
check_data
=
data
)
for
filename
in
self
.
specials
:
path
=
os
.
path
.
join
(
self
.
tmpdir
.
name
,
filename
)
path
=
os
.
path
.
join
(
self
.
tmpdir
_
name
,
filename
)
conv_content
=
Content
.
from_file
(
path
=
path
,
data
=
data
)
self
.
assertContentEqual
(
conv_content
,
self
.
empty_content
)
def
test_file_to_content_with_path
(
self
):
for
filename
,
content
in
self
.
contents
.
items
():
content_w_path
=
content
.
copy
()
path
=
os
.
path
.
join
(
self
.
tmpdir
.
name
,
filename
)
path
=
os
.
path
.
join
(
self
.
tmpdir
_
name
,
filename
)
content_w_path
[
'
path
'
]
=
path
conv_content
=
Content
.
from_file
(
path
=
path
,
save_path
=
True
)
self
.
assertContentEqual
(
conv_content
,
content_w_path
,
...
...
@@ -537,20 +539,20 @@ class FileToContent(DataMixin, unittest.TestCase):
class
DirectoryToObjects
(
DataMixin
,
unittest
.
TestCase
):
def
setUp
(
self
):
super
().
setUp
()
contents
=
os
.
path
.
join
(
self
.
tmpdir
.
name
,
b
'
contents
'
)
contents
=
os
.
path
.
join
(
self
.
tmpdir
_
name
,
b
'
contents
'
)
os
.
mkdir
(
contents
)
self
.
make_contents
(
contents
)
symlinks
=
os
.
path
.
join
(
self
.
tmpdir
.
name
,
b
'
symlinks
'
)
symlinks
=
os
.
path
.
join
(
self
.
tmpdir
_
name
,
b
'
symlinks
'
)
os
.
mkdir
(
symlinks
)
self
.
make_symlinks
(
symlinks
)
specials
=
os
.
path
.
join
(
self
.
tmpdir
.
name
,
b
'
specials
'
)
specials
=
os
.
path
.
join
(
self
.
tmpdir
_
name
,
b
'
specials
'
)
os
.
mkdir
(
specials
)
self
.
make_specials
(
specials
)
empties
=
os
.
path
.
join
(
self
.
tmpdir
.
name
,
b
'
empty1
'
,
b
'
empty2
'
)
empties
=
os
.
path
.
join
(
self
.
tmpdir
_
name
,
b
'
empty1
'
,
b
'
empty2
'
)
os
.
makedirs
(
empties
)
def
test_directory_to_objects
(
self
):
directory
=
Directory
.
from_disk
(
path
=
self
.
tmpdir
.
name
)
directory
=
Directory
.
from_disk
(
path
=
self
.
tmpdir
_
name
)
for
name
,
value
in
self
.
contents
.
items
():
self
.
assertContentEqual
(
directory
[
b
'
contents/
'
+
name
],
value
)
...
...
@@ -589,7 +591,7 @@ class DirectoryToObjects(DataMixin, unittest.TestCase):
def
test_directory_to_objects_ignore_empty
(
self
):
directory
=
Directory
.
from_disk
(
path
=
self
.
tmpdir
.
name
,
path
=
self
.
tmpdir
_
name
,
dir_filter
=
from_disk
.
ignore_empty_directories
)
...
...
@@ -623,7 +625,7 @@ class DirectoryToObjects(DataMixin, unittest.TestCase):
def
test_directory_to_objects_ignore_name
(
self
):
directory
=
Directory
.
from_disk
(
path
=
self
.
tmpdir
.
name
,
path
=
self
.
tmpdir
_
name
,
dir_filter
=
from_disk
.
ignore_named_directories
([
b
'
symlinks
'
])
)
for
name
,
value
in
self
.
contents
.
items
():
...
...
@@ -654,7 +656,7 @@ class DirectoryToObjects(DataMixin, unittest.TestCase):
def
test_directory_to_objects_ignore_name_case
(
self
):
directory
=
Directory
.
from_disk
(
path
=
self
.
tmpdir
.
name
,
path
=
self
.
tmpdir
_
name
,
dir_filter
=
from_disk
.
ignore_named_directories
([
b
'
symLiNks
'
],
case_sensitive
=
False
)
)
...
...
@@ -689,11 +691,11 @@ class DirectoryToObjects(DataMixin, unittest.TestCase):
class
TarballTest
(
DataMixin
,
unittest
.
TestCase
):
def
setUp
(
self
):
super
().
setUp
()
self
.
make_from_tarball
(
self
.
tmpdir
.
name
)
self
.
make_from_tarball
(
self
.
tmpdir
_
name
)
def
test_contents_match
(
self
):
directory
=
Directory
.
from_disk
(
path
=
os
.
path
.
join
(
self
.
tmpdir
.
name
,
b
'
sample-folder
'
)
path
=
os
.
path
.
join
(
self
.
tmpdir
_
name
,
b
'
sample-folder
'
)
)
for
name
,
data
in
self
.
tarball_contents
.
items
():
...
...
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