コード例 #1
0
ファイル: tests.py プロジェクト: shawnchin/hexaviz
    def test_textual_representation_can_be_rendered_for_an_empty_mesh(self):
        # GIVEN an empty mesh
        m = Mesh()

        # WHEN the textual representation is rendered
        out = render(m, self.JSON_TEMPLATE)

        # THEN the rendered output reflects that of an empty mesh
        out_data = json.loads(out)
        self.assertEqual({'components': [], 'connections': [], 'resources': []}, out_data)
コード例 #2
0
ファイル: tests.py プロジェクト: shawnchin/hexaviz
    def test_custom_filters_can_be_injected_into_the_template_renderer(self):
        # GIVEN an arbitrary mesh
        m = Mesh()
        m.add_component('My component')
        m.add_component('Another component')

        # WHEN it is rendered using a custom filter
        template = '{% for c in components %}{{c.name|my_filter}};{% endfor %}'
        filters = {'my_filter': lambda s: s.replace('o', '0')}
        out = render(m, template, custom_filters=filters)

        # THEN the output reflects the rendered mesh with the filtes applied
        self.assertEqual('My c0mp0nent;An0ther c0mp0nent;', out)
コード例 #3
0
ファイル: tests.py プロジェクト: shawnchin/hexaviz
    def test_textual_representation_can_be_rendered_for_a_populated_mesh(self):
        # GIVEN the following mesh
        #
        #     _____________              _____________
        #    |      A      |            |      B      |
        #    |-------------|            |-------------|
        #    |      |  n1  |----------->|  p1  |      |
        #    |      |______|            |______|  nY  |----->[ Resource Y ]
        #    |      |  n2  |-----+  +-->|  p2  |      |
        #    |______|______|     |  |   |______|______|
        #                     +- | -+
        #                     |  |
        #     _____________   |  |      _____________
        #    |      C      |  |  |     |      D      |
        #    |-------------|  |  |     |-------------|
        #    |      |  nX  |--+  +---->|  pX  |  nX  |------>[ Resource X ]
        #    |______|______|           |______|______|
        #
        m = Mesh()
        m.add_component('A', needs_ports=['n1', 'n2'])
        m.add_component('B', provides_ports=['p1', 'p2'], needs_ports=['nY'])
        m.add_component('C', needs_ports=['nX'])
        m.add_component('D', provides_ports=['pX'], needs_ports=['nX'])
        m.add_resource('Resource X')
        m.add_resource('Resource Y')

        m.add_connection('A', 'n1', 'B', 'p1')
        m.add_connection('A', 'n2', 'D', 'pX')
        m.add_connection('C', 'nX', 'B', 'p2')
        m.add_connection_to_resource('D', 'nX', 'Resource X')
        m.add_connection_to_resource('B', 'nY', 'Resource Y')

        # WHEN the textual representation is rendered
        out = render(m, self.JSON_TEMPLATE)

        # THEN the rendered output reflects that of the mesh
        out_data = json.loads(out)
        self.assertEqual({
            'components': [
                {'name': 'A', 'needs_ports': ['n1', 'n2'], 'provides_ports': []},
                {'name': 'B', 'needs_ports': ['nY'], 'provides_ports': ['p1', 'p2']},
                {'name': 'C', 'needs_ports': ['nX'], 'provides_ports': []},
                {'name': 'D', 'needs_ports': ['nX'], 'provides_ports': ['pX']},
            ],
            'resources': ['Resource X', 'Resource Y'],
            'connections': [
                {
                    'consumer_component': 'A',
                    'consumer_port': 'n1',
                    'producer_component': 'B',
                    'producer_port': 'p1',
                },
                {
                    'consumer_component': 'A',
                    'consumer_port': 'n2',
                    'producer_component': 'D',
                    'producer_port': 'pX',
                },
                {
                    'consumer_component': 'C',
                    'consumer_port': 'nX',
                    'producer_component': 'B',
                    'producer_port': 'p2',
                },
                {
                    'consumer_component': 'D',
                    'consumer_port': 'nX',
                    'resource': 'Resource X',
                },
                {
                    'consumer_component': 'B',
                    'consumer_port': 'nY',
                    'resource': 'Resource Y',
                },
            ],
        }, out_data)