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
|
||||
##############################################################################
|
||||
|
||||
import unittest
|
||||
import pytest
|
||||
|
||||
from llnl.util.filesystem import LibraryList, HeaderList
|
||||
|
||||
|
||||
class LibraryListTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
l = [
|
||||
'/dir1/liblapack.a',
|
||||
'/dir2/libfoo.dylib',
|
||||
'/dir1/libblas.a',
|
||||
'/dir3/libbar.so',
|
||||
'libbaz.so'
|
||||
]
|
||||
self.liblist = LibraryList(l)
|
||||
@pytest.fixture()
|
||||
def library_list():
|
||||
"""Returns an instance of LibraryList."""
|
||||
l = [
|
||||
'/dir1/liblapack.a',
|
||||
'/dir2/libfoo.dylib',
|
||||
'/dir1/libblas.a',
|
||||
'/dir3/libbar.so',
|
||||
'libbaz.so'
|
||||
]
|
||||
|
||||
def test_repr(self):
|
||||
x = eval(repr(self.liblist))
|
||||
self.assertEqual(self.liblist, x)
|
||||
return LibraryList(l)
|
||||
|
||||
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):
|
||||
search_flags = self.liblist.search_flags
|
||||
self.assertTrue('-L/dir1' in search_flags)
|
||||
self.assertTrue('-L/dir2' in search_flags)
|
||||
self.assertTrue('-L/dir3' in search_flags)
|
||||
self.assertTrue(isinstance(search_flags, str))
|
||||
self.assertEqual(
|
||||
search_flags,
|
||||
'-L/dir1 -L/dir2 -L/dir3'
|
||||
)
|
||||
@pytest.fixture()
|
||||
def header_list():
|
||||
"""Returns an instance of header list"""
|
||||
h = [
|
||||
'/dir1/Python.h',
|
||||
'/dir2/datetime.h',
|
||||
'/dir1/pyconfig.h',
|
||||
'/dir3/core.h',
|
||||
'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
|
||||
self.assertTrue(isinstance(ld_flags, str))
|
||||
self.assertEqual(
|
||||
ld_flags,
|
||||
search_flags + ' ' + link_flags
|
||||
)
|
||||
class TestLibraryList(object):
|
||||
|
||||
def test_paths_manipulation(self):
|
||||
names = self.liblist.names
|
||||
self.assertEqual(names, ['lapack', 'foo', 'blas', 'bar', 'baz'])
|
||||
def test_repr(self, library_list):
|
||||
x = eval(repr(library_list))
|
||||
assert library_list == x
|
||||
|
||||
directories = self.liblist.directories
|
||||
self.assertEqual(directories, ['/dir1', '/dir2', '/dir3'])
|
||||
def test_joined_and_str(self, library_list):
|
||||
|
||||
def test_get_item(self):
|
||||
a = self.liblist[0]
|
||||
self.assertEqual(a, '/dir1/liblapack.a')
|
||||
s1 = library_list.joined()
|
||||
expected = '/dir1/liblapack.a /dir2/libfoo.dylib /dir1/libblas.a /dir3/libbar.so libbaz.so' # noqa: E501
|
||||
assert s1 == expected
|
||||
|
||||
b = self.liblist[:]
|
||||
self.assertEqual(type(b), type(self.liblist))
|
||||
self.assertEqual(self.liblist, b)
|
||||
self.assertTrue(self.liblist is not b)
|
||||
s2 = str(library_list)
|
||||
assert s1 == s2
|
||||
|
||||
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 = [
|
||||
'/dir1/liblapack.a', # removed from the final list
|
||||
'/dir2/libbaz.so',
|
||||
'/dir4/libnew.a'
|
||||
]
|
||||
another = LibraryList(pylist)
|
||||
l = self.liblist + another
|
||||
self.assertEqual(len(l), 7)
|
||||
l = library_list + another
|
||||
assert len(l) == 7
|
||||
|
||||
# Invariant : l == l + l
|
||||
self.assertEqual(l, l + l)
|
||||
assert l == l + l
|
||||
|
||||
# Always produce an instance of LibraryList
|
||||
self.assertEqual(
|
||||
type(self.liblist),
|
||||
type(self.liblist + pylist)
|
||||
)
|
||||
self.assertEqual(
|
||||
type(pylist + self.liblist),
|
||||
type(self.liblist)
|
||||
)
|
||||
assert type(library_list + pylist) == type(library_list)
|
||||
assert type(pylist + library_list) == type(library_list)
|
||||
|
||||
|
||||
class HeaderListTest(unittest.TestCase):
|
||||
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
|
||||
class TestHeaderList(object):
|
||||
|
||||
def test_repr(self):
|
||||
x = eval(repr(self.headlist))
|
||||
self.assertEqual(self.headlist, x)
|
||||
def test_repr(self, header_list):
|
||||
x = eval(repr(header_list))
|
||||
assert header_list == x
|
||||
|
||||
def test_joined_and_str(self):
|
||||
s1 = self.headlist.joined()
|
||||
self.assertEqual(
|
||||
s1,
|
||||
'/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_joined_and_str(self, header_list):
|
||||
s1 = header_list.joined()
|
||||
expected = '/dir1/Python.h /dir2/datetime.h /dir1/pyconfig.h /dir3/core.h pymem.h' # noqa: E501
|
||||
assert s1 == expected
|
||||
|
||||
def test_flags(self):
|
||||
include_flags = self.headlist.include_flags
|
||||
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'
|
||||
)
|
||||
s2 = str(header_list)
|
||||
assert s1 == s2
|
||||
|
||||
macros = self.headlist.macro_definitions
|
||||
self.assertTrue('-DBOOST_LIB_NAME=boost_regex' in macros)
|
||||
self.assertTrue('-DBOOST_DYN_LINK' in macros)
|
||||
self.assertTrue(isinstance(macros, str))
|
||||
self.assertEqual(
|
||||
macros,
|
||||
'-DBOOST_LIB_NAME=boost_regex -DBOOST_DYN_LINK'
|
||||
)
|
||||
s3 = header_list.joined(';')
|
||||
expected = '/dir1/Python.h;/dir2/datetime.h;/dir1/pyconfig.h;/dir3/core.h;pymem.h' # noqa: E501
|
||||
assert s3 == expected
|
||||
|
||||
cpp_flags = self.headlist.cpp_flags
|
||||
self.assertTrue(isinstance(cpp_flags, str))
|
||||
self.assertEqual(
|
||||
cpp_flags,
|
||||
include_flags + ' ' + macros
|
||||
)
|
||||
def test_flags(self, header_list):
|
||||
include_flags = header_list.include_flags
|
||||
assert '-I/dir1' in include_flags
|
||||
assert '-I/dir2' in include_flags
|
||||
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):
|
||||
names = self.headlist.names
|
||||
self.assertEqual(
|
||||
names,
|
||||
['Python', 'datetime', 'pyconfig', 'core', 'pymem']
|
||||
)
|
||||
macros = header_list.macro_definitions
|
||||
assert '-DBOOST_LIB_NAME=boost_regex' in macros
|
||||
assert '-DBOOST_DYN_LINK' in macros
|
||||
assert isinstance(macros, str)
|
||||
assert macros == '-DBOOST_LIB_NAME=boost_regex -DBOOST_DYN_LINK'
|
||||
|
||||
directories = self.headlist.directories
|
||||
self.assertEqual(directories, ['/dir1', '/dir2', '/dir3'])
|
||||
cpp_flags = header_list.cpp_flags
|
||||
assert isinstance(cpp_flags, str)
|
||||
assert cpp_flags == include_flags + ' ' + macros
|
||||
|
||||
def test_get_item(self):
|
||||
a = self.headlist[0]
|
||||
self.assertEqual(a, '/dir1/Python.h')
|
||||
def test_paths_manipulation(self, header_list):
|
||||
names = header_list.names
|
||||
assert names == ['Python', 'datetime', 'pyconfig', 'core', 'pymem']
|
||||
|
||||
b = self.headlist[:]
|
||||
self.assertEqual(type(b), type(self.headlist))
|
||||
self.assertEqual(self.headlist, b)
|
||||
self.assertTrue(self.headlist is not b)
|
||||
directories = header_list.directories
|
||||
assert directories == ['/dir1', '/dir2', '/dir3']
|
||||
|
||||
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 = [
|
||||
'/dir1/Python.h', # removed from the final list
|
||||
'/dir2/pyconfig.h',
|
||||
'/dir4/datetime.h'
|
||||
]
|
||||
another = HeaderList(pylist)
|
||||
h = self.headlist + another
|
||||
self.assertEqual(len(h), 7)
|
||||
h = header_list + another
|
||||
assert len(h) == 7
|
||||
|
||||
# Invariant : l == l + l
|
||||
self.assertEqual(h, h + h)
|
||||
assert h == h + h
|
||||
|
||||
# Always produce an instance of HeaderList
|
||||
self.assertEqual(
|
||||
type(self.headlist),
|
||||
type(self.headlist + pylist)
|
||||
)
|
||||
self.assertEqual(
|
||||
type(pylist + self.headlist),
|
||||
type(self.headlist)
|
||||
)
|
||||
assert type(header_list + pylist) == type(header_list)
|
||||
assert type(pylist + header_list) == type(header_list)
|
||||
|
Loading…
Reference in New Issue
Block a user