示例#1
0
    def test_geojson_with_id(self):
        args = [
            '--lat', 'latitude', '--lon', 'longitude', '-k', 'slug',
            'examples/test_geo.csv'
        ]
        output_file = StringIO()

        utility = CSVJSON(args, output_file)
        utility.main()

        geojson = json.loads(output_file.getvalue())

        self.assertEqual(geojson['type'], 'FeatureCollection')
        self.assertFalse('crs' in geojson)
        self.assertEqual(
            geojson['bbox'],
            [-95.334619, 32.299076986939205, -95.250699, 32.351434])
        self.assertEqual(len(geojson['features']), 17)

        for feature in geojson['features']:
            self.assertEqual(feature['type'], 'Feature')
            self.assertTrue('id' in feature)
            self.assertEqual(len(feature['properties']), 9)

            geometry = feature['geometry']

            self.assertEqual(len(geometry['coordinates']), 2)
            self.assertTrue(isinstance(geometry['coordinates'][0], float))
            self.assertTrue(isinstance(geometry['coordinates'][1], float))
示例#2
0
    def test_keying(self):
        args = ['-k', 'a', 'examples/dummy.csv']
        output_file = StringIO()
        
        utility = CSVJSON(args, output_file)
        utility.main()

        self.assertEqual(output_file.getvalue(), '{"1": {"a": "1", "c": "3", "b": "2"}}')
示例#3
0
    def test_indentation(self):
        args = ['-i', '4', 'examples/dummy.csv']
        output_file = StringIO()

        utility = CSVJSON(args, output_file)
        utility.main()

        self.assertEqual(output_file.getvalue(), '[\n    {\n        "a": "1", \n        "c": "3", \n        "b": "2"\n    }\n]')
示例#4
0
    def test_simple(self):
        args = ['examples/dummy.csv']
        output_file = StringIO()

        utility = CSVJSON(args, output_file)
        utility.main()

        self.assertEqual(output_file.getvalue(), '[{"a": "1", "c": "3", "b": "2"}]')
示例#5
0
    def test_keying(self):
        args = ['-k', 'a', 'examples/dummy.csv']
        output_file = StringIO()

        utility = CSVJSON(args, output_file)
        utility.main()

        self.assertEqual(output_file.getvalue(),
                         '{"1": {"a": "1", "c": "3", "b": "2"}}')
示例#6
0
    def test_simple(self):
        args = ['examples/dummy.csv']
        output_file = StringIO()

        utility = CSVJSON(args, output_file)
        utility.main()

        self.assertEqual(output_file.getvalue(),
                         '[{"a": "1", "c": "3", "b": "2"}]')
示例#7
0
    def test_keying(self):
        args = ['-k', 'a', 'examples/dummy.csv']
        output_file = six.StringIO()

        utility = CSVJSON(args, output_file)
        utility.main()

        js = json.loads(output_file.getvalue())

        self.assertDictEqual(js, {"1": {"a": "1", "c": "3", "b": "2"}})
示例#8
0
    def test_indentation(self):
        args = ['-i', '4', 'examples/dummy.csv']
        output_file = six.StringIO()

        utility = CSVJSON(args, output_file)
        utility.main()

        js = json.loads(output_file.getvalue())

        self.assertDictEqual(js[0], {"a": "1", "c": "3", "b": "2"})
示例#9
0
    def test_json_streaming(self):
        args = ['--stream', 'examples/dummy3.csv']
        output_file = six.StringIO()

        utility = CSVJSON(args, output_file)
        utility.main()

        result = list(map(json.loads, output_file.getvalue().splitlines()))
        self.assertEqual(len(result), 2)
        self.assertDictEqual(result[0], {"a": "1", "c": "3", "b": "2"})
        self.assertDictEqual(result[1], {"a": "1", "c": "5", "b": "4"})
