예제 #1
0
    def test_convert_csv_to_kml_missing_coordinate_fields(self):
        """Tests the convert_csv_to_kml function"""
        from pykml.util import convert_csv_to_kml

        # create a CSV file for testing
        with tempfile.NamedTemporaryFile(mode='wt', suffix='.csv', delete=False) as csvfile:
            csvfile_name = csvfile.name
            csvfile.write('name,snippet,y,x\n')
            csvfile.write('first,The first one,45.0,-90.0\n')
            csvfile.write('second,The second one,46.0,-89.0\n')

        with open(csvfile_name, mode='rt') as csvfile:
            with self.assertRaises(KeyError):
                convert_csv_to_kml(csvfile)

        os.unlink(csvfile_name)
예제 #2
0
    def test_convert_csv_to_kml_missing_coordinate_fields(self):
        """Tests the convert_csv_to_kml function"""
        import tempfile
        from pykml.util import convert_csv_to_kml

        # create a CSV file for testing
        csvfile = tempfile.TemporaryFile()
        csvfile.write('name,snippet,y,x\n')
        csvfile.write('first,The first one,45.0,-90.0\n')
        csvfile.write('second,The second one,46.0,-89.0\n')
        csvfile.seek(0)

        try:
            convert_csv_to_kml(csvfile)
        except KeyError:
            self.assertTrue(True)
        except:
            raise
        finally:
            csvfile.close()
예제 #3
0
파일: test_util.py 프로젝트: 123abcde/pykml
 def test_convert_csv_to_kml_missing_coordinate_fields(self):
     """Tests the convert_csv_to_kml function"""
     import tempfile
     from pykml.util import convert_csv_to_kml
     
     # create a CSV file for testing
     csvfile = tempfile.TemporaryFile()
     csvfile.write('name,snippet,y,x\n')
     csvfile.write('first,The first one,45.0,-90.0\n')
     csvfile.write('second,The second one,46.0,-89.0\n')
     csvfile.seek(0)
     
     try:
         convert_csv_to_kml(csvfile)
     except KeyError:
         self.assertTrue(True)
     except:
         raise
     finally:
         csvfile.close()
예제 #4
0
    def test_convert_csv_to_kml(self):
        """Tests the convert_csv_to_kml function"""
        import tempfile
        from pykml.util import convert_csv_to_kml
        from pykml.util import format_xml_with_cdata

        # create a CSV file for testing
        csvfile = tempfile.TemporaryFile()
        csvfile.write('name,snippet,lat,lon\n')
        csvfile.write('first,The first one,45.0,-90.0\n')
        csvfile.write('second,The second one,46.0,-89.0\n')
        csvfile.write('third,"The third one (with quotes)",45.0,-88.0\n')
        csvfile.seek(0)

        kmldoc = convert_csv_to_kml(csvfile)

        csvfile.close()

        self.assertEqual(
            etree.tostring(format_xml_with_cdata(kmldoc)),
            '<kml xmlns:gx="http://www.google.com/kml/ext/2.2" '
            'xmlns:atom="http://www.w3.org/2005/Atom" '
            'xmlns="http://www.opengis.net/kml/2.2">'
            '<Document>'
            '<Folder>'
            '<name>KmlFile</name>'
            '<Placemark>'
            '<name>first</name>'
            '<Snippet maxLines="2">The first one</Snippet>'
            '<description>'
            '<![CDATA['
            '<table border="1"'
            '<tr><th>snippet</th><td>The first one</td></tr>'
            '<tr><th>lat</th><td>45.0</td></tr>'
            '<tr><th>lon</th><td>-90.0</td></tr>'
            '<tr><th>name</th><td>first</td></tr>'
            '</table>'
            ']]>'
            '</description>'
            '<Point>'
            '<coordinates>-90.0,45.0</coordinates>'
            '</Point>'
            '</Placemark>'
            '<Placemark>'
            '<name>second</name>'
            '<Snippet maxLines="2">The second one</Snippet>'
            '<description><![CDATA[<table border="1"<tr><th>snippet</th><td>The second one</td></tr><tr><th>lat</th><td>46.0</td></tr><tr><th>lon</th><td>-89.0</td></tr><tr><th>name</th><td>second</td></tr></table>]]></description>'
            '<Point>'
            '<coordinates>-89.0,46.0</coordinates>'
            '</Point>'
            '</Placemark>'
            '<Placemark>'
            '<name>third</name>'
            '<Snippet maxLines="2">The third one (with quotes)</Snippet>'
            '<description><![CDATA[<table border="1"<tr><th>snippet</th><td>The third one (with quotes)</td></tr><tr><th>lat</th><td>45.0</td></tr><tr><th>lon</th><td>-88.0</td></tr><tr><th>name</th><td>third</td></tr></table>]]></description>'
            '<Point>'
            '<coordinates>-88.0,45.0</coordinates>'
            '</Point>'
            '</Placemark>'
            '</Folder>'
            '</Document>'
            '</kml>')
