blob: 4b76838cd7459665d97da05e3ce3798dc12b3203 [file] [log] [blame]
Wei-Yu Chen49950b92021-11-08 19:19:18 +08001"""
2Copyright 2020 The Magma Authors.
3
4This source code is licensed under the BSD-style license found in the
5LICENSE file in the root directory of this source tree.
6
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License.
12"""
13
14# pylint: disable=protected-access
15from unittest import TestCase
16
17from data_models.transform_for_magma import bandwidth, gps_tr181
18from exceptions import ConfigurationError
19
20
21class TransformForMagmaTests(TestCase):
22 def test_gps_tr181(self) -> None:
23 # Negative longitude
24 inp = '-122150583'
25 out = gps_tr181(inp)
26 expected = '-122.150583'
27 self.assertEqual(out, expected, 'Should convert negative longitude')
28
29 inp = '122150583'
30 out = gps_tr181(inp)
31 expected = '122.150583'
32 self.assertEqual(out, expected, 'Should convert positive longitude')
33
34 inp = '0'
35 out = gps_tr181(inp)
36 expected = '0.0'
37 self.assertEqual(out, expected, 'Should leave zero as zero')
38
39 def test_bandwidth(self) -> None:
40 inp = 'n6'
41 out = bandwidth(inp)
42 expected = 1.4
43 self.assertEqual(out, expected, 'Should convert RBs')
44
45 inp = 1.4
46 out = bandwidth(inp)
47 expected = 1.4
48 self.assertEqual(out, expected, 'Should accept MHz')
49
50 with self.assertRaises(ConfigurationError):
51 inp = 'asdf'
52 bandwidth(inp)
53
54 with self.assertRaises(ConfigurationError):
55 inp = 1234
56 bandwidth(inp)