Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-imcflibs
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
imcf
python-imcflibs
Commits
a401130c
Commit
a401130c
authored
6 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
More unittests
parent
d1059df1
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/test_iotools.py
+57
-0
57 additions, 0 deletions
tests/test_iotools.py
tests/test_pathtools.py
+14
-0
14 additions, 0 deletions
tests/test_pathtools.py
tests/test_strtools.py
+32
-0
32 additions, 0 deletions
tests/test_strtools.py
with
103 additions
and
0 deletions
tests/test_iotools.py
0 → 100644
+
57
−
0
View file @
a401130c
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
pytest
import
zipfile
from
os.path
import
join
from
imcflibs.iotools
import
filehandle
from
imcflibs.iotools
import
readtxt
__author__
=
"
Niko Ehrenfeuchter
"
__copyright__
=
"
Niko Ehrenfeuchter
"
__license__
=
"
gpl3
"
def
test_filehandle
(
tmpdir
):
tmpfile
=
tmpdir
.
join
(
'
testfile
'
)
tmpname
=
str
(
tmpfile
)
tmphandle
=
open
(
str
(
tmpfile
),
'
w
'
)
print
(
type
(
tmphandle
))
assert
type
(
tmpname
)
is
str
assert
type
(
tmphandle
)
is
file
assert
type
(
filehandle
(
tmpname
))
is
file
assert
type
(
filehandle
(
tmphandle
,
'
w
'
))
is
file
def
test_readtxt
(
tmpdir
):
content
=
[
u
'
lorem
\n
'
,
u
'
ipsum
\n
'
,
u
'
and some more
\n
'
,
u
'
dummy text
\n
'
,
]
fh
=
tmpdir
.
mkdir
(
"
readtxt
"
).
join
(
"
content.txt
"
)
fh
.
write
(
u
''
.
join
(
content
))
print
(
fh
.
basename
)
print
(
fh
.
dirname
)
with
zipfile
.
ZipFile
(
join
(
fh
.
dirname
,
'
archive.zip
'
),
'
w
'
)
as
zf
:
zf
.
write
(
str
(
fh
),
arcname
=
'
content.txt
'
)
print
(
"
wrote [%s] into [%s]
"
%
(
str
(
fh
),
zf
.
filename
))
print
(
content
)
fromfile
=
readtxt
(
str
(
fh
))
print
(
fromfile
)
assert
fromfile
==
content
fromfile_flat
=
readtxt
(
str
(
fh
),
flat
=
True
)
assert
fromfile_flat
==
''
.
join
(
content
)
print
(
join
(
fh
.
dirname
,
'
archive.zip
'
))
fromzip
=
readtxt
(
'
content.txt
'
,
join
(
fh
.
dirname
,
'
archive.zip
'
))
print
(
fromzip
)
assert
fromzip
==
content
fromzip_flat
=
readtxt
(
'
content.txt
'
,
join
(
fh
.
dirname
,
'
archive.zip
'
),
flat
=
True
)
assert
fromzip_flat
==
''
.
join
(
content
)
This diff is collapsed.
Click to expand it.
tests/test_pathtools.py
+
14
−
0
View file @
a401130c
...
...
@@ -3,6 +3,7 @@
import
pytest
from
imcflibs.pathtools
import
parse_path
from
imcflibs.pathtools
import
jython_fiji_exists
__author__
=
"
Niko Ehrenfeuchter
"
__copyright__
=
"
Niko Ehrenfeuchter
"
...
...
@@ -31,3 +32,16 @@ def test_parse_path():
assert
path_to_dir
[
'
dname
'
]
==
'
foo
'
assert
path_to_dir
[
'
ext
'
]
==
''
def
test_parse_path_windows
():
path
=
r
'
C:\foo\bar
'
parsed
=
parse_path
(
path
)
assert
parsed
[
'
orig
'
]
==
path
assert
parsed
[
'
full
'
]
==
r
'
C:/foo/bar
'
assert
parsed
[
'
fname
'
]
==
'
bar
'
assert
parsed
[
'
dname
'
]
==
'
foo
'
def
test_jython_fiji_exists
(
tmpdir
):
assert
jython_fiji_exists
(
str
(
tmpdir
))
==
True
This diff is collapsed.
Click to expand it.
tests/test_strtools.py
0 → 100644
+
32
−
0
View file @
a401130c
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
pytest
import
os
from
imcflibs.strtools
import
_is_string_like
from
imcflibs.strtools
import
filename
from
imcflibs.strtools
import
flatten
__author__
=
"
Niko Ehrenfeuchter
"
__copyright__
=
"
Niko Ehrenfeuchter
"
__license__
=
"
gpl3
"
def
test__is_string_like
():
assert
_is_string_like
(
'
foo
'
)
==
True
assert
_is_string_like
(
12345
)
==
False
def
test_filename_from_string
():
assert
filename
(
'
test_file_name
'
)
==
'
test_file_name
'
def
test_filename_from_handle
(
tmpdir
):
path
=
str
(
tmpdir
)
fhandle
=
tmpdir
.
join
(
'
foo.txt
'
)
assert
filename
(
fhandle
)
==
os
.
path
.
join
(
path
,
'
foo.txt
'
)
def
test_flatten
():
assert
flatten
((
'
foo
'
,
'
bar
'
))
==
'
foobar
'
\ No newline at end of file
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