test_file_tags_writer_reader.py 2.11 KB
Newer Older
Aleksiej Chrabrow's avatar
Aleksiej Chrabrow committed
1
#!/usr/bin/env python3
2 3 4
# -*- coding: utf-8 -*-
# Copyright (c) 2016-2018 Braintech Sp. z o.o. [Ltd.] <http://www.braintech.pl>
# All rights reserved.
Aleksiej Chrabrow's avatar
Aleksiej Chrabrow committed
5 6

"""
7
>>> from obci_readmanager.signal_processing.tags import tags_file_writer as p
Aleksiej Chrabrow's avatar
Aleksiej Chrabrow committed
8

9
>>> from obci_readmanager.signal_processing.tags import tags_file_reader as t
Aleksiej Chrabrow's avatar
Aleksiej Chrabrow committed
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

>>> px = p.TagsFileWriter('./tescik.obci.tags')

>>> px.tag_received({'start_timestamp':1001.0, 'end_timestamp':1002.0, 'name': 'nic', 'channels':'A B C',\
                    'desc': {'x':123, 'y':456, 'z': 789}})

>>> px.tag_received({'start_timestamp':1003.0, 'end_timestamp':1004.0, 'name': 'nic2', 'channels':'A B C',\
                    'desc': {'x':1234, 'y':4567, 'z': 789}})

>>> px.tag_received({'start_timestamp':1005.0, 'end_timestamp':1006.0, 'name': 'nic3', 'channels':'A B C',\
                    'desc': {'x':12345, 'y':45678, 'z': 789}})

>>> px.finish_saving(1000.0)
'./tescik.obci.tags'

>>> py = t.TagsFileReader('tescik.obci.tags')

>>> g = py.get_tags()[0]

>>> print(g['start_timestamp'])
1.0

>>> print(g['end_timestamp'])
2.0

>>> print(g['name'])
nic

>>> print(g['desc']['y'])
456

>>> print([int(t['start_timestamp']) for t in py.get_tags()])
[1, 3, 5]


>>> #REORDER AND TEST ORDERING AGAIN ....

>>> px = p.TagsFileWriter('./tescik.obci.tags')

>>> px.tag_received({'start_timestamp':1003.0, 'end_timestamp':1004.0, 'name': 'nic2', 'channels':'A B C',\
                     'desc': {'x':1234, 'y':4567, 'z': 789}})

>>> px.tag_received({'start_timestamp':1005.0, 'end_timestamp':1006.0, 'name': 'nic3', 'channels':'A B C',\
                    'desc': {'x':12345, 'y':45678, 'z': 789}})

>>> px.tag_received({'start_timestamp':1001.0, 'end_timestamp':1002.0, 'name': 'nic', 'channels':'A B C',\
                    'desc': {'x':123, 'y':456, 'z': 789}})

>>> print([int(t['start_timestamp']) for t in py.get_tags()])
[1, 3, 5]

>>> import os

>>> import glob

>>> for fl in glob.glob('tescik*'): os.remove(fl)

"""


def run():
    import doctest
    import sys
    res = doctest.testmod(sys.modules[__name__])
    if res.failed == 0:
        print("All tests succeeded!")

77

Aleksiej Chrabrow's avatar
Aleksiej Chrabrow committed
78 79
if __name__ == '__main__':
    run()