aboutsummaryrefslogtreecommitdiffstats
path: root/test/utils/test_commons.py
blob: 3ad6deab5fe1474fb6e4a4c3d3010ea2c559eda3 (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
39
40
41
42
43
44
45
46
"""

Part of the tagit test suite.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2022
"""
# imports
import unittest

# objects to test
from bsfs.utils.commons import typename, normalize_args


## code ##

class TestCommons(unittest.TestCase):
    def test_typename(self):
        class Foo(): pass
        self.assertEqual(typename(Foo()), 'Foo')
        self.assertEqual(typename('hello'), 'str')
        self.assertEqual(typename(123), 'int')
        self.assertEqual(typename(None), 'NoneType')

    def test_normalize_args(self):
        # one argument
        self.assertEqual(normalize_args(1), (1, ))
        # pass as arguments
        self.assertEqual(normalize_args(1,2,3), (1,2,3))
        # pass as iterator
        self.assertEqual(normalize_args(iter([1,2,3])), (1,2,3))
        # pass as generator
        self.assertEqual(normalize_args((i for i in range(1, 4))), (1,2,3))
        self.assertEqual(normalize_args(i for i in range(1, 4)), (1,2,3)) # w/o brackets
        # pass as iterable
        self.assertEqual(normalize_args([1,2,3]), (1,2,3))
        # pass an iterable with a single item
        self.assertEqual(normalize_args([1]), (1, ))



## main ##

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

## EOF ##