|
@@ -25,6 +25,22 @@ INPUT_DOUBLEQUOTES = """Id,POINT_X,POINT_Y,Category,"ED field estimate"
|
|
|
107,450833.019732,4048207.02664,"High Erosion","Low Erosion"
|
|
|
"""
|
|
|
|
|
|
+INPUT_TSV = """Id\tPOINT_X\tPOINT_Y\tCategory\t"ED field estimate"
|
|
|
+100\t437343.6704\t4061363.41525\t"High Erosion"\t"Low Deposition"
|
|
|
+101\t453643.127906\t4050070.29852\t"High Erosion"\t"Low Erosion"
|
|
|
+102\t454903.605427\t4049480.80568\t"High Erosion"\t"High Erosion"
|
|
|
+105\t437734.838807\t4060493.98315\t"High Erosion"\t"Low Erosion"
|
|
|
+107\t450833.019732\t4048207.02664\t"High Erosion"\t"Low Erosion"
|
|
|
+"""
|
|
|
+
|
|
|
+INPUT_UNCOMMON = """Id@POINT_X@POINT_Y@Category@^ED field estimate^
|
|
|
+100@437343.6704@4061363.41525@^High Erosion^@^Low Deposition^
|
|
|
+101@453643.127906@4050070.29852@^High Erosion^@^Low Erosion^
|
|
|
+102@454903.605427@4049480.80568@^High Erosion^@^High Erosion^
|
|
|
+105@437734.838807@4060493.98315@^High Erosion^@^Low Erosion^
|
|
|
+107@450833.019732@4048207.02664@^High Erosion^@^Low Erosion^
|
|
|
+"""
|
|
|
+
|
|
|
TABLE_1 = """cat|x|y|ed_cat|field_estimate
|
|
|
100|437343.6704|4061363.41525|High Erosion|Low Deposition
|
|
|
101|453643.127906|4050070.29852|High Erosion|Low Erosion
|
|
@@ -56,7 +72,7 @@ class SimpleCsvTestCase(TestCase):
|
|
|
separator='pipe')
|
|
|
self.assertEqual(first=TABLE_1.replace('\n', os.linesep),
|
|
|
second=category,
|
|
|
- msg="Labels do not match")
|
|
|
+ msg="Attribute table has wrong entries")
|
|
|
|
|
|
def test_text_delimeter(self):
|
|
|
"""Test loading CSV with delimiter
|
|
@@ -65,7 +81,8 @@ class SimpleCsvTestCase(TestCase):
|
|
|
"""
|
|
|
self.assertModule(
|
|
|
'v.in.ascii', input='-', output=self.xyvector,
|
|
|
- separator='comma', skip=1, x=2, y=3, cat=1,
|
|
|
+ separator='comma', text='doublequote',
|
|
|
+ skip=1, x=2, y=3, cat=1,
|
|
|
columns="cat int, x double, y double,"
|
|
|
" ed_cat varchar(20), field_estimate varchar(20)",
|
|
|
stdin_=INPUT_DOUBLEQUOTES)
|
|
@@ -79,6 +96,41 @@ class SimpleCsvTestCase(TestCase):
|
|
|
# TODO: standardize string strip? perhaps discourage, it messes up the diff
|
|
|
# TODO: use replace solution for newlines in lib (compare to current one)
|
|
|
|
|
|
+ def test_tsv(self):
|
|
|
+ """Test loading TSV (CSV with tab as delim)
|
|
|
+
|
|
|
+ Using double quote character for quote.
|
|
|
+ """
|
|
|
+ self.assertModule(
|
|
|
+ 'v.in.ascii', input='-', output=self.xyvector,
|
|
|
+ separator='tab', text='"',
|
|
|
+ skip=1, x=2, y=3, cat=1,
|
|
|
+ columns="cat int, x double, y double,"
|
|
|
+ " ed_cat varchar(20), field_estimate varchar(20)",
|
|
|
+ stdin_=INPUT_TSV)
|
|
|
+
|
|
|
+ category = read_command('v.db.select', map=self.xyvector,
|
|
|
+ separator='pipe')
|
|
|
+ self.assertEqual(first=TABLE_1.replace('\n', os.linesep),
|
|
|
+ second=category,
|
|
|
+ msg="Attribute table has wrong entries")
|
|
|
+
|
|
|
+ def test_uncommon_delims(self):
|
|
|
+ """Test loading CSV with uncommon delimiters"""
|
|
|
+ self.assertModule(
|
|
|
+ 'v.in.ascii', input='-', output=self.xyvector,
|
|
|
+ separator='@', text='^',
|
|
|
+ skip=1, x=2, y=3, cat=1,
|
|
|
+ columns="cat int, x double, y double,"
|
|
|
+ " ed_cat varchar(20), field_estimate varchar(20)",
|
|
|
+ stdin_=INPUT_UNCOMMON)
|
|
|
+
|
|
|
+ category = read_command('v.db.select', map=self.xyvector,
|
|
|
+ separator='pipe')
|
|
|
+ self.assertEqual(first=TABLE_1.replace('\n', os.linesep),
|
|
|
+ second=category,
|
|
|
+ msg="Attribute table has wrong entries")
|
|
|
+
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
test()
|