Skip to content

Commit d325289

Browse files
committed
Code formatting with Black
1 parent 170273c commit d325289

13 files changed

+52
-28
lines changed

clevercsv/consistency.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .detect_type import type_score
1414
from .potential_dialects import get_dialects
1515

16+
1617
def detect_dialect_consistency(data, delimiters=None, verbose=False):
1718
"""Detect the dialect with the data consistency measure
1819
@@ -55,10 +56,7 @@ def detect_dialect_consistency(data, delimiters=None, verbose=False):
5556
for dialect in sorted(dialects):
5657
P = pattern_score(data, dialect)
5758
if P < Qmax:
58-
log(
59-
"%15r:\tP = %15.6f\tskip."
60-
% (dialect, P)
61-
)
59+
log("%15r:\tP = %15.6f\tskip." % (dialect, P))
6260
continue
6361
T = type_score(data, dialect)
6462
Q = P * T

clevercsv/console/commands/detect.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ def handle(self):
3737
self.line(f"quotechar = {dialect.quotechar}".strip())
3838
self.line(f"escapechar = {dialect.escapechar}".strip())
3939
else:
40-
self.line('Detected: ' + str(dialect))
40+
self.line("Detected: " + str(dialect))

clevercsv/cparser_util.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
_FIELD_SIZE_LIMIT = 128 * 1024
1515

16+
1617
def field_size_limit(*args, **kwargs):
1718
"""Get/Set the limit to the field size.
1819

clevercsv/detect_type.py

-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ def is_unix_path(self, cell):
249249
return self._run_regex(cell, "unix_path")
250250

251251

