[codemod][lint][fbcode/c*] Enable BLACK by default

Test Plan: manual inspection & sandcastle

Reviewed By: zertosh

Differential Revision: D30279364

fbshipit-source-id: c1ed77dfe43a3bde358f92737cd5535ae5d13c9a
This commit is contained in:
Zsolt Dollenstein
2021-08-12 10:56:55 -07:00
committed by Facebook GitHub Bot
parent aac3c7bd06
commit b004307252
188 changed files with 56875 additions and 28744 deletions

View File

@ -1,14 +1,27 @@
from typing import List, Tuple
from test_jit import JitTestCase
from torch.testing._internal.common_utils import run_tests
from typing import List, Tuple
class TestScript(JitTestCase):
def test_str_ops(self):
def test_str_is(s: str) -> Tuple[bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool]:
return s.isupper(), s.islower(), s.isdigit(), s.isspace(), \
s.isalnum(), s.isalpha(), s.isdecimal(), s.isnumeric(), \
s.isidentifier(), s.istitle(), s.isprintable()
def test_str_is(
s: str,
) -> Tuple[bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool]:
return (
s.isupper(),
s.islower(),
s.isdigit(),
s.isspace(),
s.isalnum(),
s.isalpha(),
s.isdecimal(),
s.isnumeric(),
s.isidentifier(),
s.istitle(),
s.isprintable(),
)
def test_str_to(s: str) -> Tuple[str, str, str, str, str]:
return s.upper(), s.lower(), s.capitalize(), s.title(), s.swapcase()
@ -27,19 +40,39 @@ class TestScript(JitTestCase):
s.strip(char_set),
)
inputs = ["", "12a", "!B", "12", "a", "B", "aB", "$12", "B12", "AB ",
" \t", " \n", "\na", "abc", "123.3", "s a", "b12a ",
"more strings with spaces", "Titular Strings", "\x0acan'tprintthis",
"spaces at the end ", " begin"]
inputs = [
"",
"12a",
"!B",
"12",
"a",
"B",
"aB",
"$12",
"B12",
"AB ",
" \t",
" \n",
"\na",
"abc",
"123.3",
"s a",
"b12a ",
"more strings with spaces",
"Titular Strings",
"\x0acan'tprintthis",
"spaces at the end ",
" begin",
]
def test_str_center(i: int, s: str) -> str:
return s.center(i)
def test_str_center_fc(i: int, s: str) -> str:
return s.center(i, '*')
return s.center(i, "*")
def test_str_center_error(s: str) -> str:
return s.center(10, '**')
return s.center(10, "**")
def test_ljust(s: str, i: int) -> str:
return s.ljust(i)
@ -48,7 +81,7 @@ class TestScript(JitTestCase):
return s.ljust(i, fc)
def test_ljust_fc_err(s: str) -> str:
return s.ljust(10, '**')
return s.ljust(10, "**")
def test_rjust(s: str, i: int) -> str:
return s.rjust(i)
@ -57,7 +90,7 @@ class TestScript(JitTestCase):
return s.rjust(i, fc)
def test_rjust_fc_err(s: str) -> str:
return s.rjust(10, '**')
return s.rjust(10, "**")
def test_zfill(s: str, i: int) -> str:
return s.zfill(i)
@ -69,19 +102,33 @@ class TestScript(JitTestCase):
for char_set in ["abc", "123", " ", "\t"]:
self.checkScript(test_str_strip_char_set, (input, char_set))
for i in range(7):
self.checkScript(test_str_center, (i, input,))
self.checkScript(test_str_center_fc, (i, input,))
self.checkScript(
test_str_center,
(
i,
input,
),
)
self.checkScript(
test_str_center_fc,
(
i,
input,
),
)
self.checkScript(test_ljust, (input, i))
self.checkScript(test_ljust_fc, (input, i, '*'))
self.checkScript(test_ljust_fc, (input, i, "*"))
self.checkScript(test_rjust, (input, i))
self.checkScript(test_rjust_fc, (input, i, '*'))
self.checkScript(test_rjust_fc, (input, i, "*"))
self.checkScript(test_zfill, (input, i))
with self.assertRaises(Exception):
test_str_center_error("error")
test_ljust("error")
def test_count() -> Tuple[int, int, int, int, int, int, int, int, int, int, int, int]:
def test_count() -> Tuple[
int, int, int, int, int, int, int, int, int, int, int, int
]:
return (
"hello".count("h"),
"hello".count("h", 0, 1),
@ -94,11 +141,27 @@ class TestScript(JitTestCase):
"hello".count("ell", -3),
"hello".count("ell", -10, 1),
"hello".count("ell", 0, -10),
"hello".count("ell", 0, 10)
"hello".count("ell", 0, 10),
)
self.checkScript(test_count, ())
def test_endswith() -> Tuple[bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool]:
def test_endswith() -> Tuple[
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
]:
return (
"hello".endswith("lo"),
"hello".endswith("lo", 0),
@ -113,11 +176,27 @@ class TestScript(JitTestCase):
"hello".endswith("l", -8),
"hello".endswith("l", 0, -5),
"hello".endswith("l", -2, 3),
"hello".endswith("l", -8, 4)
"hello".endswith("l", -8, 4),
)
self.checkScript(test_endswith, ())
def test_startswith() -> Tuple[bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool, bool]:
def test_startswith() -> Tuple[
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
bool,
]:
return (
"hello".startswith("lo"),
"hello".startswith("lo", 0),
@ -132,19 +211,21 @@ class TestScript(JitTestCase):
"hello".startswith("l", -8),
"hello".startswith("l", 0, -5),
"hello".startswith("l", -2, 3),
"hello".startswith("l", -8, 4)
"hello".startswith("l", -8, 4),
)
self.checkScript(test_startswith, ())
def test_expandtabs() -> Tuple[str, str, str, str, str, str]:
return (
'xyz\t82345\tabc'.expandtabs(),
'xyz\t32345\tabc'.expandtabs(3),
'xyz\t52345\tabc'.expandtabs(5),
'xyz\t62345\tabc'.expandtabs(6),
'xyz\t72345\tabc'.expandtabs(7),
'xyz\t62345\tabc'.expandtabs(-5),
"xyz\t82345\tabc".expandtabs(),
"xyz\t32345\tabc".expandtabs(3),
"xyz\t52345\tabc".expandtabs(5),
"xyz\t62345\tabc".expandtabs(6),
"xyz\t72345\tabc".expandtabs(7),
"xyz\t62345\tabc".expandtabs(-5),
)
self.checkScript(test_expandtabs, ())
def test_rfind() -> Tuple[int, int, int, int, int, int, int, int, int]:
@ -159,6 +240,7 @@ class TestScript(JitTestCase):
"hello123abc".rfind("12", 4, -4),
"hello123abc".rfind("ab", -7, -20),
)
self.checkScript(test_rfind, ())
def test_find() -> Tuple[int, int, int, int, int, int, int, int, int]:
@ -173,6 +255,7 @@ class TestScript(JitTestCase):
"hello123abc".find("12", 4, -4),
"hello123abc".find("ab", -7, -20),
)
self.checkScript(test_find, ())
def test_index() -> Tuple[int, int, int, int, int, int]:
@ -184,6 +267,7 @@ class TestScript(JitTestCase):
"hello123abc".index("ab", -7),
"hello123abc".index("12", 4, -4),
)
self.checkScript(test_index, ())
def test_rindex() -> Tuple[int, int, int, int, int, int]:
@ -195,6 +279,7 @@ class TestScript(JitTestCase):
"hello123abc".rindex("ab", -7),
"hello123abc".rindex("12", 4, -4),
)
self.checkScript(test_rindex, ())
def test_replace() -> Tuple[str, str, str, str, str, str, str]:
@ -207,11 +292,18 @@ class TestScript(JitTestCase):
"ccc".replace("c", "ccc", 3),
"cc".replace("c", "ccc", -3),
)
self.checkScript(test_replace, ())
def test_partition() -> Tuple[Tuple[str, str, str], Tuple[str, str, str], Tuple[str, str, str],
Tuple[str, str, str], Tuple[str, str, str], Tuple[str, str, str],
Tuple[str, str, str]]:
def test_partition() -> Tuple[
Tuple[str, str, str],
Tuple[str, str, str],
Tuple[str, str, str],
Tuple[str, str, str],
Tuple[str, str, str],
Tuple[str, str, str],
Tuple[str, str, str],
]:
return (
"hello123abc".partition("llo"),
"ff".partition("f"),
@ -221,11 +313,18 @@ class TestScript(JitTestCase):
"ccc".partition("ccc"),
"cc".partition("ccc"),
)
self.checkScript(test_partition, ())
def test_rpartition() -> Tuple[Tuple[str, str, str], Tuple[str, str, str], Tuple[str, str, str],
Tuple[str, str, str], Tuple[str, str, str], Tuple[str, str, str],
Tuple[str, str, str]]:
def test_rpartition() -> Tuple[
Tuple[str, str, str],
Tuple[str, str, str],
Tuple[str, str, str],
Tuple[str, str, str],
Tuple[str, str, str],
Tuple[str, str, str],
Tuple[str, str, str],
]:
return (
"hello123abc".rpartition("llo"),
"ff".rpartition("f"),
@ -235,10 +334,22 @@ class TestScript(JitTestCase):
"ccc".rpartition("ccc"),
"cc".rpartition("ccc"),
)
self.checkScript(test_rpartition, ())
def test_split() -> Tuple[List[str], List[str], List[str], List[str], List[str],
List[str], List[str], List[str], List[str], List[str], List[str]]:
def test_split() -> Tuple[
List[str],
List[str],
List[str],
List[str],
List[str],
List[str],
List[str],
List[str],
List[str],
List[str],
List[str],
]:
return (
"a a a a a".split(),
"a a a a a".split(),
@ -252,6 +363,7 @@ class TestScript(JitTestCase):
" a*a a*a a ".split("*", -1),
" a*a a*a a ".split("a*", 10),
)
self.checkScript(test_split, ())
# test raising error for empty separator
@ -259,11 +371,21 @@ class TestScript(JitTestCase):
s = "test"
return s.split("")
self.checkScriptRaisesRegex(test_split_empty_separator, (), Exception,
"empty separator")
self.checkScriptRaisesRegex(
test_split_empty_separator, (), Exception, "empty separator"
)
def test_rsplit() -> Tuple[List[str], List[str], List[str], List[str], List[str],
List[str], List[str], List[str], List[str]]:
def test_rsplit() -> Tuple[
List[str],
List[str],
List[str],
List[str],
List[str],
List[str],
List[str],
List[str],
List[str],
]:
return (
"a a a a a".rsplit(),
" a a a a a ".rsplit(" "),
@ -275,10 +397,12 @@ class TestScript(JitTestCase):
" a*a a*a a ".rsplit("*", -1),
" a*a a*a a".rsplit("a*", 10),
)
self.checkScript(test_rsplit, ())
def test_splitlines() -> Tuple[List[str], List[str], List[str], List[str],
List[str], List[str]]:
def test_splitlines() -> Tuple[
List[str], List[str], List[str], List[str], List[str], List[str]
]:
return (
"hello\ntest".splitlines(),
"hello\n\ntest\n".splitlines(),
@ -287,6 +411,7 @@ class TestScript(JitTestCase):
"hello\v\f\ntest".splitlines(),
"hello\ftest".splitlines(),
)
self.checkScript(test_splitlines, ())
def test_str_cmp(a: str, b: str) -> Tuple[bool, bool, bool, bool, bool, bool]:
@ -304,6 +429,7 @@ class TestScript(JitTestCase):
"**a**".join(["b", "c", "d", "e"]),
"".join(["a", "b", "c"]),
)
self.checkScript(test_str_join, ())
def test_bool_conversion(a: str):
@ -315,5 +441,6 @@ class TestScript(JitTestCase):
self.checkScript(test_bool_conversion, ("nonempty",))
self.checkScript(test_bool_conversion, ("",))
if __name__ == '__main__':
if __name__ == "__main__":
run_tests()