Beispiel #1
0
    def test_compression(self):
        """Test compression"""

        xmloutput = tempfile.NamedTemporaryFile(delete=False)

        writer = changewriter.OSMChangeWriter(filename=xmloutput.name,
                                              compress=True)
        objects_to_test = test_objects  # just test way
        writer.add_create(objects_to_test)
        writer.close()

        parsed = etree.parse(GzipFile(xmloutput.name, "r"))
        parsedRoot = parsed.getroot()
        self.assertTrue(parsedRoot.tag == "osmChange")
        xmloutput.close()
Beispiel #2
0
    def test_close(self):
        """Ensure close() function correctly adds osmChange tags"""
        with tempfile.NamedTemporaryFile(delete=False) as of:
            writer = changewriter.OSMChangeWriter(filename=of.name)
            objects_to_test = test_objects  # just test way
            writer.add_create(objects_to_test)
            writer.close()

            _of = open(of.name, "rb")
            parsed = etree.parse(_of)
            _of.close()
            parsedRoot = parsed.getroot()
            self.assertTrue(parsedRoot.tag == "osmChange")
            self.assertTrue(parsedRoot[0].tag == "create")
            of.close()
Beispiel #3
0
    def test_write_file(self):
        """Ensure that providing a filename to OSMChangeWriter produces a file"""
        with tempfile.NamedTemporaryFile(delete=False) as of:
            writer = changewriter.OSMChangeWriter(filename=of.name)
            objects_to_test = test_objects  # just test way
            writer.add_create(objects_to_test)
            writer.close()
            with open(of.name, "r") as f:
                f.seek(0)
                parsed = etree.parse(f)
                parsedRoot = parsed.getroot()
                parsedElements = list(parsedRoot[0])

                self.assertTrue(parsedRoot[0].tag == "create")
                self.assertTrue(len(parsedElements) == len(objects_to_test))
            of.close()
Beispiel #4
0
    def test_create_multiple(self):
        """Ensure a multiple modify nodes are written correctly"""

        xmloutput = tempfile.NamedTemporaryFile(delete=False)
        writer = changewriter.OSMChangeWriter(filename=xmloutput.name)
        objects_to_test = test_objects  # just test way
        writer.add_create(objects_to_test)
        writer.close()
        _of = open(xmloutput.name, "rb")
        parsed = etree.parse(_of)
        _of.close()
        parsedRoot = parsed.getroot()
        parsedElements = list(parsedRoot[0])
        self.assertTrue(parsedRoot[0].tag == "create")
        self.assertTrue(len(parsedElements) == len(objects_to_test))

        xmloutput.close()
        os.remove(xmloutput.name)
Beispiel #5
0
    def test_modify_way(self):
        """Ensure a single modify way is written correctly"""
        xmloutput = tempfile.NamedTemporaryFile(delete=False)
        writer = changewriter.OSMChangeWriter(filename=xmloutput.name)
        objects_to_test = [test_objects[1]]  # just test way
        writer.add_modify(objects_to_test)
        writer.close()
        _of = open(xmloutput.name, "rb")
        parsed = etree.parse(_of)
        _of.close()
        parsedRoot = parsed.getroot()
        parsedElements = list(parsedRoot[0])
        parsedTags = parsed.xpath("/osmChange/modify/way/tag")

        self.assertTrue(parsedRoot[0].tag == "modify")
        self.assertTrue(parsedElements[0].tag == "way")
        self.assertTrue(len(parsedElements) == len(objects_to_test))
        self.assertTrue(
            set(parsedElements[0].keys()) == set(["id", "version"]))
        self.assertTrue(len(parsedTags) == len(test_objects[0].tags))

        xmloutput.close()
        os.remove(xmloutput.name)