Ejemplo n.º 1
0
    def test_find_classes(self):
        test_tag_entries = (
            [
                PRE_POST_ORIG_TAG,
                ANOTHER_ORIG_TAG,
                parse_ljsl.TagComponent("", "PRE_", 200, 2, 3, "_POST", True, [])
            ],
            [
                parse_ljsl.TagComponent("", "PRE_", 300, 2, 3, "_POST", True, [])
            ]
        )

        classes = lj_scribe.find_classes(test_tag_entries, TEST_DEVICE_REGS)
        self.assertEqual(len(classes), 2)

        class_group_1 = classes[0]
        self.assertEqual(len(class_group_1), 3)

        sub_group_1 = class_group_1[0]
        sub_name_group_1 = map(lambda x: x[0]["name"], sub_group_1)
        self.assertEqual(
            sub_name_group_1,
            ["ORIG_PRE_100_POST", "ORIG_PRE_100_POST"]
        )

        sub_group_2 = class_group_1[1]
        sub_name_group_2 = map(lambda x: x[0]["name"], sub_group_2)
        self.assertEqual(
            sub_name_group_2,
            ["ORIG_ANOTHER_200", "ORIG_ANOTHER_200"]
        )

        sub_group_3 = class_group_1[2]
        sub_name_group_3 = map(lambda x: x[0]["name"], sub_group_3)
        self.assertEqual(
            sub_name_group_3,
            ["ORIG_PRE_100_POST", "ORIG_PRE_100_POST"]
        )

        class_group_2 = classes[1]
        self.assertEqual(len(class_group_2), 1)

        sub_group_4 = class_group_2[0]
        sub_name_group_4 = map(lambda x: x[0]["name"], sub_group_4)
        self.assertEqual(
            sub_name_group_4,
            ["ORIG_PRE_100_POST", "ORIG_PRE_100_POST"]
        )
Ejemplo n.º 2
0
    def test_unknown_register(self):
        test_tag_entries = [
            [
                parse_ljsl.TagComponent("", "UNKNOWN", 200, 2, 3, "_POST", True, [])
            ]
        ]

        with self.assertRaises(lj_scribe.RegisterNotFoundError):
            classes = lj_scribe.find_classes(test_tag_entries, TEST_DEVICE_REGS)
Ejemplo n.º 3
0
    def test_render_tag_summary(self):
        with TEST_APP.test_request_context("/"):
            special_tag = parse_ljsl.TagComponent("", "PRE_", 100, 4, 3,
                "_POST", True, [])
            str_summary = lj_scribe.render_tag_summary(
                TEST_TAG_BY_CLASS_NAMES,
                [
                    special_tag,
                    ANOTHER_ORIG_TAG,
                    NO_LJMMM_ORIG_TAG
                ],
                "ORIG_TAG"
            )

        self.assertEqual(str_summary.count("class-summary"), 3)
        self.assertEqual(str_summary.count("sub-tag"), 3)
        self.assertEqual(str_summary.count("individual-name"), 6)
        self.assertEqual(str_summary.count("individual-address"), 6)
        self.assertEqual(str_summary.count("ORIG_TAG"), 1)
