file_list: ported to pytest (#4054)
This commit is contained in:
parent
17767bcf25
commit
6a01612ad4
@ -23,203 +23,181 @@
|
|||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
import unittest
|
import pytest
|
||||||
|
|
||||||
from llnl.util.filesystem import LibraryList, HeaderList
|
from llnl.util.filesystem import LibraryList, HeaderList
|
||||||
|
|
||||||
|
|
||||||
class LibraryListTest(unittest.TestCase):
|
@pytest.fixture()
|
||||||
def setUp(self):
|
def library_list():
|
||||||
l = [
|
"""Returns an instance of LibraryList."""
|
||||||
'/dir1/liblapack.a',
|
l = [
|
||||||
'/dir2/libfoo.dylib',
|
'/dir1/liblapack.a',
|
||||||
'/dir1/libblas.a',
|
'/dir2/libfoo.dylib',
|
||||||
'/dir3/libbar.so',
|
'/dir1/libblas.a',
|
||||||
'libbaz.so'
|
'/dir3/libbar.so',
|
||||||
]
|
'libbaz.so'
|
||||||
self.liblist = LibraryList(l)
|
]
|
||||||
|
|
||||||
def test_repr(self):
|
return LibraryList(l)
|
||||||
x = eval(repr(self.liblist))
|
|
||||||
self.assertEqual(self.liblist, x)
|
|
||||||
|
|
||||||
def test_joined_and_str(self):
|
|
||||||
s1 = self.liblist.joined()
|
|
||||||
self.assertEqual(
|
|
||||||
s1,
|
|
||||||
'/dir1/liblapack.a /dir2/libfoo.dylib /dir1/libblas.a /dir3/libbar.so libbaz.so' # NOQA: ignore=E501
|
|
||||||
)
|
|
||||||
s2 = str(self.liblist)
|
|
||||||
self.assertEqual(s1, s2)
|
|
||||||
s3 = self.liblist.joined(';')
|
|
||||||
self.assertEqual(
|
|
||||||
s3,
|
|
||||||
'/dir1/liblapack.a;/dir2/libfoo.dylib;/dir1/libblas.a;/dir3/libbar.so;libbaz.so' # NOQA: ignore=E501
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_flags(self):
|
@pytest.fixture()
|
||||||
search_flags = self.liblist.search_flags
|
def header_list():
|
||||||
self.assertTrue('-L/dir1' in search_flags)
|
"""Returns an instance of header list"""
|
||||||
self.assertTrue('-L/dir2' in search_flags)
|
h = [
|
||||||
self.assertTrue('-L/dir3' in search_flags)
|
'/dir1/Python.h',
|
||||||
self.assertTrue(isinstance(search_flags, str))
|
'/dir2/datetime.h',
|
||||||
self.assertEqual(
|
'/dir1/pyconfig.h',
|
||||||
search_flags,
|
'/dir3/core.h',
|
||||||
'-L/dir1 -L/dir2 -L/dir3'
|
'pymem.h'
|
||||||
)
|
]
|
||||||
|
h = HeaderList(h)
|
||||||
|
h.add_macro('-DBOOST_LIB_NAME=boost_regex')
|
||||||
|
h.add_macro('-DBOOST_DYN_LINK')
|
||||||
|
return h
|
||||||
|
|
||||||
link_flags = self.liblist.link_flags
|
|
||||||
self.assertTrue('-llapack' in link_flags)
|
|
||||||
self.assertTrue('-lfoo' in link_flags)
|
|
||||||
self.assertTrue('-lblas' in link_flags)
|
|
||||||
self.assertTrue('-lbar' in link_flags)
|
|
||||||
self.assertTrue('-lbaz' in link_flags)
|
|
||||||
self.assertTrue(isinstance(link_flags, str))
|
|
||||||
self.assertEqual(
|
|
||||||
link_flags,
|
|
||||||
'-llapack -lfoo -lblas -lbar -lbaz'
|
|
||||||
)
|
|
||||||
|
|
||||||
ld_flags = self.liblist.ld_flags
|
class TestLibraryList(object):
|
||||||
self.assertTrue(isinstance(ld_flags, str))
|
|
||||||
self.assertEqual(
|
|
||||||
ld_flags,
|
|
||||||
search_flags + ' ' + link_flags
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_paths_manipulation(self):
|
def test_repr(self, library_list):
|
||||||
names = self.liblist.names
|
x = eval(repr(library_list))
|
||||||
self.assertEqual(names, ['lapack', 'foo', 'blas', 'bar', 'baz'])
|
assert library_list == x
|
||||||
|
|
||||||
directories = self.liblist.directories
|
def test_joined_and_str(self, library_list):
|
||||||
self.assertEqual(directories, ['/dir1', '/dir2', '/dir3'])
|
|
||||||
|
|
||||||
def test_get_item(self):
|
s1 = library_list.joined()
|
||||||
a = self.liblist[0]
|
expected = '/dir1/liblapack.a /dir2/libfoo.dylib /dir1/libblas.a /dir3/libbar.so libbaz.so' # noqa: E501
|
||||||
self.assertEqual(a, '/dir1/liblapack.a')
|
assert s1 == expected
|
||||||
|
|
||||||
b = self.liblist[:]
|
s2 = str(library_list)
|
||||||
self.assertEqual(type(b), type(self.liblist))
|
assert s1 == s2
|
||||||
self.assertEqual(self.liblist, b)
|
|
||||||
self.assertTrue(self.liblist is not b)
|
|
||||||
|
|
||||||
def test_add(self):
|
s3 = library_list.joined(';')
|
||||||
|
expected = '/dir1/liblapack.a;/dir2/libfoo.dylib;/dir1/libblas.a;/dir3/libbar.so;libbaz.so' # noqa: E501
|
||||||
|
assert s3 == expected
|
||||||
|
|
||||||
|
def test_flags(self, library_list):
|
||||||
|
|
||||||
|
search_flags = library_list.search_flags
|
||||||
|
assert '-L/dir1' in search_flags
|
||||||
|
assert '-L/dir2' in search_flags
|
||||||
|
assert '-L/dir3' in search_flags
|
||||||
|
assert isinstance(search_flags, str)
|
||||||
|
assert search_flags == '-L/dir1 -L/dir2 -L/dir3'
|
||||||
|
|
||||||
|
link_flags = library_list.link_flags
|
||||||
|
assert '-llapack' in link_flags
|
||||||
|
assert '-lfoo' in link_flags
|
||||||
|
assert '-lblas' in link_flags
|
||||||
|
assert '-lbar' in link_flags
|
||||||
|
assert '-lbaz' in link_flags
|
||||||
|
assert isinstance(link_flags, str)
|
||||||
|
assert link_flags == '-llapack -lfoo -lblas -lbar -lbaz'
|
||||||
|
|
||||||
|
ld_flags = library_list.ld_flags
|
||||||
|
assert isinstance(ld_flags, str)
|
||||||
|
assert ld_flags == search_flags + ' ' + link_flags
|
||||||
|
|
||||||
|
def test_paths_manipulation(self, library_list):
|
||||||
|
names = library_list.names
|
||||||
|
assert names == ['lapack', 'foo', 'blas', 'bar', 'baz']
|
||||||
|
|
||||||
|
directories = library_list.directories
|
||||||
|
assert directories == ['/dir1', '/dir2', '/dir3']
|
||||||
|
|
||||||
|
def test_get_item(self, library_list):
|
||||||
|
a = library_list[0]
|
||||||
|
assert a == '/dir1/liblapack.a'
|
||||||
|
|
||||||
|
b = library_list[:]
|
||||||
|
assert type(b) == type(library_list)
|
||||||
|
assert library_list == b
|
||||||
|
assert library_list is not b
|
||||||
|
|
||||||
|
def test_add(self, library_list):
|
||||||
pylist = [
|
pylist = [
|
||||||
'/dir1/liblapack.a', # removed from the final list
|
'/dir1/liblapack.a', # removed from the final list
|
||||||
'/dir2/libbaz.so',
|
'/dir2/libbaz.so',
|
||||||
'/dir4/libnew.a'
|
'/dir4/libnew.a'
|
||||||
]
|
]
|
||||||
another = LibraryList(pylist)
|
another = LibraryList(pylist)
|
||||||
l = self.liblist + another
|
l = library_list + another
|
||||||
self.assertEqual(len(l), 7)
|
assert len(l) == 7
|
||||||
|
|
||||||
# Invariant : l == l + l
|
# Invariant : l == l + l
|
||||||
self.assertEqual(l, l + l)
|
assert l == l + l
|
||||||
|
|
||||||
# Always produce an instance of LibraryList
|
# Always produce an instance of LibraryList
|
||||||
self.assertEqual(
|
assert type(library_list + pylist) == type(library_list)
|
||||||
type(self.liblist),
|
assert type(pylist + library_list) == type(library_list)
|
||||||
type(self.liblist + pylist)
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
type(pylist + self.liblist),
|
|
||||||
type(self.liblist)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class HeaderListTest(unittest.TestCase):
|
class TestHeaderList(object):
|
||||||
def setUp(self):
|
|
||||||
h = [
|
|
||||||
'/dir1/Python.h',
|
|
||||||
'/dir2/datetime.h',
|
|
||||||
'/dir1/pyconfig.h',
|
|
||||||
'/dir3/core.h',
|
|
||||||
'pymem.h'
|
|
||||||
]
|
|
||||||
headlist = HeaderList(h)
|
|
||||||
headlist.add_macro('-DBOOST_LIB_NAME=boost_regex')
|
|
||||||
headlist.add_macro('-DBOOST_DYN_LINK')
|
|
||||||
self.headlist = headlist
|
|
||||||
|
|
||||||
def test_repr(self):
|
def test_repr(self, header_list):
|
||||||
x = eval(repr(self.headlist))
|
x = eval(repr(header_list))
|
||||||
self.assertEqual(self.headlist, x)
|
assert header_list == x
|
||||||
|
|
||||||
def test_joined_and_str(self):
|
def test_joined_and_str(self, header_list):
|
||||||
s1 = self.headlist.joined()
|
s1 = header_list.joined()
|
||||||
self.assertEqual(
|
expected = '/dir1/Python.h /dir2/datetime.h /dir1/pyconfig.h /dir3/core.h pymem.h' # noqa: E501
|
||||||
s1,
|
assert s1 == expected
|
||||||
'/dir1/Python.h /dir2/datetime.h /dir1/pyconfig.h /dir3/core.h pymem.h' # NOQA: ignore=E501
|
|
||||||
)
|
|
||||||
s2 = str(self.headlist)
|
|
||||||
self.assertEqual(s1, s2)
|
|
||||||
s3 = self.headlist.joined(';')
|
|
||||||
self.assertEqual(
|
|
||||||
s3,
|
|
||||||
'/dir1/Python.h;/dir2/datetime.h;/dir1/pyconfig.h;/dir3/core.h;pymem.h' # NOQA: ignore=E501
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_flags(self):
|
s2 = str(header_list)
|
||||||
include_flags = self.headlist.include_flags
|
assert s1 == s2
|
||||||
self.assertTrue('-I/dir1' in include_flags)
|
|
||||||
self.assertTrue('-I/dir2' in include_flags)
|
|
||||||
self.assertTrue('-I/dir3' in include_flags)
|
|
||||||
self.assertTrue(isinstance(include_flags, str))
|
|
||||||
self.assertEqual(
|
|
||||||
include_flags,
|
|
||||||
'-I/dir1 -I/dir2 -I/dir3'
|
|
||||||
)
|
|
||||||
|
|
||||||
macros = self.headlist.macro_definitions
|
s3 = header_list.joined(';')
|
||||||
self.assertTrue('-DBOOST_LIB_NAME=boost_regex' in macros)
|
expected = '/dir1/Python.h;/dir2/datetime.h;/dir1/pyconfig.h;/dir3/core.h;pymem.h' # noqa: E501
|
||||||
self.assertTrue('-DBOOST_DYN_LINK' in macros)
|
assert s3 == expected
|
||||||
self.assertTrue(isinstance(macros, str))
|
|
||||||
self.assertEqual(
|
|
||||||
macros,
|
|
||||||
'-DBOOST_LIB_NAME=boost_regex -DBOOST_DYN_LINK'
|
|
||||||
)
|
|
||||||
|
|
||||||
cpp_flags = self.headlist.cpp_flags
|
def test_flags(self, header_list):
|
||||||
self.assertTrue(isinstance(cpp_flags, str))
|
include_flags = header_list.include_flags
|
||||||
self.assertEqual(
|
assert '-I/dir1' in include_flags
|
||||||
cpp_flags,
|
assert '-I/dir2' in include_flags
|
||||||
include_flags + ' ' + macros
|
assert '-I/dir3' in include_flags
|
||||||
)
|
assert isinstance(include_flags, str)
|
||||||
|
assert include_flags == '-I/dir1 -I/dir2 -I/dir3'
|
||||||
|
|
||||||
def test_paths_manipulation(self):
|
macros = header_list.macro_definitions
|
||||||
names = self.headlist.names
|
assert '-DBOOST_LIB_NAME=boost_regex' in macros
|
||||||
self.assertEqual(
|
assert '-DBOOST_DYN_LINK' in macros
|
||||||
names,
|
assert isinstance(macros, str)
|
||||||
['Python', 'datetime', 'pyconfig', 'core', 'pymem']
|
assert macros == '-DBOOST_LIB_NAME=boost_regex -DBOOST_DYN_LINK'
|
||||||
)
|
|
||||||
|
|
||||||
directories = self.headlist.directories
|
cpp_flags = header_list.cpp_flags
|
||||||
self.assertEqual(directories, ['/dir1', '/dir2', '/dir3'])
|
assert isinstance(cpp_flags, str)
|
||||||
|
assert cpp_flags == include_flags + ' ' + macros
|
||||||
|
|
||||||
def test_get_item(self):
|
def test_paths_manipulation(self, header_list):
|
||||||
a = self.headlist[0]
|
names = header_list.names
|
||||||
self.assertEqual(a, '/dir1/Python.h')
|
assert names == ['Python', 'datetime', 'pyconfig', 'core', 'pymem']
|
||||||
|
|
||||||
b = self.headlist[:]
|
directories = header_list.directories
|
||||||
self.assertEqual(type(b), type(self.headlist))
|
assert directories == ['/dir1', '/dir2', '/dir3']
|
||||||
self.assertEqual(self.headlist, b)
|
|
||||||
self.assertTrue(self.headlist is not b)
|
|
||||||
|
|
||||||
def test_add(self):
|
def test_get_item(self, header_list):
|
||||||
|
a = header_list[0]
|
||||||
|
assert a == '/dir1/Python.h'
|
||||||
|
|
||||||
|
b = header_list[:]
|
||||||
|
assert type(b) == type(header_list)
|
||||||
|
assert header_list == b
|
||||||
|
assert header_list is not b
|
||||||
|
|
||||||
|
def test_add(self, header_list):
|
||||||
pylist = [
|
pylist = [
|
||||||
'/dir1/Python.h', # removed from the final list
|
'/dir1/Python.h', # removed from the final list
|
||||||
'/dir2/pyconfig.h',
|
'/dir2/pyconfig.h',
|
||||||
'/dir4/datetime.h'
|
'/dir4/datetime.h'
|
||||||
]
|
]
|
||||||
another = HeaderList(pylist)
|
another = HeaderList(pylist)
|
||||||
h = self.headlist + another
|
h = header_list + another
|
||||||
self.assertEqual(len(h), 7)
|
assert len(h) == 7
|
||||||
|
|
||||||
# Invariant : l == l + l
|
# Invariant : l == l + l
|
||||||
self.assertEqual(h, h + h)
|
assert h == h + h
|
||||||
|
|
||||||
# Always produce an instance of HeaderList
|
# Always produce an instance of HeaderList
|
||||||
self.assertEqual(
|
assert type(header_list + pylist) == type(header_list)
|
||||||
type(self.headlist),
|
assert type(pylist + header_list) == type(header_list)
|
||||||
type(self.headlist + pylist)
|
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
type(pylist + self.headlist),
|
|
||||||
type(self.headlist)
|
|
||||||
)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user