Ejemplo n.º 1
0
    def test_create_region(self,get_g):
        from lxml import etree
        xml = """ <region id='a' name='test_region'/> """
        tree = etree.parse(StringIO(xml))
        r_node = tree.getroot()
        r = Region(r_node)
        self.assertEqual(r.get_name(), 'test_region')
        self.assertEqual(r.get_resolution(), None)
        r.set_resolution(1)
        self.assertEqual(r.get_resolution(), 1)

        xml = """ <region id='a' name='test_region@test_mapset'/> """
        tree = etree.parse(StringIO(xml))
        r_node = tree.getroot()
        r = Region(r_node)
        self.assertEqual(r.get_name(), 'test_region')
        self.assertEqual(r.get_mapset(), 'test_mapset')

        xml = """ <region id='a'></region> """
        tree = etree.parse(StringIO(xml))
        r_node = tree.getroot()
        r = Region(r_node)
        self.assertEqual(r.get_resolution(), 1)
        self.assertEqual(r.get_name(), None)
        xml = """ <region id='a'><resolution>1</resolution></region> """
        tree = etree.parse(StringIO(xml))
        r_node = tree.getroot()
        r = Region(r_node)
        self.assertEqual(r.get_resolution(), 1)
        self.assertEqual(r.get_name(), None)
        xml = """ <region id='a'><resolution>201</resolution></region> """
        tree = etree.parse(StringIO(xml))
        r_node = tree.getroot()
        r = Region(r_node)
        self.assertEqual(r.get_resolution(), 201)
        self.assertEqual(r.get_name(), None)
        xml = """ <region id='a'><resolution>flibble</resolution></region> """
        tree = etree.parse(StringIO(xml))
        r_node = tree.getroot()
        r = Region(r_node)
        self.assertRaises(ValueError,r.get_resolution)
        self.assertEqual(r.get_name(), None)

        r.set_name('test_region')
        self.assertEqual(r.get_name(), 'test_region')

        r.set_resolution(1)
        self.assertEqual(r.get_resolution(), 1)
        self.assertRaises(ValueError,r.set_resolution,'fox')