mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-13 15:35:08 +00:00
batch 2 - update Python idiom to 3.7 using pyupgrade (#11342)
* batch 2 - update Python idiom to 3.7 using pyupgrade * Apply suggestions from code review
This commit is contained in:
parent
9e363c9f94
commit
266d9d3fb0
19 changed files with 64 additions and 70 deletions
|
|
@ -34,13 +34,13 @@ def inventory():
|
|||
|
||||
|
||||
def load_txt_data(path):
|
||||
with open(path, "r") as f:
|
||||
with open(path) as f:
|
||||
s = f.read()
|
||||
return s
|
||||
|
||||
|
||||
def load_yml_data(path):
|
||||
with open(path, "r") as f:
|
||||
with open(path) as f:
|
||||
d = yaml.safe_load(f)
|
||||
return d
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ def test_verify_file_bad_config(inventory):
|
|||
|
||||
|
||||
def get_vm_pool_json():
|
||||
with open("tests/unit/plugins/inventory/fixtures/opennebula_inventory.json", "r") as json_file:
|
||||
with open("tests/unit/plugins/inventory/fixtures/opennebula_inventory.json") as json_file:
|
||||
jsondata = json.load(json_file)
|
||||
|
||||
data = type("pyone.bindings.VM_POOLSub", (object,), {"VM": []})()
|
||||
|
|
@ -349,15 +349,13 @@ keyed_groups:
|
|||
# note the vm_pool (and json data file) has four hosts,
|
||||
# but the options above asks ansible to filter one out
|
||||
assert len(get_vm_pool_json().VM) == 4
|
||||
assert set(vm.NAME for vm in get_vm_pool_json().VM) == set(
|
||||
[
|
||||
"terraform_demo_00",
|
||||
"terraform_demo_01",
|
||||
"terraform_demo_srv_00",
|
||||
"bs-windows",
|
||||
]
|
||||
)
|
||||
assert set(im._inventory.hosts) == set(["terraform_demo_00", "terraform_demo_01", "terraform_demo_srv_00"])
|
||||
assert {vm.NAME for vm in get_vm_pool_json().VM} == {
|
||||
"terraform_demo_00",
|
||||
"terraform_demo_01",
|
||||
"terraform_demo_srv_00",
|
||||
"bs-windows",
|
||||
}
|
||||
assert set(im._inventory.hosts) == {"terraform_demo_00", "terraform_demo_01", "terraform_demo_srv_00"}
|
||||
|
||||
host_demo00 = im._inventory.get_host("terraform_demo_00")
|
||||
host_demo01 = im._inventory.get_host("terraform_demo_01")
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ from ansible_collections.community.general.plugins.lookup.onepassword import (
|
|||
|
||||
|
||||
def load_file(file):
|
||||
with open((os.path.join(os.path.dirname(__file__), "onepassword_fixtures", file)), "r") as f:
|
||||
with open(os.path.join(os.path.dirname(__file__), "onepassword_fixtures", file)) as f:
|
||||
return json.loads(f.read())
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ class TestLookupModule(unittest.TestCase):
|
|||
def test_bitwarden_plugin_duplicates(self):
|
||||
# There are two records with name dupe_name; we need to be order-insensitive with
|
||||
# checking what was retrieved.
|
||||
self.assertEqual(set(["b", "d"]), set(self.lookup.run(["dupe_name"], field="password")[0]))
|
||||
self.assertEqual({"b", "d"}, set(self.lookup.run(["dupe_name"], field="password")[0]))
|
||||
|
||||
@patch("ansible_collections.community.general.plugins.lookup.bitwarden._bitwarden", new=MockBitwarden())
|
||||
def test_bitwarden_plugin_full_item(self):
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ class TestInterfacesFileModule(unittest.TestCase):
|
|||
with open(testfilepath, "wb") as f:
|
||||
f.write(string.encode())
|
||||
else:
|
||||
with open(testfilepath, "r") as goldenfile:
|
||||
with open(testfilepath) as goldenfile:
|
||||
goldenData = json.load(goldenfile)
|
||||
self.assertEqual(goldenData, ifaces)
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ class TestInterfacesFileModule(unittest.TestCase):
|
|||
f.write(string.encode())
|
||||
f.close()
|
||||
else:
|
||||
with open(testfilepath, "r") as goldenfile:
|
||||
with open(testfilepath) as goldenfile:
|
||||
goldenstring = goldenfile.read()
|
||||
goldenfile.close()
|
||||
self.assertEqual(goldenstring, string)
|
||||
|
|
|
|||
|
|
@ -245,9 +245,7 @@ class TestPermanentParams(ModuleTestCase):
|
|||
with patch("ansible_collections.community.general.plugins.modules.modprobe.Modprobe.modprobe_files"):
|
||||
modprobe.modprobe_files = ["/etc/modprobe.d/dummy1.conf", "/etc/modprobe.d/dummy2.conf"]
|
||||
|
||||
assert modprobe.permanent_params == set(
|
||||
["numdummies=4", "dummy_parameter1=6", "dummy_parameter2=5"]
|
||||
)
|
||||
assert modprobe.permanent_params == {"numdummies=4", "dummy_parameter1=6", "dummy_parameter2=5"}
|
||||
|
||||
def test_module_permanent_params_empty(self):
|
||||
files_content = ["", ""]
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ valid_inventory = {
|
|||
"sed": "4.8-1",
|
||||
"sqlite": "3.36.0-1",
|
||||
},
|
||||
"installed_groups": {"base-devel": set(["gawk", "grep", "file", "findutils", "pacman", "sed", "gzip", "gettext"])},
|
||||
"installed_groups": {"base-devel": {"gawk", "grep", "file", "findutils", "pacman", "sed", "gzip", "gettext"}},
|
||||
"available_pkgs": {
|
||||
"acl": "2.3.1-1",
|
||||
"amd-ucode": "20211027.1d00989-1",
|
||||
|
|
@ -61,35 +61,33 @@ valid_inventory = {
|
|||
"sudo": "1.9.8.p2-3",
|
||||
},
|
||||
"available_groups": {
|
||||
"base-devel": set(
|
||||
[
|
||||
"libtool",
|
||||
"gawk",
|
||||
"which",
|
||||
"texinfo",
|
||||
"fakeroot",
|
||||
"grep",
|
||||
"findutils",
|
||||
"autoconf",
|
||||
"gzip",
|
||||
"pkgconf",
|
||||
"flex",
|
||||
"patch",
|
||||
"groff",
|
||||
"m4",
|
||||
"bison",
|
||||
"gcc",
|
||||
"gettext",
|
||||
"make",
|
||||
"file",
|
||||
"pacman",
|
||||
"sed",
|
||||
"automake",
|
||||
"sudo",
|
||||
"binutils",
|
||||
]
|
||||
),
|
||||
"some-group": set(["libtool", "sudo", "binutils"]),
|
||||
"base-devel": {
|
||||
"libtool",
|
||||
"gawk",
|
||||
"which",
|
||||
"texinfo",
|
||||
"fakeroot",
|
||||
"grep",
|
||||
"findutils",
|
||||
"autoconf",
|
||||
"gzip",
|
||||
"pkgconf",
|
||||
"flex",
|
||||
"patch",
|
||||
"groff",
|
||||
"m4",
|
||||
"bison",
|
||||
"gcc",
|
||||
"gettext",
|
||||
"make",
|
||||
"file",
|
||||
"pacman",
|
||||
"sed",
|
||||
"automake",
|
||||
"sudo",
|
||||
"binutils",
|
||||
},
|
||||
"some-group": {"libtool", "sudo", "binutils"},
|
||||
},
|
||||
"upgradable_pkgs": {
|
||||
"sqlite": VersionTuple(current="3.36.0-1", latest="3.37.0-1"),
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class UTHelper:
|
|||
for ext in extensions:
|
||||
test_spec_filename = test_module.__file__.replace(".py", ext)
|
||||
if os.path.exists(test_spec_filename):
|
||||
with open(test_spec_filename, "r") as test_spec_filehandle:
|
||||
with open(test_spec_filename) as test_spec_filehandle:
|
||||
return UTHelper.from_file(ansible_module, test_module, test_spec_filehandle, mocks=mocks)
|
||||
|
||||
raise Exception(
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ def test_make_unsafe_dict_key():
|
|||
|
||||
|
||||
def test_make_unsafe_set():
|
||||
value = set([_make_trusted("test")])
|
||||
value = {_make_trusted("test")}
|
||||
if not SUPPORTS_DATA_TAGGING:
|
||||
value.add(_make_trusted(b"test"))
|
||||
unsafe_value = make_unsafe(value)
|
||||
|
|
@ -147,7 +147,7 @@ def test_make_unsafe_set():
|
|||
for obj in unsafe_value:
|
||||
assert _is_trusted(obj)
|
||||
|
||||
value = set([_make_trusted("{{test}}")])
|
||||
value = {_make_trusted("{{test}}")}
|
||||
if not SUPPORTS_DATA_TAGGING:
|
||||
value.add(_make_trusted(b"{{test}}"))
|
||||
unsafe_value = make_unsafe(value)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue