예제 #1
0
파일: test_osm.py 프로젝트: encukou/upoints
class TestWay(TestCase):
    def setUp(self):
        self.bare = Way(0, (0, 1, 2))
        self.named = Way(0, (0, 1, 2), True, 'jnrowe',
                         utils.Timestamp(2008, 1, 25))
        self.tagged = Way(0, (0, 1, 2), tags={'key': 'value'})

    def test___repr__(self):
        expect(repr(self.bare)) == 'Way(0, [0, 1, 2], False, None, None, None)'
        expect(repr(self.named)) == \
            ("Way(0, [0, 1, 2], True, 'jnrowe', Timestamp(2008, 1, 25, 0, 0), "
             'None)')
        expect(repr(self.tagged)) == \
            "Way(0, [0, 1, 2], False, None, None, {'key': 'value'})"

    def test___str__(self):
        expect(str(self.bare)) == 'Way 0 (nodes: 0, 1, 2)'
        expect(str(self.named)) == \
            ('Way 0 (nodes: 0, 1, 2) [visible, user: jnrowe, timestamp: '
             '2008-01-25T00:00:00+00:00]')
        expect(str(self.tagged)) == 'Way 0 (nodes: 0, 1, 2) [key: value]'
        nodes = [
            Node(0, 52.015749, -0.221765, True, 'jnrowe',
                 utils.Timestamp(2008, 1, 25, 12, 52, 11), None),
            Node(1, 52.015761, -0.221767, True, None,
                 utils.Timestamp(2008, 1, 25, 12, 53, 14),
                 {'created_by': 'hand', 'highway': 'crossing'}),
            Node(2, 52.015754, -0.221766, True, 'jnrowe',
                 utils.Timestamp(2008, 1, 25, 12, 52, 30),
                 {'amenity': 'pub'}),
        ]
        data = self.tagged.__str__(nodes).splitlines()
        expect(data[0]) == 'Way 0 [key: value]'
        expect(data[1]) == \
            ("""    Node 0 (52°00'56"N, 000°13'18"W) [visible, user: """
             'jnrowe, timestamp: 2008-01-25T12:52:11+00:00]')
        expect(data[2]) == \
            ("""    Node 1 (52°00'56"N, 000°13'18"W) [visible, timestamp: """
             '2008-01-25T12:53:14+00:00, created_by: hand, highway: crossing]')
        expect(data[3]) == \
            ("""    Node 2 (52°00'56"N, 000°13'18"W) [visible, user: """
             'jnrowe, timestamp: 2008-01-25T12:52:30+00:00, amenity: pub]')

    def test_toosm(self):
        xml_str_compare(
            '<way id="0" visible="false"><nd ref="0"/><nd ref="1"/><nd ref="2"/></way>',
            etree.tostring(self.bare.toosm())
        )
        xml_str_compare(
            '<way id="0" timestamp="2008-01-25T00:00:00+00:00" user="******" visible="true"><nd ref="0"/><nd ref="1"/><nd ref="2"/></way>',
            etree.tostring(self.named.toosm()))
        xml_str_compare(
            '<way id="0" visible="false"><tag k="key" v="value"/><nd ref="0"/><nd ref="1"/><nd ref="2"/></way>',
            etree.tostring(self.tagged.toosm()))
예제 #2
0
파일: test_osm.py 프로젝트: JNRowe/upoints
 def setup(self):
     self.bare = Way(0, (0, 1, 2))
     self.named = Way(0, (0, 1, 2), True, 'jnrowe',
                      utils.Timestamp(2008, 1, 25))
     self.tagged = Way(0, (0, 1, 2), tags={'key': 'value'})
예제 #3
0
파일: test_osm.py 프로젝트: JNRowe/upoints
class TestWay:
    def setup(self):
        self.bare = Way(0, (0, 1, 2))
        self.named = Way(0, (0, 1, 2), True, 'jnrowe',
                         utils.Timestamp(2008, 1, 25))
        self.tagged = Way(0, (0, 1, 2), tags={'key': 'value'})

    @mark.parametrize('node, result', [
        ('bare', 'Way(0, [0, 1, 2], False, None, None, None)'),
        ('named',
         "Way(0, [0, 1, 2], True, 'jnrowe', Timestamp(2008, 1, 25, 0, 0), "
         "None)"),
        ('tagged', "Way(0, [0, 1, 2], False, None, None, {'key': 'value'})"),
    ])
    def test___repr__(self, node, result):
        assert repr(getattr(self, node)) == result

    @mark.parametrize('node, result', [
        ('bare', 'Way 0 (nodes: 0, 1, 2)'),
        ('named',
         'Way 0 (nodes: 0, 1, 2) [visible, user: jnrowe, timestamp: '
         '2008-01-25T00:00:00+00:00]'),
        ('tagged', 'Way 0 (nodes: 0, 1, 2) [key: value]'),
    ])
    def test___str__(self, node, result):
        assert str(getattr(self, node)) == result

    def test___str___list(self):
        nodes = [
            Node(0, 52.015749, -0.221765, True, 'jnrowe',
                 utils.Timestamp(2008, 1, 25, 12, 52, 11), None),
            Node(1, 52.015761, -0.221767, True, None,
                 utils.Timestamp(2008, 1, 25, 12, 53, 14),
                 {'created_by': 'hand', 'highway': 'crossing'}),
            Node(2, 52.015754, -0.221766, True, 'jnrowe',
                 utils.Timestamp(2008, 1, 25, 12, 52, 30),
                 {'amenity': 'pub'}),
        ]
        assert self.tagged.__str__(nodes).splitlines() == [
            'Way 0 [key: value]',
            """    Node 0 (52°00'56"N, 000°13'18"W) [visible, user: """
            'jnrowe, timestamp: 2008-01-25T12:52:11+00:00]',
            """    Node 1 (52°00'56"N, 000°13'18"W) [visible, timestamp: """
            '2008-01-25T12:53:14+00:00, created_by: hand, highway: crossing]',
            """    Node 2 (52°00'56"N, 000°13'18"W) [visible, user: """
            'jnrowe, timestamp: 2008-01-25T12:52:30+00:00, amenity: pub]',
        ]

    @mark.parametrize('node, result', [
        ('bare',
         '<way id="0" visible="false">'
         '<nd ref="0"/><nd ref="1"/><nd ref="2"/>'
         '</way>'),
        ('named',
         '<way id="0" timestamp="2008-01-25T00:00:00+00:00" user="******" '
         'visible="true">'
         '<nd ref="0"/><nd ref="1"/><nd ref="2"/>'
         '</way>'),
        ('tagged',
         '<way id="0" visible="false">'
         '<tag k="key" v="value"/>'
         '<nd ref="0"/><nd ref="1"/><nd ref="2"/>'
         '</way>'),
    ])
    def test_toosm(self, node, result):
        xml_str_compare(result, etree.tostring(getattr(self, node).toosm()))