summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@googlemail.com>2017-04-30 19:09:04 +0200
committerTodd Gamblin <tgamblin@llnl.gov>2017-04-30 10:09:04 -0700
commit6a01612ad4e1f8676b4e0ae477444a2d618096ce (patch)
tree586ee599cb6c16a1d80ef951dcf67fbb89408c3f /lib
parent17767bcf25c4b2bd53c506768696b2ae4533050f (diff)
downloadspack-6a01612ad4e1f8676b4e0ae477444a2d618096ce.tar.gz
spack-6a01612ad4e1f8676b4e0ae477444a2d618096ce.tar.bz2
spack-6a01612ad4e1f8676b4e0ae477444a2d618096ce.tar.xz
spack-6a01612ad4e1f8676b4e0ae477444a2d618096ce.zip
file_list: ported to pytest (#4054)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/file_list.py338
1 files changed, 158 insertions, 180 deletions
diff --git a/lib/spack/spack/test/file_list.py b/lib/spack/spack/test/file_list.py
index 09517b4dab..be4334f055 100644
--- a/lib/spack/spack/test/file_list.py
+++ b/lib/spack/spack/test/file_list.py
@@ -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)
-
- def test_repr(self):
- 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):
- 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'
- )
-
- 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
- )
-
- def test_paths_manipulation(self):
- names = self.liblist.names
- self.assertEqual(names, ['lapack', 'foo', 'blas', 'bar', 'baz'])
-
- directories = self.liblist.directories
- self.assertEqual(directories, ['/dir1', '/dir2', '/dir3'])
-
- def test_get_item(self):
- a = self.liblist[0]
- self.assertEqual(a, '/dir1/liblapack.a')
-
- b = self.liblist[:]
- self.assertEqual(type(b), type(self.liblist))
- self.assertEqual(self.liblist, b)
- self.assertTrue(self.liblist is not b)
-
- def test_add(self):
+@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'
+ ]
+
+ return LibraryList(l)
+
+
+@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
+
+
+class TestLibraryList(object):
+
+ def test_repr(self, library_list):
+ x = eval(repr(library_list))
+ assert library_list == x
+
+ def test_joined_and_str(self, library_list):
+
+ s1 = library_list.joined()
+ expected = '/dir1/liblapack.a /dir2/libfoo.dylib /dir1/libblas.a /dir3/libbar.so libbaz.so' # noqa: E501
+ assert s1 == expected
+
+ s2 = str(library_list)
+ assert s1 == s2
+
+ 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)
- )
-
-
-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
-
- def test_repr(self):
- x = eval(repr(self.headlist))
- self.assertEqual(self.headlist, 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_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'
- )
-
- 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'
- )
-
- cpp_flags = self.headlist.cpp_flags
- self.assertTrue(isinstance(cpp_flags, str))
- self.assertEqual(
- cpp_flags,
- include_flags + ' ' + macros
- )
-
- def test_paths_manipulation(self):
- names = self.headlist.names
- self.assertEqual(
- names,
- ['Python', 'datetime', 'pyconfig', 'core', 'pymem']
- )
-
- directories = self.headlist.directories
- self.assertEqual(directories, ['/dir1', '/dir2', '/dir3'])
-
- def test_get_item(self):
- a = self.headlist[0]
- self.assertEqual(a, '/dir1/Python.h')
-
- b = self.headlist[:]
- self.assertEqual(type(b), type(self.headlist))
- self.assertEqual(self.headlist, b)
- self.assertTrue(self.headlist is not b)
-
- def test_add(self):
+ assert type(library_list + pylist) == type(library_list)
+ assert type(pylist + library_list) == type(library_list)
+
+
+class TestHeaderList(object):
+
+ def test_repr(self, header_list):
+ x = eval(repr(header_list))
+ assert header_list == x
+
+ 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
+
+ s2 = str(header_list)
+ assert s1 == s2
+
+ s3 = header_list.joined(';')
+ expected = '/dir1/Python.h;/dir2/datetime.h;/dir1/pyconfig.h;/dir3/core.h;pymem.h' # noqa: E501
+ assert s3 == expected
+
+ 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'
+
+ 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'
+
+ cpp_flags = header_list.cpp_flags
+ assert isinstance(cpp_flags, str)
+ assert cpp_flags == include_flags + ' ' + macros
+
+ def test_paths_manipulation(self, header_list):
+ names = header_list.names
+ assert names == ['Python', 'datetime', 'pyconfig', 'core', 'pymem']
+
+ directories = header_list.directories
+ assert directories == ['/dir1', '/dir2', '/dir3']
+
+ 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)