diff --git a/tests/backend/loaders/properties/test_properties_builtin_functions.py b/tests/backend/loaders/properties/test_properties_builtin_functions.py index 946c6a4f..68a859be 100644 --- a/tests/backend/loaders/properties/test_properties_builtin_functions.py +++ b/tests/backend/loaders/properties/test_properties_builtin_functions.py @@ -19,9 +19,9 @@ @pytest.mark.parametrize( - 'inp,exp', - ((' ', (None, '')), - ('aaa', ('aaa', '')), + "inp,exp", + ((" ", (None, "")), + ("aaa", ("aaa", "")), ), ) def test_parseline_warnings(inp, exp): @@ -30,12 +30,12 @@ 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): @@ -43,12 +43,12 @@ def test_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): @@ -56,9 +56,9 @@ def test_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): @@ -66,8 +66,8 @@ def test_10_unescape(inp, exp): @pytest.mark.parametrize( - 'inp,exp', - ((r':=\ ', r'\:\=\\ '), + "inp,exp", + ((r":=\ ", r"\:\=\\ "), ), ) def test_escape(inp, exp): @@ -75,34 +75,34 @@ def test_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): diff --git a/tests/dicts/test_functions.py b/tests/dicts/test_functions.py index b7d9b99e..27097cfa 100644 --- a/tests/dicts/test_functions.py +++ b/tests/dicts/test_functions.py @@ -13,9 +13,9 @@ @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): @@ -23,17 +23,17 @@ def test_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): @@ -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))), ), ) @@ -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)))), ), @@ -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): diff --git a/tests/ioinfo/test_factory.py b/tests/ioinfo/test_factory.py index c88db0d4..44d7e4da 100644 --- a/tests/ioinfo/test_factory.py +++ b/tests/ioinfo/test_factory.py @@ -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" ) diff --git a/tests/ioinfo/test_utils.py b/tests/ioinfo/test_utils.py index 91b306b6..4ed24f00 100644 --- a/tests/ioinfo/test_utils.py +++ b/tests/ioinfo/test_utils.py @@ -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): @@ -27,7 +27,7 @@ def test_get_path_and_ext(inp, exp): try: PATH_RESOLVE_SHOULD_WORK: bool = bool( - pathlib.Path('').expanduser().resolve() + pathlib.Path("").expanduser().resolve() ) except (RuntimeError, OSError): PATH_RESOLVE_SHOULD_WORK: bool = False @@ -35,35 +35,35 @@ def test_get_path_and_ext(inp, exp): @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('') + path = pathlib.Path("") 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: diff --git a/tests/parsers/test_utils.py b/tests/parsers/test_utils.py index 21186365..8950a5d2 100644 --- a/tests/parsers/test_utils.py +++ b/tests/parsers/test_utils.py @@ -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 ) @@ -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): @@ -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) @@ -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]), ) diff --git a/tests/processors/common.py b/tests/processors/common.py index 732127b4..e7a4d7d2 100644 --- a/tests/processors/common.py +++ b/tests/processors/common.py @@ -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] diff --git a/tests/processors/test_processors.py b/tests/processors/test_processors.py index 144aacea..5cf4e67a 100644 --- a/tests/processors/test_processors.py +++ b/tests/processors/test_processors.py @@ -29,7 +29,7 @@ def test_10_init(self): def test_12_init_with_processors(self): prcs = TT.Processors(PRS) self.assertEqual(prcs.list(sort=True), - sorted(PRS, key=operator.methodcaller('cid'))) + sorted(PRS, key=operator.methodcaller("cid"))) def test_20_list_by_cid(self): prcs = TT.Processors(PRS) @@ -40,12 +40,12 @@ def test_20_list_by_cid(self): def test_20_list_x(self): prcs = TT.Processors(PRS) self.assertRaises(ValueError, prcs.list_x) - self.assertEqual(prcs.list_x('cid'), + self.assertEqual(prcs.list_x("cid"), sorted(set(p.cid() for p in PRS))) - self.assertEqual(prcs.list_x('type'), + self.assertEqual(prcs.list_x("type"), sorted(set(p.type() for p in PRS))) res = sorted(set(A.extensions() + B.extensions() + C.extensions())) - self.assertEqual(prcs.list_x('extension'), res) + self.assertEqual(prcs.list_x("extension"), res) # vim:sw=4:ts=4:et: diff --git a/tests/processors/test_utils.py b/tests/processors/test_utils.py index 471d3d77..9c2257dc 100644 --- a/tests/processors/test_utils.py +++ b/tests/processors/test_utils.py @@ -21,23 +21,23 @@ class TestCase(unittest.TestCase): def test_select_by_key(self): ies = (([], []), - (((['a'], 1), ), [('a', [1])]), - (((['a', 'aaa'], 1), - (['b', 'bb'], 2), - (['a'], 3)), - [('a', [1, 3]), - ('aaa', [1]), - ('b', [2]), - ('bb', [2])])) + (((["a"], 1), ), [("a", [1])]), + (((["a", "aaa"], 1), + (["b", "bb"], 2), + (["a"], 3)), + [("a", [1, 3]), + ("aaa", [1]), + ("b", [2]), + ("bb", [2])])) for inp, exp in ies: self.assertEqual(TT.select_by_key(inp), exp) def test_select_by_key_reversed(self): - ies = ((((['a', 'aaa'], 1), - (['a'], 3)), - [('a', [3, 1]), - ('aaa', [1])]), + ies = ((((["a", "aaa"], 1), + (["a"], 3)), + [("a", [3, 1]), + ("aaa", [1])]), ) def sfn(itr): @@ -48,19 +48,19 @@ def sfn(itr): def test_list_by_x(self): (a, a2, a3, b, c) = (A(), A2(), A3(), B(), C()) - ies = ((([], 'type'), []), - (([a], 'type'), [(a.type(), [a])]), - (([a], 'extensions'), + ies = ((([], "type"), []), + (([a], "type"), [(a.type(), [a])]), + (([a], "extensions"), [(x, [a]) for x in a.extensions()]), - (((a, a2, a3), 'type'), + (((a, a2, a3), "type"), [(a.type(), [a3, a2, a])]), - (([a, b, c], 'type'), + (([a, b, c], "type"), [(a.type(), [a]), (b.type(), [b, c])]), - ((PRS, 'type'), + ((PRS, "type"), [(a.type(), [a3, a2, a]), (b.type(), [b, c])]), - ((PRS, 'extensions'), - [('js', [a3, a2, a]), ('json', [a3, a2, a]), - ('jsn', [a3, a2, a]), ('yaml', [b, c]), ('yml', [b, c])]), + ((PRS, "extensions"), + [("js", [a3, a2, a]), ("json", [a3, a2, a]), + ("jsn", [a3, a2, a]), ("yaml", [b, c]), ("yml", [b, c])]), ) for prs_key, exp in ies: @@ -70,16 +70,16 @@ def test_list_by_x(self): def test_list_by_x_ng_cases(self): with self.assertRaises(ValueError): - TT.list_by_x(PRS, 'undef') + TT.list_by_x(PRS, "undef") def test_findall_with_pred__type(self): def _findall_by_type(typ): return TT.findall_with_pred(lambda p: p.type() == typ, PRS) (a, a2, a3, b, c) = (A(), A2(), A3(), B(), C()) - ies = (('json', [a3, a2, a]), - ('yaml', [b, c]), - ('undefined', []), + ies = (("json", [a3, a2, a]), + ("yaml", [b, c]), + ("undefined", []), ) for inp, exp in ies: @@ -90,9 +90,9 @@ def _findall_with_pred__ext(ext): return TT.findall_with_pred(lambda p: ext in p.extensions(), PRS) (a, a2, a3, b, c) = (A(), A2(), A3(), B(), C()) - ies = (('js', [a3, a2, a]), - ('yml', [b, c]), - ('xyz', []), + ies = (("js", [a3, a2, a]), + ("yml", [b, c]), + ("xyz", []), ) for inp, exp in ies: @@ -117,34 +117,34 @@ def test_maybe_processor(self): def test_find_by_type_or_id(self): (a, a2, a3, b, c) = (A(), A2(), A3(), B(), C()) - ies = ((('json', PRS), [a3, a2, a]), - (('yaml', PRS), [b, c]), - (('dummy', PRS), [c]), + ies = ((("json", PRS), [a3, a2, a]), + (("yaml", PRS), [b, c]), + (("dummy", PRS), [c]), ) for inp, exp in ies: self.assertEqual(TT.find_by_type_or_id(*inp), exp) def test_find_by_type_or_id_ng_cases(self): with self.assertRaises(UnknownProcessorTypeError): - TT.find_by_type_or_id('xyz', PRS) + TT.find_by_type_or_id("xyz", PRS) def test_find_by_fileext(self): - ies = ((('js', PRS), [A3(), A2(), A()]), - (('yml', PRS), [B(), C()]), + ies = ((("js", PRS), [A3(), A2(), A()]), + (("yml", PRS), [B(), C()]), ) for inp, exp in ies: self.assertEqual(TT.find_by_fileext(*inp), exp) def test_find_by_fileext_ng_cases(self): with self.assertRaises(UnknownFileTypeError): - TT.find_by_fileext('xyz', PRS) + TT.find_by_fileext("xyz", PRS) def test_find_by_maybe_file(self): (a, a2, a3, b, c) = (A(), A2(), A3(), B(), C()) - obj = anyconfig.ioinfo.make('/path/to/a.json') + obj = anyconfig.ioinfo.make("/path/to/a.json") - ies = ((('/path/to/a.jsn', PRS), [a3, a2, a]), - (('../../path/to/b.yml', PRS), [b, c]), + ies = ((("/path/to/a.jsn", PRS), [a3, a2, a]), + (("../../path/to/b.yml", PRS), [b, c]), ((obj, PRS), [a3, a2, a]), ) @@ -152,8 +152,8 @@ def test_find_by_maybe_file(self): self.assertEqual(TT.find_by_maybe_file(*inp), exp) def test_find_by_maybe_file_ng_cases(self): - ies = (('/tmp/x.xyz', PRS), - ('/dev/null', PRS), + ies = (("/tmp/x.xyz", PRS), + ("/dev/null", PRS), ) for inp in ies: with self.assertRaises(UnknownFileTypeError): @@ -161,9 +161,9 @@ def test_find_by_maybe_file_ng_cases(self): def test_findall_ng_cases(self): ies = (((None, PRS, None), ValueError), # w/o path nor type - (('/tmp/x.xyz', PRS, None), UnknownFileTypeError), - (('/dev/null', PRS, None), UnknownFileTypeError), - ((None, PRS, 'xyz'), UnknownProcessorTypeError), + (("/tmp/x.xyz", PRS, None), UnknownFileTypeError), + (("/dev/null", PRS, None), UnknownFileTypeError), + ((None, PRS, "xyz"), UnknownProcessorTypeError), ) for inp, exc in ies: with self.assertRaises(exc): @@ -171,10 +171,10 @@ def test_findall_ng_cases(self): def test_findall_by_maybe_file(self): (a, a2, a3, b, c) = (A(), A2(), A3(), B(), C()) - obj = anyconfig.ioinfo.make('/path/to/a.json') + obj = anyconfig.ioinfo.make("/path/to/a.json") - ies = ((('/path/to/a.jsn', PRS), [a3, a2, a]), - (('../../path/to/b.yml', PRS), [b, c]), + ies = ((("/path/to/a.jsn", PRS), [a3, a2, a]), + (("../../path/to/b.yml", PRS), [b, c]), ((obj, PRS), [a3, a2, a]), ) for inp, exp in ies: @@ -182,9 +182,9 @@ def test_findall_by_maybe_file(self): def test_findall_by_type_or_id(self): (a, a2, a3, b, c) = (A(), A2(), A3(), B(), C()) - ies = (((None, PRS, 'json'), [a3, a2, a]), - ((None, PRS, 'yaml'), [b, c]), - ((None, PRS, 'dummy'), [c]), + ies = (((None, PRS, "json"), [a3, a2, a]), + ((None, PRS, "yaml"), [b, c]), + ((None, PRS, "dummy"), [c]), ) for inp, exp in ies: self.assertEqual(TT.findall(*inp), exp) @@ -202,19 +202,19 @@ def test_find_by_forced_type(self): def test_find__maybe_file(self): (a3, b) = (A3(), B()) - obj = anyconfig.ioinfo.make('/path/to/a.json') + obj = anyconfig.ioinfo.make("/path/to/a.json") - ies = ((('/path/to/a.jsn', PRS), a3), - (('../../path/to/b.yml', PRS), b), + ies = ((("/path/to/a.jsn", PRS), a3), + (("../../path/to/b.yml", PRS), b), ((obj, PRS), a3), ) for inp, exp in ies: self.assertEqual(TT.find(*inp), exp) def test_find__type_or_id(self): - ies = (((None, PRS, 'json'), A3()), - ((None, PRS, 'yaml'), B()), - ((None, PRS, 'dummy'), C()), + ies = (((None, PRS, "json"), A3()), + ((None, PRS, "yaml"), B()), + ((None, PRS, "dummy"), C()), ) for inp, exp in ies: self.assertEqual(TT.find(*inp), exp) diff --git a/tests/schema/test_jsonschema.py b/tests/schema/test_jsonschema.py index 1eaadade..cd0d7cef 100644 --- a/tests/schema/test_jsonschema.py +++ b/tests/schema/test_jsonschema.py @@ -15,19 +15,19 @@ class Test_00_Base(unittest.TestCase): - obj = {'a': 1} + obj = {"a": 1} schema = {"type": "object", "properties": {"a": {"type": "integer"}}} obj2 = dict(a=1, b=[1, 2], c=dict(d="aaa", e=0.1)) - ref_scm = {'properties': {'a': {'type': 'integer'}, - 'b': {'items': {'type': 'integer'}, - 'type': 'array'}, - 'c': {'properties': {'d': {'type': 'string'}, - 'e': {'type': - 'number'}}, - 'type': 'object'}}, - 'type': 'object'} + ref_scm = {"properties": {"a": {"type": "integer"}, + "b": {"items": {"type": "integer"}, + "type": "array"}, + "c": {"properties": {"d": {"type": "string"}, + "e": {"type": + "number"}}, + "type": "object"}}, + "type": "object"} opts = dict(ac_schema_typemap=SUPPORTED) @@ -45,14 +45,14 @@ def test_22_array_to_schema__empty_array(self): self.assertEqual(scm, ref, scm) def test_30_object_to_schema_nodes_iter(self): - scm = TT.object_to_schema({'a': 1}) + scm = TT.object_to_schema({"a": 1}) ref = dict(type="object", properties=dict(a=dict(type="integer"))) self.assertEqual(scm, ref, scm) @unittest.skipIf(not SUPPORTED, "json schema lib is not available") class Test_10_Validation(Test_00_Base): - obj_ng = dict(a='aaa') + obj_ng = {"a": "aaa"} def test_10_validate(self): (ret, msg) = TT.validate(self.obj, self.schema) @@ -97,16 +97,16 @@ def test_10_validate__ng(self): class Test_20_GenSchema(Test_00_Base): def test_40_gen_schema__primitive_types(self): - self.assertEqual(TT.gen_schema(None), {'type': 'null'}) - self.assertEqual(TT.gen_schema(0), {'type': 'integer'}) - self.assertEqual(TT.gen_schema("aaa"), {'type': 'string'}) + self.assertEqual(TT.gen_schema(None), {"type": "null"}) + self.assertEqual(TT.gen_schema(0), {"type": "integer"}) + self.assertEqual(TT.gen_schema("aaa"), {"type": "string"}) scm = TT.gen_schema([1]) - ref_scm = {'items': {'type': 'integer'}, 'type': 'array'} + ref_scm = {"items": {"type": "integer"}, "type": "array"} self.assertEqual(scm, ref_scm) - scm = TT.gen_schema({'a': 1}) - ref_scm = {'properties': {'a': {'type': 'integer'}}, 'type': 'object'} + scm = TT.gen_schema({"a": 1}) + ref_scm = {"properties": {"a": {"type": "integer"}}, "type": "object"} self.assertEqual(scm, ref_scm) def test_42_gen_schema_and_validate(self): @@ -132,36 +132,36 @@ class Test_30_GenStrictSchema(Test_00_Base): "properties": {"a": {"type": "integer"}}, "required": ["a"]} - ref_scm = {'properties': {'a': {'type': 'integer'}, - 'b': {'items': {'type': 'integer'}, - 'type': 'array', - 'minItems': 2, 'uniqueItems': True}, - 'c': {'properties': {'d': {'type': 'string'}, - 'e': {'type': - 'number'}}, - 'type': 'object', - 'required': ['d', 'e']}}, - 'type': 'object', - 'required': ['a', 'b', 'c']} + ref_scm = {"properties": {"a": {"type": "integer"}, + "b": {"items": {"type": "integer"}, + "type": "array", + "minItems": 2, "uniqueItems": True}, + "c": {"properties": {"d": {"type": "string"}, + "e": {"type": + "number"}}, + "type": "object", + "required": ["d", "e"]}}, + "type": "object", + "required": ["a", "b", "c"]} def test_40_gen_schema__primitive_types(self): - self.assertEqual(_gen_scm(None), {'type': 'null'}) - self.assertEqual(_gen_scm(0), {'type': 'integer'}) - self.assertEqual(_gen_scm("aaa"), {'type': 'string'}) + self.assertEqual(_gen_scm(None), {"type": "null"}) + self.assertEqual(_gen_scm(0), {"type": "integer"}) + self.assertEqual(_gen_scm("aaa"), {"type": "string"}) scm = _gen_scm([1]) - ref_scm = {'items': {'type': 'integer'}, 'type': 'array', - 'minItems': 1, 'uniqueItems': True} + ref_scm = {"items": {"type": "integer"}, "type": "array", + "minItems": 1, "uniqueItems": True} self.assertEqual(scm, ref_scm) scm = _gen_scm(["aaa", "bbb", "aaa"]) - ref_scm = {'items': {'type': 'string'}, 'type': 'array', - 'minItems': 3, 'uniqueItems': False} + ref_scm = {"items": {"type": "string"}, "type": "array", + "minItems": 3, "uniqueItems": False} self.assertEqual(scm, ref_scm) - scm = _gen_scm({'a': 1}) - ref_scm = {'properties': {'a': {'type': 'integer'}}, - 'type': 'object', 'required': ['a']} + scm = _gen_scm({"a": 1}) + ref_scm = {"properties": {"a": {"type": "integer"}}, + "type": "object", "required": ["a"]} self.assertEqual(scm, ref_scm) def test_42_gen_schema_and_validate(self): diff --git a/tests/template/test_jinja2.py b/tests/template/test_jinja2.py index 8cbadb4b..5318db2e 100644 --- a/tests/template/test_jinja2.py +++ b/tests/template/test_jinja2.py @@ -12,20 +12,20 @@ try: import anyconfig.template.jinja2 as TT except ImportError: - raise unittest.SkipTest('jinja2 does not look available.') + raise unittest.SkipTest("jinja2 does not look available.") from .. import base -TDATA_DIR = base.RES_DIR / 'template/jinja2/' +TDATA_DIR = base.RES_DIR / "template/jinja2/" TEMPLATES = [ - (path, (TDATA_DIR / '10/r/10.txt').read_text()) - for path in (TDATA_DIR / '10').glob('*.j2') + (path, (TDATA_DIR / "10/r/10.txt").read_text()) + for path in (TDATA_DIR / "10").glob("*.j2") ] TEMPLATES_WITH_FILTERS = [ - (path, (TDATA_DIR / f'20/r/{path.stem}.txt').read_text()) - for path in (TDATA_DIR / '20').glob('*.j2') + (path, (TDATA_DIR / f"20/r/{path.stem}.txt").read_text()) + for path in (TDATA_DIR / "20").glob("*.j2") ] @@ -42,9 +42,9 @@ def negate(value): class FunctionsTestCase(unittest.TestCase): def test_make_template_paths(self): - tpath0 = pathlib.Path('/path/to/a/').resolve() - path0 = tpath0 / 'tmpl.j2' - tmp0 = pathlib.Path('/tmp').resolve() + tpath0 = pathlib.Path("/path/to/a/").resolve() + path0 = tpath0 / "tmpl.j2" + tmp0 = pathlib.Path("/tmp").resolve() ies = (((path0, ), [tpath0]), ((path0, [tmp0]), [tpath0, tmp0]), ) @@ -54,12 +54,12 @@ def test_make_template_paths(self): ) def test_make_template_paths_after_chdir(self): - tmp0 = pathlib.Path('/tmp').resolve() + tmp0 = pathlib.Path("/tmp").resolve() saved = pathlib.Path().cwd().resolve() try: os.chdir(str(tmp0)) - tpath1 = pathlib.Path('.') - path1 = tpath1 / 'tmpl.j2' + tpath1 = pathlib.Path(".") + path1 = tpath1 / "tmpl.j2" ies = (((path1, ), [tmp0]), ((path1, [tmp0]), [tmp0]), ) @@ -99,15 +99,15 @@ def test_render_with_wrong_path(self): with tempfile.TemporaryDirectory() as tdir: workdir = pathlib.Path(tdir) - ng_t = workdir / 'ng.j2' - ok_t = workdir / 'ok.j2' - ok_t_content = 'a: {{ a }}' - ok_content = 'a: aaa' - ctx = dict(a='aaa', ) + ng_t = workdir / "ng.j2" + ok_t = workdir / "ok.j2" + ok_t_content = "a: {{ a }}" + ok_content = "a: aaa" + ctx = dict(a="aaa", ) ok_t.write_text(ok_t_content) - with unittest.mock.patch('builtins.input') as mock_input: + with unittest.mock.patch("builtins.input") as mock_input: mock_input.return_value = str(ok_t) c_r = TT.render(str(ng_t), ctx, ask=True) self.assertEqual(c_r, ok_content) @@ -121,7 +121,7 @@ def test_try_render_with_empty_filepath_and_content(self): def test_render_with_filter(self): for inp, exp in TEMPLATES_WITH_FILTERS: self.assertAlmostEqual( - TT.render(inp, filters={'negate': negate}), exp + TT.render(inp, filters={"negate": negate}), exp ) # vim:sw=4:ts=4:et: diff --git a/tests/test_lib.py b/tests/test_lib.py index 2f8a2590..0190b595 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -17,13 +17,13 @@ anyconfig.dump(c, "/dev/null", "yaml") """ -NULL_DEV = '/dev/null' +NULL_DEV = "/dev/null" if not pathlib.Path(NULL_DEV).exists(): - NULL_DEV = 'NUL' + NULL_DEV = "NUL" def check_output(cmd): - devnull = open(NULL_DEV, 'w') + devnull = open(NULL_DEV, "w") proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=devnull) return proc.communicate()[0] @@ -31,11 +31,11 @@ def check_output(cmd): class TestCase(unittest.TestCase): def test_00_run_script(self): - with tempfile.TemporaryDirectory(prefix='anyconfig-tests-') as tmpdir: + with tempfile.TemporaryDirectory(prefix="anyconfig-tests-") as tmpdir: script = pathlib.Path(tmpdir) / "a.py" script.write_text(SCRIPT_TO_USE_ANYCONFIG) out = check_output(["python", str(script)]) - self.assertTrue(out in (b'', '')) + self.assertTrue(out in (b"", "")) # vim:sw=4:ts=4:et: diff --git a/tests/utils/test_detectors.py b/tests/utils/test_detectors.py index 3ea449f5..957526ee 100644 --- a/tests/utils/test_detectors.py +++ b/tests/utils/test_detectors.py @@ -12,12 +12,12 @@ @pytest.mark.parametrize( - 'inp,exp', + ("inp", "exp"), ((None, False), ([], True), ((), True), ((str(x) for x in range(10)), True), ([str(x) for x in range(10)], True), - ('abc', False), (0, False), ({}, False), + ("abc", False), (0, False), ({}, False), ), ) def test_is_iterable(inp, exp): @@ -25,10 +25,10 @@ def test_is_iterable(inp, exp): @pytest.mark.parametrize( - 'inp,exp', + ("inp", "exp"), ((None, False), (0, False), - ('aaa', False), + ("aaa", False), ({}, False), ([], True), ((), True), ((str(x) for x in range(10)), True), @@ -40,15 +40,15 @@ def test_is_list_like(inp, exp): @pytest.mark.parametrize( - 'inp,exp', + ("inp", "exp"), ((None, False), (0, False), - ('aaa', False), + ("aaa", False), ([], False), ((1, ), False), - (collections.namedtuple('Point', ('x', 'y'))(1, 2), False), + (collections.namedtuple("Point", ("x", "y"))(1, 2), False), ({}, True), - (collections.OrderedDict((('a', 1), ('b', 2))), True), + (collections.OrderedDict((("a", 1), ("b", 2))), True), ), ) def test_is_dict_like(inp, exp): diff --git a/tests/utils/test_lists.py b/tests/utils/test_lists.py index ad987855..d50e33c2 100644 --- a/tests/utils/test_lists.py +++ b/tests/utils/test_lists.py @@ -14,11 +14,11 @@ class TestCase(unittest.TestCase): def test_groupby(self): - items = (('a', 1), ('b', -1), ('c', 1)) + items = (("a", 1), ("b", -1), ("c", 1)) res = TT.groupby(items, operator.itemgetter(1)) self.assertEqual( [(key, tuple(grp)) for key, grp in res], - [(-1, (('b', -1),)), (1, (('a', 1), ('c', 1)))] + [(-1, (("b", -1),)), (1, (("a", 1), ("c", 1)))] ) def test_concat(self):