Mercurial > hg > Lemuriformes
comparison tests/test_cast.py @ 18:56596902e9ae default tip
add some setup + tests
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 10 Dec 2017 17:57:03 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:4793f99b73e0 | 18:56596902e9ae |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 """ | |
4 data casting functions | |
5 """ | |
6 | |
7 import unittest | |
8 from lemiformes import cast | |
9 | |
10 class TestCast(unittest.TestCase): | |
11 | |
12 def test_isiterable(self): | |
13 assert not cast.isiterable(1) | |
14 assert cast.isiterable(range(5)) | |
15 | |
16 def test_make_iterable(self): | |
17 iterval = cast.iterable(1) | |
18 assert cast.isiterable(iterval) | |
19 assert list(iterval) == [1] | |
20 assert cast.iterable([1,2,3]) == [1,2,3] | |
21 | |
22 def test_interference(self): | |
23 ints = ['1', '2', '3'] | |
24 floats = ['1', '2', '3.5'] | |
25 strings = ['1', '2', "I'm a kitty!"] | |
26 | |
27 assert cast.infer(ints) == int | |
28 assert cast.infer(floats) == float | |
29 assert cast.infer(strings) == str | |
30 | |
31 def test_casting(self): | |
32 ints = ['1', '2', '3'] | |
33 floats = ['1', '2', '3.5'] | |
34 strings = ['1', '2', "I'm a kitty!"] | |
35 | |
36 assert cast.cast(ints) == [1, 2, 3] | |
37 assert cast.cast(floats) == [1., 2., 3.5] | |
38 assert cast.cast(strings) == strings | |
39 | |
40 | |
41 if __name__ == '__main__': | |
42 unittest.main() |