summaryrefslogtreecommitdiffstats
path: root/python/macholib/macholib_tests/test_dylib.py
blob: dcbc453582d062d18f7a8113042b3b632bf2a55d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from macholib import dylib

import sys
if sys.version_info[:2] <= (2,6):
    import unittest2 as unittest
else:
    import unittest

def d(location=None, name=None, shortname=None, version=None, suffix=None):
    return dict(
        location=location,
        name=name,
        shortname=shortname,
        version=version,
        suffix=suffix
    )

class TestDylib (unittest.TestCase):
    def testInvalid(self):
        self.assertTrue(dylib.dylib_info('completely/invalid') is None)
        self.assertTrue(dylib.dylib_info('completely/invalid_debug') is None)

    def testUnversioned(self):
        self.assertEqual(dylib.dylib_info('P/Foo.dylib'),
                d('P', 'Foo.dylib', 'Foo'))
        self.assertEqual(dylib.dylib_info('P/Foo_debug.dylib'),
                d('P', 'Foo_debug.dylib', 'Foo', suffix='debug'))

    def testVersioned(self):
        self.assertEqual(dylib.dylib_info('P/Foo.A.dylib'),
            d('P', 'Foo.A.dylib', 'Foo', 'A'))
        self.assertEqual(dylib.dylib_info('P/Foo_debug.A.dylib'),
            d('P', 'Foo_debug.A.dylib', 'Foo_debug', 'A'))
        self.assertEqual(dylib.dylib_info('P/Foo.A_debug.dylib'),
            d('P', 'Foo.A_debug.dylib', 'Foo', 'A', 'debug'))

if __name__ == "__main__":
    unittest.main()