Debian Codegraph @

nixio/test/test_util.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # Copyright © 2014, German Neuroinformatics Node (G-Node)
3 #
4 # All rights reserved.
5 #
6 # Redistribution and use in section and binary forms, with or without
7 # modification, are permitted under the terms of the BSD License. See
8 # LICENSE file in the root of the Project.
9 import unittest
10 from nixio.util import names, units
11
12
13 class TestUtil(unittest.TestCase):
14
15 def setUp(self):
16 pass
17
18 def tearDown(self):
19 pass
20
21 def test_name_sanitizer(self):
22 assert names.sanitizer("validName") == "validName"
23 assert names.sanitizer("invalid/name") == "invalid_name"
24
25 def test_name_check(self):
26 assert names.check("validName")
27 assert not names.check("invalid/name")
28
29 def test_unit_sanitizer(self):
30 assert units.sanitizer("µV") == "uV"
31 assert units.sanitizer("muOhm") == "uOhm"
32
33 def test_unit_is_si(self):
34 assert units.is_si('V')
35 assert units.is_si('mV')
36 assert units.is_si('kV')
37 assert not units.is_si('Kv')
38 assert not units.is_si('in')
39 assert not units.is_si('pt')
40 assert not units.is_si('ft')
41 assert not units.is_si('yrd')
42
43 def test_unit_is_atomic(self):
44 assert units.is_atomic('mV')
45 assert units.is_atomic('mV^2')
46 assert not units.is_atomic('mV^2/Hz')
47
48 def test_unit_is_compound(self):
49 assert units.is_compound('mV^2/Hz')
50 assert not units.is_compound('mV')
51
52 def test_unit_split_compound(self):
53 unit_1 = "mV^2/Hz"
54 unit_2 = "mV^2 * Hz^-1"
55
56 assert len(units.split_compound('mV')) == 1
57
58 atomics = units.split_compound(unit_1)
59 assert len(atomics) == 2
60 # FIXME the following is not entirely correct should be Hz^-1
61 # needs to be fixed in nix!
62 assert atomics[0] == "mV^2" and atomics[1] == "Hz^-1"
63
64 atomics = units.split_compound(unit_2)
65 assert len(atomics) == 2
66 assert atomics[0] == "mV^2" and atomics[1] == "Hz^-1"
67
68 def test_unit_scalable(self):
69 base_unit = 'V'
70 scalable_1 = 'kV'
71 scalable_2 = 'uV'
72 inscalable = 'g'
73
74 assert units.scalable([base_unit], [scalable_1])
75 assert units.scalable([base_unit], [scalable_2])
76 assert units.scalable([base_unit], [base_unit])
77 assert not units.scalable([base_unit], [inscalable])
78 assert(units.scalable([base_unit, scalable_1],
79 [base_unit, scalable_2]))
80
81 def test_unit_scaling(self):
82 base_unit = 'V'
83 scalable_1 = 'kV'
84 scalable_2 = 'uV'
85
86 assert units.scaling(base_unit, scalable_1) == 1e-03
87 assert units.scaling(base_unit, scalable_2) == 1e06
88
89 def test_unit_split(self):
90 unit_1 = 'kV'
91 unit_2 = 'mV^2'
92 unit_3 = 'Hz^-1'
93
94 prefix, base, power = units.split(unit_1)
95 assert prefix == 'k' and base == 'V' and power == ''
96
97 prefix, base, power = units.split(unit_2)
98 assert prefix == 'm' and base == 'V' and power == '2'
99
100 prefix, base, power = units.split(unit_3)
101 assert prefix == '' and base == 'Hz' and power == '-1'