Skip to content

Commit

Permalink
fix: replace single quotes with double quotes as ruff recommend that …
Browse files Browse the repository at this point in the history
…as much as possible
  • Loading branch information
ssato committed Mar 17, 2024
1 parent 71204f8 commit fe4663a
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@


@pytest.mark.parametrize(
'inp,exp',
((' ', (None, '')),
('aaa', ('aaa', '')),
"inp,exp",
((" ", (None, "")),
("aaa", ("aaa", "")),
),
)
def test_parseline_warnings(inp, exp):
Expand All @@ -30,79 +30,79 @@ def test_parseline_warnings(inp, exp):


@pytest.mark.parametrize(
'inp,exp',
(('aaa:', ('aaa', '')),
(' aaa:', ('aaa', '')),
('url = http://localhost', ('url', 'http://localhost')),
('calendar.japanese.type: LocalGregorianCalendar',
('calendar.japanese.type', 'LocalGregorianCalendar')),
"inp,exp",
(("aaa:", ("aaa", "")),
(" aaa:", ("aaa", "")),
("url = http://localhost", ("url", "http://localhost")),
("calendar.japanese.type: LocalGregorianCalendar",
("calendar.japanese.type", "LocalGregorianCalendar")),
),
)
def test_parseline(inp, exp):
assert TT.parseline(inp) == exp


@pytest.mark.parametrize(
'inp,exp',
(('', None),
('a: A', 'a: A'),
('# a: A', None),
('! a: A', None),
('a: A # comment', 'a: A # comment'),
"inp,exp",
(("", None),
("a: A", "a: A"),
("# a: A", None),
("! a: A", None),
("a: A # comment", "a: A # comment"),
),
)
def test_pre_process_line(inp, exp):
assert TT._pre_process_line(inp) == exp


@pytest.mark.parametrize(
'inp,exp',
((r'aaa\:bbb', 'aaa:bbb'),
(r'\\a', r'\a'),
"inp,exp",
((r"aaa\:bbb", "aaa:bbb"),
(r"\\a", r"\a"),
),
)
def test_10_unescape(inp, exp):
assert TT.unescape(inp) == exp


@pytest.mark.parametrize(
'inp,exp',
((r':=\ ', r'\:\=\\ '),
"inp,exp",
((r":=\ ", r"\:\=\\ "),
),
)
def test_escape(inp, exp):
assert TT.escape(inp) == exp


@pytest.mark.parametrize(
'inp,exp',
((':', '\\:'),
('=', '\\='),
('a', 'a'),
"inp,exp",
((":", "\\:"),
("=", "\\="),
("a", "a"),
),
)
def test_escape_char(inp, exp):
assert TT._escape_char(inp) == exp


KEY_0 = 'calendar.japanese.type'
VAL_0 = 'LocalGregorianCalendar'
KV_0 = f'{KEY_0}: {VAL_0}'
KEY_0 = "calendar.japanese.type"
VAL_0 = "LocalGregorianCalendar"
KV_0 = f"{KEY_0}: {VAL_0}"
KV_1 = """application/postscript: \\
x=Postscript File;y=.eps,.ps
"""


@pytest.mark.parametrize(
'inp,exp',
(('', {}),
(f'# {KV_0}', {}),
(f'! {KV_0}', {}),
(f'{KEY_0}:', {KEY_0: ''}),
"inp,exp",
(("", {}),
(f"# {KV_0}", {}),
(f"! {KV_0}", {}),
(f"{KEY_0}:", {KEY_0: ""}),
(KV_0, {KEY_0: VAL_0}),
(f'{KV_0}# ...', {KEY_0: f'{VAL_0}# ...'}),
('key=a\\:b', {'key': 'a:b'}),
(KV_1, {'application/postscript': 'x=Postscript File;y=.eps,.ps'}),
(f"{KV_0}# ...", {KEY_0: f"{VAL_0}# ..."}),
("key=a\\:b", {"key": "a:b"}),
(KV_1, {"application/postscript": "x=Postscript File;y=.eps,.ps"}),
),
)
def test_load(inp, exp):
Expand Down
40 changes: 20 additions & 20 deletions tests/dicts/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@


@pytest.mark.parametrize(
'inp,exp',
(('/a~1b', '/a/b'),
('~1aaa~1~0bbb', '/aaa/~bbb'),
("inp", "exp"),
(("/a~1b", "/a/b"),
("~1aaa~1~0bbb", "/aaa/~bbb"),
),
)
def test_jsnp_unescape(inp, exp):
assert TT._jsnp_unescape(inp) == exp


@pytest.mark.parametrize(
'args,exp',
((('', ), []),
(('/', ), ['']),
(('/a', ), ['a']),
(('.a', ), ['a']),
(('a', ), ['a']),
(('a.', ), ['a']),
(('/a/b/c', ), ['a', 'b', 'c']),
(('a.b.c', ), ['a', 'b', 'c']),
(('abc', ), ['abc']),
(('/a/b/c', ), ['a', 'b', 'c']),
("args", "exp"),
((("", ), []),
(("/", ), [""]),
(("/a", ), ["a"]),
((".a", ), ["a"]),
(("a", ), ["a"]),
(("a.", ), ["a"]),
(("/a/b/c", ), ["a", "b", "c"]),
(("a.b.c", ), ["a", "b", "c"]),
(("abc", ), ["abc"]),
(("/a/b/c", ), ["a", "b", "c"]),
),
)
def test_split_path(args, exp):
Expand All @@ -42,8 +42,8 @@ def test_split_path(args, exp):

# FIXME: Add some more test cases
@pytest.mark.parametrize(
'args,exp',
(((dict(a=1, b=dict(c=2, )), 'a.b.d', 3),
("args", "exp"),
(((dict(a=1, b=dict(c=2, )), "a.b.d", 3),
dict(a=dict(b=dict(d=3)), b=dict(c=2))),
),
)
Expand All @@ -58,10 +58,10 @@ def test_set_(args, exp):
# FIXME: Likewise.
@pytest.mark.parametrize(
("obj", "opts", "exp"),
((OD((('a', 1), )),
((OD((("a", 1), )),
{"ac_ordered": False, "ac_dict": dict},
dict(a=1)),
(OD((('a', OD((('b', OD((('c', 1), ))), ))), )),
(OD((("a", OD((("b", OD((("c", 1), ))), ))), )),
{"ac_ordered": False, "ac_dict": dict},
dict(a=dict(b=dict(c=1)))),
),
Expand All @@ -71,10 +71,10 @@ def test_convert_to(obj, opts, exp):


@pytest.mark.parametrize(
'objs,exp',
("objs", "exp"),
((([], (), [x for x in range(10)], (x for x in range(4))), True),
(([], {}), False),
(([], 'aaa'), False),
(([], "aaa"), False),
),
)
def test_are_list_like(objs, exp):
Expand Down
4 changes: 2 additions & 2 deletions tests/ioinfo/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@


TEST_IOI_PATH_OBJ = IOInfo(
src=TEST_PY, type=IOI_PATH_OBJ, path=str(TEST_PY), extension='py'
src=TEST_PY, type=IOI_PATH_OBJ, path=str(TEST_PY), extension="py"
)
TEST_IOI_STREAM = IOInfo(
src=TEST_PY.open(), type=IOI_STREAM, path=str(TEST_PY), extension='py'
src=TEST_PY.open(), type=IOI_STREAM, path=str(TEST_PY), extension="py"
)


Expand Down
40 changes: 20 additions & 20 deletions tests/ioinfo/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@


@pytest.mark.parametrize(
('inp', 'exp'),
((SELF, (SELF.resolve(), 'py')),
("inp", "exp"),
((SELF, (SELF.resolve(), "py")),
)
)
def test_get_path_and_ext(inp, exp):
Expand All @@ -27,43 +27,43 @@ def test_get_path_and_ext(inp, exp):

try:
PATH_RESOLVE_SHOULD_WORK: bool = bool(
pathlib.Path('<stdout>').expanduser().resolve()
pathlib.Path("<stdout>").expanduser().resolve()
)
except (RuntimeError, OSError):
PATH_RESOLVE_SHOULD_WORK: bool = False


@pytest.mark.skipif(
PATH_RESOLVE_SHOULD_WORK,
reason='pathlib.Path.resolve() should work'
reason="pathlib.Path.resolve() should work"
)
def test_get_path_and_ext_failures():
path = pathlib.Path('<stdout>')
path = pathlib.Path("<stdout>")
res = TT.get_path_and_ext(path)
assert res == (path, '')
assert res == (path, "")


def test_expand_from_path(tmp_path):
tdir = tmp_path / 'a' / 'b' / 'c'
tdir = tmp_path / "a" / "b" / "c"
tdir.mkdir(parents=True)

pathlib.Path(tdir / 'd.txt').touch()
pathlib.Path(tdir / 'e.txt').touch()
pathlib.Path(tdir / 'f.json').write_text("{'a': 1}\n")
pathlib.Path(tdir / "d.txt").touch()
pathlib.Path(tdir / "e.txt").touch()
pathlib.Path(tdir / "f.json").write_text("{'a': 1}\n")

path = tdir / 'd.txt'
path = tdir / "d.txt"

for inp, exp in ((path, [path]),
(tdir / '*.txt',
[tdir / 'd.txt', tdir / 'e.txt']),
(tdir.parent / '**' / '*.txt',
[tdir / 'd.txt', tdir / 'e.txt']),
(tdir.parent / '**' / '*.*',
[tdir / 'd.txt',
tdir / 'e.txt',
tdir / 'f.json']),
(tdir / "*.txt",
[tdir / "d.txt", tdir / "e.txt"]),
(tdir.parent / "**" / "*.txt",
[tdir / "d.txt", tdir / "e.txt"]),
(tdir.parent / "**" / "*.*",
[tdir / "d.txt",
tdir / "e.txt",
tdir / "f.json"]),
):
res = sorted(TT.expand_from_path(inp))
assert res == sorted(exp), f'{inp!r} vs. {exp!r}'
assert res == sorted(exp), f"{inp!r} vs. {exp!r}"

# vim:sw=4:ts=4:et:
18 changes: 9 additions & 9 deletions tests/parsers/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
PSRS = Parsers().list()
JSON_PSRS = sorted(
(p() for p in JSON_PSR_CLSS),
key=operator.methodcaller('priority'), reverse=True
key=operator.methodcaller("priority"), reverse=True
)


Expand All @@ -31,7 +31,7 @@ def test_load_plugins(self):
def test_list_types(self):
res = TT.list_types()
self.assertTrue(bool(res))
self.assertTrue(any(x in res for x in ('json', 'ini', 'xml')))
self.assertTrue(any(x in res for x in ("json", "ini", "xml")))

def test_list_by_x(self):
for lfn in (TT.list_by_cid, TT.list_by_type, TT.list_by_extension):
Expand All @@ -40,17 +40,17 @@ def test_list_by_x(self):

def test_findall_ng_cases(self):
ies = (((None, None), ValueError), # w/o path nor type
(('/tmp/x.xyz', None), UnknownFileTypeError),
(('/dev/null', None), UnknownFileTypeError),
((None, 'xyz'), UnknownProcessorTypeError),
(("/tmp/x.xyz", None), UnknownFileTypeError),
(("/dev/null", None), UnknownFileTypeError),
((None, "xyz"), UnknownProcessorTypeError),
)
for inp, exc in ies:
with self.assertRaises(exc):
TT.findall(*inp)

def test_findall(self):
argss = (('foo.json', None),
(None, 'json'),
argss = (("foo.json", None),
(None, "json"),
)
for args in argss:
psrs = TT.findall(*args)
Expand All @@ -59,8 +59,8 @@ def test_findall(self):
self.assertEqual(psrs, JSON_PSRS)

def test_find(self):
argss = (('foo.json', None),
(None, 'json'),
argss = (("foo.json", None),
(None, "json"),
(None, JSON_PSR_CLSS[0]),
(None, JSON_PSRS[0]),
)
Expand Down
22 changes: 11 additions & 11 deletions tests/processors/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@


class A(anyconfig.models.processor.Processor):
_cid = 'A'
_type = 'json'
_extensions = ['json', 'jsn', 'js']
_cid = "A"
_type = "json"
_extensions = ["json", "jsn", "js"]


class A2(A):
_cid = 'A2'
_cid = "A2"
_priority = 20 # Higher priority than A.


class A3(A):
_cid = 'A3'
_cid = "A3"
_priority = 99 # Higher priority than A and A2.


class B(anyconfig.models.processor.Processor):
_cid = 'B'
_type = 'yaml'
_extensions = ['yaml', 'yml']
_cid = "B"
_type = "yaml"
_extensions = ["yaml", "yml"]
_priority = 99 # Higher priority than C.


class C(anyconfig.models.processor.Processor):
_cid = 'dummy'
_type = 'yaml'
_extensions = ['yaml', 'yml']
_cid = "dummy"
_type = "yaml"
_extensions = ["yaml", "yml"]


PRS = [A, A2, A3, B, C]
Expand Down
Loading

0 comments on commit fe4663a

Please sign in to comment.