Mercurial > hg > Lemuriformes
view 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 |
line wrap: on
line source
#!/usr/bin/env python """ data casting functions """ import unittest from lemiformes import cast class TestCast(unittest.TestCase): def test_isiterable(self): assert not cast.isiterable(1) assert cast.isiterable(range(5)) def test_make_iterable(self): iterval = cast.iterable(1) assert cast.isiterable(iterval) assert list(iterval) == [1] assert cast.iterable([1,2,3]) == [1,2,3] def test_interference(self): ints = ['1', '2', '3'] floats = ['1', '2', '3.5'] strings = ['1', '2', "I'm a kitty!"] assert cast.infer(ints) == int assert cast.infer(floats) == float assert cast.infer(strings) == str def test_casting(self): ints = ['1', '2', '3'] floats = ['1', '2', '3.5'] strings = ['1', '2', "I'm a kitty!"] assert cast.cast(ints) == [1, 2, 3] assert cast.cast(floats) == [1., 2., 3.5] assert cast.cast(strings) == strings if __name__ == '__main__': unittest.main()