252-
253252
def gen_known_type(cells):
254253
"""
255254
Utility that yields a generator over whether or not the provided cells are

clevercsv/dialect.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __eq__(self, other):
120120
return self.__key() == other.__key()
121121

122122
def __lt__(self, other):
123-
# This provides a partial order on dialect objects with the goal of
123+
# This provides a partial order on dialect objects with the goal of
124124
# speeding up the consistency measure.
125125
if not isinstance(other, SimpleDialect):
126126
return False

clevercsv/escape.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,20 @@ def is_potential_escapechar(char, encoding, block_char=None):
4343

4444
ctr = unicodedata.category(as_unicode)
4545
if block_char is None:
46-
block_char = ["!", "?", '"', "'", ".", ",", ";", ":", "%", "*", "&",
47-
"#"]
46+
block_char = [
47+
"!",
48+
"?",
49+
'"',
50+
"'",
51+
".",
52+
",",
53+
";",
54+
":",
55+
"%",
56+
"*",
57+
"&",
58+
"#",
59+
]
4860
if ctr == "Po":
4961
if as_unicode in block_char:
5062
return False

clevercsv/exceptions.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
from .cparser import Error as ParserError
1111

12+
1213
class Error(ParserError):
1314
pass
1415

16+
1517
class NoDetectionResult(Exception):
1618
pass

clevercsv/read.py

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .dialect import SimpleDialect
1616
from .exceptions import Error
1717

18+
1819
class reader(object):
1920
def __init__(self, csvfile, dialect="excel", **fmtparams):
2021
self.csvfile = csvfile

tests/test_unit/test_detect.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,16 @@ def test_delimiters(self):
103103
def test_has_header(self):
104104
detector = Detector()
105105
self.assertEqual(detector.has_header(self.sample1), False)
106-
self.assertEqual(detector.has_header(self.header1 + self.sample1),
107-
True)
106+
self.assertEqual(
107+
detector.has_header(self.header1 + self.sample1), True
108+
)
108109

109110
def test_has_header_regex_special_delimiter(self):
110111
detector = Detector()
111112
self.assertEqual(detector.has_header(self.sample8), False)
112-
self.assertEqual(detector.has_header(self.header2 + self.sample8),
113-
True)
113+
self.assertEqual(
114+
detector.has_header(self.header2 + self.sample8), True
115+
)
114116

115117

116118
if __name__ == "__main__":

tests/test_unit/test_detect_pattern.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def test_abstraction_1(self):
2828

2929
def test_abstraction_2(self):
3030
out = detect_pattern.make_abstraction(
31-
"A,\rA,A,A\r", SimpleDialect(delimiter=",", quotechar="", escapechar="")
31+
"A,\rA,A,A\r",
32+
SimpleDialect(delimiter=",", quotechar="", escapechar=""),
3233
)
3334
exp = "CDCRCDCDC"
3435
self.assertEqual(exp, out)
@@ -73,7 +74,8 @@ def test_abstraction_7(self):
7374

7475
def test_abstraction_8(self):
7576
out = detect_pattern.make_abstraction(
76-
',"",,\r\n', SimpleDialect(delimiter=",", quotechar='"', escapechar="")
77+
',"",,\r\n',
78+
SimpleDialect(delimiter=",", quotechar='"', escapechar=""),
7779
)
7880
exp = "CDCDCDC"
7981
self.assertEqual(exp, out)
@@ -84,42 +86,48 @@ def test_abstraction_8(self):
8486

8587
def test_abstraction_9(self):
8688
out = detect_pattern.make_abstraction(
87-
"A,B|,C", SimpleDialect(delimiter=",", quotechar="", escapechar="|")
89+
"A,B|,C",
90+
SimpleDialect(delimiter=",", quotechar="", escapechar="|"),
8891
)
8992
exp = "CDC"
9093
self.assertEqual(exp, out)
9194

9295
def test_abstraction_10(self):
9396
out = detect_pattern.make_abstraction(
94-
'A,"B,C|"D"', SimpleDialect(delimiter=",", quotechar='"', escapechar="|")
97+
'A,"B,C|"D"',
98+
SimpleDialect(delimiter=",", quotechar='"', escapechar="|"),
9599
)
96100
exp = "CDC"
97101
self.assertEqual(exp, out)
98102

99103
def test_abstraction_11(self):
100104
out = detect_pattern.make_abstraction(
101-
"a,|b,c", SimpleDialect(delimiter=",", quotechar="", escapechar="|")
105+
"a,|b,c",
106+
SimpleDialect(delimiter=",", quotechar="", escapechar="|"),
102107
)
103108
exp = "CDCDC"
104109
self.assertEqual(exp, out)
105110

106111
def test_abstraction_12(self):
107112
out = detect_pattern.make_abstraction(
108-
"a,b|,c", SimpleDialect(delimiter=",", quotechar="", escapechar="|")
113+
"a,b|,c",
114+
SimpleDialect(delimiter=",", quotechar="", escapechar="|"),
109115
)
110116
exp = "CDC"
111117
self.assertEqual(exp, out)
112118

113119
def test_abstraction_13(self):
114120
out = detect_pattern.make_abstraction(
115-
'a,"b,c|""', SimpleDialect(delimiter=",", quotechar='"', escapechar="|")
121+
'a,"b,c|""',
122+
SimpleDialect(delimiter=",", quotechar='"', escapechar="|"),
116123
)
117124
exp = "CDC"
118125
self.assertEqual(exp, out)
119126

120127
def test_abstraction_14(self):
121128
out = detect_pattern.make_abstraction(
122-
"a,b||c", SimpleDialect(delimiter=",", quotechar="", escapechar="|")
129+
"a,b||c",
130+
SimpleDialect(delimiter=",", quotechar="", escapechar="|"),
123131
)
124132
exp = "CDC"
125133
self.assertEqual(exp, out)

tests/test_unit/test_normal_forms.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_form_2(self):
5050
self.assertFalse(is_form_2('a,"",3\n1,2,3', dialect))
5151

5252
def test_form_3(self):
53-
A = SimpleDialect(delimiter=',', quotechar="'", escapechar="")
53+
A = SimpleDialect(delimiter=",", quotechar="'", escapechar="")
5454
Q = SimpleDialect(delimiter=",", quotechar='"', escapechar="")
5555

5656
self.assertTrue(is_form_3('A,B\nC,"D"', Q))
@@ -59,9 +59,8 @@ def test_form_3(self):
5959
self.assertFalse(is_form_3('A,\nC,"d,e"', Q))
6060
self.assertFalse(is_form_3("3;4,B\nC,D", Q))
6161

62-
self.assertFalse(is_form_3("A,B\n\"C\",D\n", A))
63-
self.assertTrue(is_form_3("A,B\n\"C\",D\n", Q))
64-
62+
self.assertFalse(is_form_3('A,B\n"C",D\n', A))
63+
self.assertTrue(is_form_3('A,B\n"C",D\n', Q))
6564

6665
def test_form_4(self):
6766
quoted = SimpleDialect(delimiter="", quotechar='"', escapechar="")
@@ -90,5 +89,6 @@ def test_form_5(self):
9089
self.assertFalse(is_form_5("A,B\n1,\n2,3", dialect))
9190
self.assertFalse(is_form_5('"A,""B"""\n"1,"\n"2,3"', dialect))
9291

93-
if __name__ == '__main__':
92+
93+
if __name__ == "__main__":
9494
unittest.main()

tests/test_unit/test_potential_dialects.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ def test_get_delimiters(self):
4141
out = get_delimiters(data, "UTF-8")
4242
self.assertEqual(out, exp)
4343

44-
if __name__ == '__main__':
44+
45+
if __name__ == "__main__":
4546
unittest.main()

tests/test_unit/test_wrappers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_read_csv(self):
106106
self._read_test_rows(rows, exp)
107107

108108
# This raises a NoDetectionResult due to the spacing after the
109-
# delimiter, which confuses the detection algorithm. Support for
109+
# delimiter, which confuses the detection algorithm. Support for
110110
# detecting 'skipinitialspace' should fix this problem.
111111
rows = ['1, "AA"', '2, "BB"', '3, "CC"']
112112
exp = [["1", "AA"], ["2", "BB"], ["3", "CC"]]

0 commit comments

Comments
 (0)