Coverage for test/d7a/alp/test_action.py: 92%
24 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# author: Christophe VG <contact@christophe.vg>
21# unit tests for the D7 ALP Action
23import unittest
25from d7a.alp.action import Action
26from d7a.alp.regular_action import RegularAction
29class TestAction(unittest.TestCase):
30 def test_default_action_constructor(self):
31 Action()
33 def test_action_construction_switches(self):
34 RegularAction(group=True, resp=True)
36 def test_default_nop_action_operand(self):
37 a = Action()
38 self.assertEqual(a.op, 0)
40 def test_action_bad_operation(self):
41 def bad(): Action(Action())
42 self.assertRaises(ValueError, bad)
44 def test_byte_generation(self):
45 bytes = bytearray(RegularAction())
46 self.assertEqual(len(bytes), 1)
47 self.assertEqual(bytes[0], int('00000000', 2))
49 bytes = bytearray(RegularAction(group=True, resp=True))
50 self.assertEqual(len(bytes), 1)
51 self.assertEqual(bytes[0], int('11000000', 2))
53 # TODO: use mocking to create operations
55if __name__ == '__main__':
56 suite = unittest.TestLoader().loadTestsFromTestCase(TestAction)
57 unittest.TextTestRunner(verbosity=2).run(suite)