Coverage for test/d7a/sp/test_configuration.py: 95%
39 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-24 08:03 +0200
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-24 08:03 +0200
1#
2# Copyright (c) 2015-2021 University of Antwerp, Aloxy NV.
3#
4# This file is part of pyd7a.
5# See https://github.com/Sub-IoT/pyd7a for further info.
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
20# unit tests for the D7A SP (FIFO) Configuration
22import unittest
24from bitstring import ConstBitStream
26from d7a.d7anp.addressee import IdType, NlsMethod
28from d7a.types.ct import CT
29from d7a.sp.qos import QoS, ResponseMode, RetryMode
30from d7a.sp.configuration import Configuration
32class TestConfiguration(unittest.TestCase):
33 def test_default_constructor(self):
34 c = Configuration()
36 def test_invalid_configuration_construction(self):
37 def bad(args, kwargs): Configuration(**kwargs)
38 self.assertRaises(ValueError, bad, [], { "qos" : None })
39 self.assertRaises(ValueError, bad, [], { "addressee" : None })
40 self.assertRaises(ValueError, bad, [], { "dorm_to" : None })
42 def test_configuration_bad_composed_objects(self):
43 def bad(args, kwargs): Configuration(**kwargs)
44 self.assertRaises(ValueError, bad, [], { "qos": CT() })
45 self.assertRaises(ValueError, bad, [], { "dorm_to": QoS() })
46 self.assertRaises(ValueError, bad, [], { "addressee": QoS() })
48 def test_byte_generation(self):
49 # TODO: use mocking framework to mock sub-objects
50 bytes = bytearray(Configuration())
51 self.assertEqual(len(bytes), 4)
52 self.assertEqual(bytes[0], int( '00000000', 2)) # qos
53 self.assertEqual(bytes[1], int( '00000000', 2)) # dorm_to (CT)
54 self.assertEqual(bytes[2], int( '00010000', 2)) # addressee control NOID
55 self.assertEqual(bytes[3], 0) # access class
57 def test_parse(self):
58 bytes = [
59 0b00000000,
60 0,
61 0b00010000,
62 0
63 ]
65 config = Configuration.parse(ConstBitStream(bytes=bytes))
67 self.assertEqual(config.qos.resp_mod, ResponseMode.RESP_MODE_NO)
68 self.assertEqual(config.qos.retry_mod, RetryMode.RETRY_MODE_NO)
69 self.assertEqual(config.qos.stop_on_err, False)
70 self.assertEqual(config.qos.record, False)
71 self.assertEqual(config.addressee.id_type, IdType.NOID)
72 self.assertEqual(config.addressee.nls_method, NlsMethod.NONE)
73 self.assertEqual(config.addressee.access_class, 0)
75if __name__ == '__main__':
76 suite = unittest.TestLoader().loadTestsFromTestCase(TestConfiguration)
77 unittest.TextTestRunner(verbosity=1).run(suite)