Пример #1
0
    def test_element_list_selector(self):
        # Setup
        tree, parser = parse(os.path.join(self.data_dir, 'DCMotor.mo'))

        # Act
        selector = ElementListSelector()
        element_list = selector.apply_to_root(tree, parser)

        # Assert
        self.assertEqual(1, len(element_list), "should have one element list")
        self.assertIsRule(element_list[0], 'element_list', parser)
Пример #2
0
    def test_nth_child_selector(self):
        # Setup
        tree, parser = parse(os.path.join(self.data_dir, 'DCMotor.mo'))

        # Act
        selector = (ElementListSelector().chain(NthChildSelector(2)))
        element = selector.apply_to_root(tree, parser)

        # Assert
        self.assertEqual(1, len(element), "should have one element")
        # the third child should be the Inductor line
        # (semicolons are also children of the element_list)
        elementText = element[0].getText()
        self.assertTrue(elementText.startswith('Inductor'))
Пример #3
0
    def test_assert_count_fails(self):
        # Setup
        class NoneSelector(Selector):
            """NoneSelector selects nothing"""
            def _select(self, root, parser):
                return []

        tree, parser = parse(os.path.join(self.data_dir, 'DCMotor.mo'))

        # Act, Assert
        selector = NoneSelector().assert_count(
            1, 'Unexpected number of nodes selected')

        with self.assertRaises(Exception):
            selector.apply_to_root(tree, parser)
Пример #4
0
    def test_assert_count_passes(self):
        # Setup
        class OneSelector(Selector):
            """OneSelector selects one node"""
            def _select(self, root, parser):
                # note that we aren't really using a node from tree
                # it shouldn't matter for this test
                return [{}]

        tree, parser = parse(os.path.join(self.data_dir, 'DCMotor.mo'))

        # Act, Assert
        selector = OneSelector().assert_count(
            1, 'Unexpected number of nodes selected')
        # no exception should be raised
        selector.apply_to_root(tree, parser)
Пример #5
0
 def __init__(self, source):
     self._source = source
     self._tree, self._parser = parse(source)
     self._transformations = []
     self._listener = None