Ejemplo n.º 4
0
    def test_find_classes_from_map(self):
        names = [[parse_ljsl.TagComponent(
            title='',
            prefix=u'LED_COMM',
            start_num=None,
            num_regs=None,
            num_between_regs=None,
            postfix=None,
            includes_ljmmm=False,
            device_types=[]
        )]]

        LED_COMM_PAIR = lj_scribe.UnresolvedToResolvedPair(
            {
                'streamable': False,
                'displayname': ['LED COMM displayname'],
                'name': 'LED_COMM',
                'tags': ['DIO'],
                'readwrite': 'RW',
                'devices': [
                    {'name': 'T7', 'fwmin': 1.7777},
                    {'name': 'T4', 'fwmin': 1.4444}
                ],
                'address': 2990,
                'type': 'UINT16',
                'description': 'Test desc.',
                'constants': [
                    {'name': 'Off', 'value': 0},
                    {'name': 'On', 'value': 1},
                ]
            },
            {
                'streamable': False,
                'description': 'Test desc.',
                'tags': ['DIO'],
                'altnames': [],
                'write': True,
                'type_index': '1',
                'read': True,
                'constants': [
                    {'name': 'Off', 'value': 0},
                    {'name': 'On', 'value': 1},
                ],
                'address': 2990,
                'type': 'UINT16',
                'isBuffer': False,
                'name': 'LED_COMM'
            }
        )

        reg_maps = {
            'T7': [LED_COMM_PAIR],
            'T4': [LED_COMM_PAIR]
        }
        reg_maps['T4'][0][1]['fwmin'] = 1.4444
        reg_maps['T7'][0][1]['fwmin'] = 1.7777
        not_found_reg_names = []
        tag_class_tuples = lj_scribe.find_classes_from_map(
            names,
            reg_maps,
            not_found_reg_names
        )

        EXPECTED_TAG_CLASS_TUPLES = [[[
            lj_scribe.UnresolvedToResolvedPair(
                unresolved={
                    'streamable': False,
                    'displayname': ['LED COMM displayname'],
                    'name': 'LED_COMM',
                    'tags': ['DIO'],
                    'readwrite': 'RW',
                    'constants': [
                        {'name': 'Off', 'value': 0},
                        {'name': 'On', 'value': 1}
                    ],
                    'address': 2990,
                    'type': 'UINT16',
                    'devices': [
                        {'name': 'T7', 'fwmin': 1.7777},
                        {'name': 'T4', 'fwmin': 1.4444}
                    ],
                    'description': 'Test desc.'
                },
                resolved={
                    'description': 'Test desc.',
                    'tags': ['DIO'],
                    'read': True,
                    'type_index': '1',
                    'address': 2990,
                    'constants': [
                        {'name': 'Off', 'value': 0},
                        {'name': 'On', 'value': 1}
                    ],

                    'fwmin': 1.7777, # This isn't needed

                    'streamable': False,
                    'name': 'LED_COMM',
                    'altnames': [],
                    'write': True,
                    'isBuffer': False,
                    'type': 'UINT16'
                }
            )
        ]]]

        self.assertEqual(0, len(not_found_reg_names))
        self.assertEqual(EXPECTED_TAG_CLASS_TUPLES, tag_class_tuples)
Ejemplo n.º 5
0
    ({"name": "ORIG_PRE_100_POST"}, {"name": "PRE_100_POST"}),
    ({"name": "ORIG_PRE_100_POST"}, {"name": "PRE_103_POST"}),
    ({"name": "ORIG_PRE_100_POST"}, {"name": "PRE_200_POST"}),
    ({"name": "ORIG_PRE_100_POST"}, {"name": "PRE_203_POST"}),
    ({"name": "ORIG_PRE_100_POST"}, {"name": "PRE_300_POST"}),
    ({"name": "ORIG_PRE_100_POST"}, {"name": "PRE_303_POST"}),
    ({"name": "ORIG_ANOTHER_200"}, {"name": "ANOTHER_200"}),
    ({"name": "ORIG_ANOTHER_200"}, {"name": "ANOTHER_203"})
)

TEST_RESOLVED_TO_UNRESOLVED_PAIRS = map(
    lambda x: lj_scribe.UnresolvedToResolvedPair(*x),
    TEST_DEVICE_REGS
)

PRE_POST_ORIG_TAG = parse_ljsl.TagComponent("", "PRE_", 100, 2, 3, "_POST",
    True, [])
ANOTHER_ORIG_TAG = parse_ljsl.TagComponent("", "ANOTHER_", 200, 2, 3, "", True, [])
ORIG_TAG_NO_GAP = parse_ljsl.TagComponent("", "YAC", 200, 2, None, "", True, [])
NO_LJMMM_ORIG_TAG = parse_ljsl.TagComponent("", "TEST", None, None, None, None,
    False, [])

LOREM_IPSUM = '''Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.'''

PRE_POST_GROUPING = lj_scribe.UnresolvedWithResolvedGrouping(
    resolved=[
        {