def test_lantern(self):
        class Test(object):
            def __init__(self):
                pass

            def path(self):
                return 'test'

        module_mock = MagicMock()
        with patch.dict(
                'sys.modules', **{
                    'lantern': module_mock,
                    'lantern.live': module_mock,
                }):
            module_mock.LanternLive = Test
            from perspective._type import type_detect

            t, _, x = type_detect(Test(), True)

            assert x == 'test'
            assert t == 'lantern'

            import sys
            sys.modules['lantern'] = Nope()
            type_detect('test')
    def test_pandas(self):
        import pandas as pd
        import json
        from perspective._type import type_detect

        df = pd.DataFrame([1, 2])
        t, _, x = type_detect(df, True)

        expected = json.dumps([{"index": 0, "0": 1}, {"index": 1, "0": 2}])
        print(x)
        print(expected)
        assert json.loads(x) == json.loads(expected)
        assert t == 'pandas'

        # series check
        df = pd.DataFrame([1, 2])
        t, _, x = type_detect(df[0], True)

        expected = json.dumps([{"index": 0, "0": 1}, {"index": 1, "0": 2}])
        print(x)
        print(expected)
        assert json.loads(x) == json.loads(expected)
        assert t == 'pandas'

        df = pd.DataFrame([[1, 2]],
                          columns=['1', '2'],
                          index=[datetime.today(),
                                 datetime.today()])
        t, _, x = type_detect(df, True)
        assert t == 'pandas'

        import sys
        sys.modules['pandas'] = Nope()
        type_detect('test', True)
        sys.modules['pandas'] = pd
    def test_dict(self):
        from perspective._type import type_detect
        x = {'a': 'simple test'}

        t, _, y = type_detect(x, True)
        print(y)
        assert y == '[{"a": "simple test"}]'
        assert t == 'dict'
    def test_list(self):
        from perspective._type import type_detect
        x = ['a', 'simple', 'test']

        t, _, y = type_detect(x, True)
        print(y)
        assert y == '["a", "simple", "test"]'
        assert t == 'list'
Beispiel #5
0
    def test_pandas(self):
        import pandas as pd
        import ujson
        from perspective._type import type_detect

        df = pd.DataFrame([1, 2])
        _, x = type_detect(df)

        expected = ujson.dumps([{"index": 0, "0": 1}, {"index": 1, "0": 2}])
        assert x == expected

        df = pd.DataFrame([[1, 2]],
                          columns=['1', '2'],
                          index=[datetime.today(),
                                 datetime.today()])
        _, x = type_detect(df)

        import sys
        sys.modules['pandas'] = Nope()
        type_detect('test')
        sys.modules['pandas'] = pd
Beispiel #6
0
    def test_pyarrow(self):
        import pyarrow as pa
        from perspective._type import type_detect
        x1 = pa.Array(['test', 'test2'])
        x2 = pa.frombuffer(b'test')

        type_detect(x1)
        type_detect(x2)

        import sys
        sys.modules['pyarrow'] = Nope()
        type_detect('test')
        sys.modules['pyarrow'] = pa
Beispiel #7
0
    def test_dict(self):
        from perspective._type import type_detect
        x = {'a': 'simple test'}

        _, y = type_detect(x)
        assert y == '[{"a":"simple test"}]'
Beispiel #8
0
    def test_list(self):
        from perspective._type import type_detect
        x = ['a', 'simple', 'test']

        _, y = type_detect(x)
        assert y == '["a","simple","test"]'
Beispiel #9
0
 def test_other(self):
     from perspective._type import type_detect
     _, x = type_detect('test')
     assert x == 'test'
Beispiel #10
0
 def test_webroutes(self):
     from perspective._type import type_detect
     x = ['https://', 'http://', 'wss://', 'ws://', 'sio://']
     for val in x:
         assert val + 'test' == type_detect(val + 'test')[1]
 def test_other(self):
     from perspective._type import type_detect
     t, _, x = type_detect('test', True)
     assert x == 'test'
     assert t == ''