Skip to content
Snippets Groups Projects
Commit a401130c authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

More unittests

parent d1059df1
No related branches found
No related tags found
No related merge requests found
#!/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)
......@@ -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
#!/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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment