1# Copyright (c) 2021 EUMETSAT
2# License: Proprietary
3
4""" Tests for Limits and LimitDefinition classes that represent SRDB tables OCP and OCF """
5
6from chart.products.scos2000.limits import Limits, LimitDefinition
7
8
9def test_limits_init():
10 """ Initialize a Limits object without LimitDefinitions """
11 limits = Limits(['ABC12345', '1', '2', 'U', 'R'])
12
13 assert limits.name == 'ABC12345'
14 assert limits.nbchck == 1
15 assert limits.nbool == 2
16 assert limits.inter == 'U'
17 assert limits.codin == 'R'
18
19
20def test_limits_init_with_definitions():
21 """ Initialize a Limits object including LimitDefinitions.
22 Confirm that definitions are set in the correct order. """
23 limits = Limits(['ABC12345', '1', '2', 'U', 'R'],
24 [['1', 'S', '1.23', '4.56', 'DEF67890', '1'],
25 ['2', 'H', '2.22', '3.33', 'DEF67890', '1']])
26
27 assert len(limits.ocp) == 2
28 assert limits.ocp[0].pos == 1
29 assert limits.ocp[1].pos == 2
30
31
32def test_limits_repr():
33 """ Initialize a Limits object and test for correct __repr__ """
34 limits = Limits(['ABC12345', '1', '2', 'U', 'R'])
35
36 assert repr(limits) == 'Limits([ABC12345, 1, 2, U, R])'
37
38
39def test_limit_definition_init_real():
40 """ Initialize a LimitDefinition object with real (float) limit values. """
41 limit_def = LimitDefinition(['1', 'S', '1.23', '4.56', 'DEF67890', '1'], 'R')
42
43 assert limit_def.pos == 1
44 assert limit_def.type == 'S'
45 assert limit_def.lvalu == 1.23
46 assert limit_def.hvalu == 4.56
47 assert limit_def.rlchk == 'DEF67890'
48 assert limit_def.valpar == 1
49
50
51def test_limit_definition_init_int():
52 """ Initialize a LimitDefinition object with integer limit values. """
53 limit_def = LimitDefinition(['1', 'S', '1', '4', 'DEF67890', '1'], 'I')
54
55 assert limit_def.pos == 1
56 assert limit_def.type == 'S'
57 assert limit_def.lvalu == 1
58 assert limit_def.hvalu == 4
59 assert limit_def.rlchk == 'DEF67890'
60 assert limit_def.valpar == 1
61
62
63def test_limit_definition_init_empty_values():
64 """ Initialize a LimitDefinition object with empty limit values. """
65 limit_def = LimitDefinition(['1', 'C', '', '', 'DEF67890', '1'], 'I')
66
67 assert limit_def.pos == 1
68 assert limit_def.type == 'C'
69 assert limit_def.lvalu == ''
70 assert limit_def.hvalu == ''
71 assert limit_def.rlchk == 'DEF67890'
72 assert limit_def.valpar == 1
73
74
75def test_limit_definition_repr():
76 """ Initialize a LimitDefinition object and test for correct __repr__ """
77 limit_def = LimitDefinition(['1', 'S', '1.23', '4.56', 'DEF67890', '1'], 'R')
78
79 assert repr(limit_def) == 'LimitDefinition([1, S, 1.23, 4.56, DEF67890, 1])'