示例#10
0
    def test_indentation(self):
        args = ['-i', '4', 'examples/dummy.csv']
        output_file = StringIO()

        utility = CSVJSON(args, output_file)
        utility.main()

        self.assertEqual(
            output_file.getvalue(),
            '[\n    {\n        "a": "1", \n        "c": "3", \n        "b": "2"\n    }\n]'
        )
示例#11
0
    def test_geojson_with_crs(self):
        args = ['--lat', 'latitude', '--lon', 'longitude', '--crs', 'EPSG:4269', 'examples/test_geo.csv']
        output_file = six.StringIO()

        utility = CSVJSON(args, output_file)
        utility.main()

        geojson = json.loads(output_file.getvalue())

        self.assertEqual(geojson['type'], 'FeatureCollection')
        self.assertTrue('crs' in geojson)
        self.assertEqual(geojson['bbox'], [-95.334619, 32.299076986939205, -95.250699, 32.351434])
        self.assertEqual(len(geojson['features']), 17)

        crs = geojson['crs']

        self.assertEqual(crs['type'], 'name')
        self.assertEqual(crs['properties']['name'], 'EPSG:4269')
示例#12
0
    def test_geojson_with_crs(self):
        args = ["--lat", "latitude", "--lon", "longitude", "--crs", "EPSG:4269", "examples/test_geo.csv"]
        output_file = six.StringIO()

        utility = CSVJSON(args, output_file)
        utility.main()

        geojson = json.loads(output_file.getvalue())

        self.assertEqual(geojson["type"], "FeatureCollection")
        self.assertTrue("crs" in geojson)
        self.assertEqual(geojson["bbox"], [-95.334619, 32.299076986939205, -95.250699, 32.351434])
        self.assertEqual(len(geojson["features"]), 17)

        crs = geojson["crs"]

        self.assertEqual(crs["type"], "name")
        self.assertEqual(crs["properties"]["name"], "EPSG:4269")
示例#13
0
    def test_geojson_with_id(self):
        args = ['--lat', 'latitude', '--lon', 'longitude', '-k', 'slug', 'examples/test_geo.csv']
        output_file = six.StringIO()

        utility = CSVJSON(args, output_file)
        utility.main()

        geojson = json.loads(output_file.getvalue())

        self.assertEqual(geojson['type'], 'FeatureCollection')
        self.assertFalse('crs' in geojson)
        self.assertEqual(geojson['bbox'], [-95.334619, 32.299076986939205, -95.250699, 32.351434])
        self.assertEqual(len(geojson['features']), 17)

        for feature in geojson['features']:
            self.assertEqual(feature['type'], 'Feature')
            self.assertTrue('id' in feature)
            self.assertEqual(len(feature['properties']), 9)

            geometry = feature['geometry']

            self.assertEqual(len(geometry['coordinates']), 2)
            self.assertTrue(isinstance(geometry['coordinates'][0], float))
            self.assertTrue(isinstance(geometry['coordinates'][1], float))
示例#14
0
    def test_geojson_with_id(self):
        args = ["--lat", "latitude", "--lon", "longitude", "-k", "slug", "examples/test_geo.csv"]
        output_file = six.StringIO()

        utility = CSVJSON(args, output_file)
        utility.main()

        geojson = json.loads(output_file.getvalue())

        self.assertEqual(geojson["type"], "FeatureCollection")
        self.assertFalse("crs" in geojson)
        self.assertEqual(geojson["bbox"], [-95.334619, 32.299076986939205, -95.250699, 32.351434])
        self.assertEqual(len(geojson["features"]), 17)

        for feature in geojson["features"]:
            self.assertEqual(feature["type"], "Feature")
            self.assertTrue("id" in feature)
            self.assertEqual(len(feature["properties"]), 9)

            geometry = feature["geometry"]

            self.assertEqual(len(geometry["coordinates"]), 2)
            self.assertTrue(isinstance(geometry["coordinates"][0], float))
            self.assertTrue(isinstance(geometry["coordinates"][1], float))