예제 #5
0
파일: test_util.py 프로젝트: 123abcde/pykml
 def test_convert_csv_to_kml(self):
     """Tests the convert_csv_to_kml function"""
     import tempfile
     from pykml.util import convert_csv_to_kml
     from pykml.util import format_xml_with_cdata
     
     # create a CSV file for testing
     csvfile = tempfile.TemporaryFile()
     csvfile.write('name,snippet,lat,lon\n')
     csvfile.write('first,The first one,45.0,-90.0\n')
     csvfile.write('second,The second one,46.0,-89.0\n')
     csvfile.write('third,"The third one (with quotes)",45.0,-88.0\n')
     csvfile.seek(0)
     
     kmldoc = convert_csv_to_kml(csvfile)
     
     csvfile.close()
     
     self.assertEqual(
         etree.tostring(format_xml_with_cdata(kmldoc)),
         '<kml xmlns:gx="http://www.google.com/kml/ext/2.2" '
              'xmlns:atom="http://www.w3.org/2005/Atom" '
              'xmlns="http://www.opengis.net/kml/2.2">'
              '<Document>'
                 '<Folder>'
                     '<name>KmlFile</name>'
                     '<Placemark>'
                         '<name>first</name>'
                         '<Snippet maxLines="2">The first one</Snippet>'
                         '<description>'
                             '<![CDATA['
                               '<table border="1"'
                                 '<tr><th>snippet</th><td>The first one</td></tr>'
                                 '<tr><th>lat</th><td>45.0</td></tr>'
                                 '<tr><th>lon</th><td>-90.0</td></tr>'
                                 '<tr><th>name</th><td>first</td></tr>'
                               '</table>'
                             ']]>'
                         '</description>'
                         '<Point>'
                             '<coordinates>-90.0,45.0</coordinates>'
                         '</Point>'
                     '</Placemark>'
                     '<Placemark>'
                         '<name>second</name>'
                         '<Snippet maxLines="2">The second one</Snippet>'
                         '<description><![CDATA[<table border="1"<tr><th>snippet</th><td>The second one</td></tr><tr><th>lat</th><td>46.0</td></tr><tr><th>lon</th><td>-89.0</td></tr><tr><th>name</th><td>second</td></tr></table>]]></description>'
                         '<Point>'
                             '<coordinates>-89.0,46.0</coordinates>'
                         '</Point>'
                     '</Placemark>'
                     '<Placemark>'
                         '<name>third</name>'
                         '<Snippet maxLines="2">The third one (with quotes)</Snippet>'
                         '<description><![CDATA[<table border="1"<tr><th>snippet</th><td>The third one (with quotes)</td></tr><tr><th>lat</th><td>45.0</td></tr><tr><th>lon</th><td>-88.0</td></tr><tr><th>name</th><td>third</td></tr></table>]]></description>'
                         '<Point>'
                             '<coordinates>-88.0,45.0</coordinates>'
                         '</Point>'
                     '</Placemark>'
                 '</Folder>'
             '</Document>'
         '</kml>'
     )
예제 #6
0
    def test_convert_csv_to_kml(self):
        """Tests the convert_csv_to_kml function"""
        import tempfile
        from pykml.util import convert_csv_to_kml
        from pykml.util import format_xml_with_cdata

        # create a CSV file for testing
        with tempfile.NamedTemporaryFile(mode='wt', suffix='.csv', delete=False) as csvfile:
            csvfile_name = csvfile.name
            csvfile.write('name,snippet,lat,lon\n')
            csvfile.write('first,The first one,45.0,-90.0\n')
            csvfile.write('second,The second one,46.0,-89.0\n')
            csvfile.write('third,"The third one (with quotes)",45.0,-88.0\n')

        with open(csvfile_name, 'rt') as csvfile:
            kmldoc = convert_csv_to_kml(csvfile)

        os.unlink(csvfile_name)

        root = format_xml_with_cdata(kmldoc)

        data = etree.tostring(root, encoding='utf-8', xml_declaration=True)
        expected = \
            '<?xml version="1.0" encoding="UTF-8"?>' \
            '<kml xmlns="http://www.opengis.net/kml/2.2" ' \
            'xmlns:atom="http://www.w3.org/2005/Atom" ' \
            'xmlns:gx="http://www.google.com/kml/ext/2.2">' \
            '<Document>' \
            '<Folder>' \
            '<name>KmlFile</name>' \
            '<Placemark>' \
            '<name>first</name>' \
            '<Snippet maxLines="2">The first one</Snippet>' \
            '<description><![CDATA[<table border="1"' \
            '<tr><th>name</th><td>first</td></tr>' \
            '<tr><th>snippet</th><td>The first one</td></tr>' \
            '<tr><th>lat</th><td>45.0</td></tr>' \
            '<tr><th>lon</th><td>-90.0</td></tr>' \
            '</table>]]></description>' \
            '<Point>' \
            '<coordinates>-90.0,45.0</coordinates>' \
            '</Point>' \
            '</Placemark>' \
            '<Placemark>' \
            '<name>second</name>' \
            '<Snippet maxLines="2">The second one</Snippet>' \
            '<description><![CDATA[<table border="1"' \
            '<tr><th>name</th><td>second</td></tr>' \
            '<tr><th>snippet</th><td>The second one</td></tr>' \
            '<tr><th>lat</th><td>46.0</td></tr>' \
            '<tr><th>lon</th><td>-89.0</td></tr>' \
            '</table>]]></description>' \
            '<Point>' \
            '<coordinates>-89.0,46.0</coordinates>' \
            '</Point>' \
            '</Placemark>' \
            '<Placemark>' \
            '<name>third</name>' \
            '<Snippet maxLines="2">The third one (with quotes)</Snippet>' \
            '<description><![CDATA[<table border="1"' \
            '<tr><th>name</th><td>third</td></tr>' \
            '<tr><th>snippet</th><td>The third one (with quotes)</td></tr>' \
            '<tr><th>lat</th><td>45.0</td></tr>' \
            '<tr><th>lon</th><td>-88.0</td></tr>' \
            '</table>]]></description>' \
            '<Point>' \
            '<coordinates>-88.0,45.0</coordinates>' \
            '</Point>' \
            '</Placemark>' \
            '</Folder>' \
            '</Document>' \
            '</kml>'
        expected = expected.encode('utf-8')

        self.assertXmlEquivalentOutputs(data, expected)