Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop python<=3.7 support #220

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dbusmock/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: UTF-8
"""Mock D-Bus objects for test suites."""

# This program is free software; you can redistribute it and/or modify it under
Expand Down
1 change: 0 additions & 1 deletion dbusmock/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: UTF-8
"""Main entry point for running mock server."""

# This program is free software; you can redistribute it and/or modify it under
Expand Down
1 change: 0 additions & 1 deletion dbusmock/mockobject.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: UTF-8
"""Mock D-Bus objects for test suites."""

# This program is free software; you can redistribute it and/or modify it under
Expand Down
2 changes: 1 addition & 1 deletion dbusmock/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def start_dbus(conf: Optional[str] = None) -> Tuple[int, str]:
argv.append("--config-file=" + str(conf))
else:
argv.append("--session")
lines = subprocess.check_output(argv, universal_newlines=True).strip().splitlines()
lines = subprocess.check_output(argv, text=True).strip().splitlines()
assert len(lines) == 2, "expected exactly 2 lines of output from dbus-daemon"
# usually the first line is the address, but be lenient and accept any order
try:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
]
dynamic = ["version"]
requires-python = ">=3.6"
requires-python = ">=3.8"

dependencies = ["dbus-python"]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_api_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def fixture_upower_mock(dbusmock_system):

def test_dbusmock_test_template(upower_mock):
assert upower_mock
out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
out = subprocess.check_output(["upower", "--dump"], text=True)
assert "version:" in out
assert "0.99" in out
12 changes: 6 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def start_mock(self, args, wait_name, wait_path, wait_system=False):
self.wait_for_bus_object(wait_name, wait_path, wait_system)

def start_mock_process(self, args):
return subprocess.check_output([sys.executable, "-m", "dbusmock", *args], universal_newlines=True)
return subprocess.check_output([sys.executable, "-m", "dbusmock", *args], text=True)

def test_session_bus(self):
self.start_mock(["com.example.Test", "/", "TestIface"], "com.example.Test", "/")
Expand All @@ -80,7 +80,7 @@ def test_template_upower_explicit_path(self):
def check_upower_running(self):
# check that it actually ran the template, if we have upower
if have_upower:
out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
out = subprocess.check_output(["upower", "--dump"], text=True)
self.assertRegex(out, r"on-battery:\s+no")

mock_out = self.p_mock.stdout.readline()
Expand All @@ -99,7 +99,7 @@ def test_template_conflicting_bus(self):
subprocess.check_output(
[sys.executable, "-m", "dbusmock", "--system", "--session", "-t", "upower"],
stderr=subprocess.STDOUT,
universal_newlines=True,
text=True,
)
err = cm.exception
self.assertEqual(err.returncode, 2)
Expand All @@ -115,7 +115,7 @@ def test_template_parameters(self):

# check that it actually ran the template, if we have upower
if have_upower:
out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
out = subprocess.check_output(["upower", "--dump"], text=True)
self.assertRegex(out, r"daemon-version:\s+0\.99\.0")
self.assertRegex(out, r"on-battery:\s+yes")

Expand All @@ -124,7 +124,7 @@ def test_template_parameters_malformed_json(self):
subprocess.check_output(
[sys.executable, "-m", "dbusmock", "-t", "upower", "-p", '{"DaemonVersion: "0.99.0"}'],
stderr=subprocess.STDOUT,
universal_newlines=True,
text=True,
)
err = cm.exception
self.assertEqual(err.returncode, 2)
Expand All @@ -135,7 +135,7 @@ def test_template_parameters_not_dict(self):
subprocess.check_output(
[sys.executable, "-m", "dbusmock", "-t", "upower", "-p", '"banana"'],
stderr=subprocess.STDOUT,
universal_newlines=True,
text=True,
)
err = cm.exception
self.assertEqual(err.returncode, 2)
Expand Down
24 changes: 12 additions & 12 deletions tests/test_logind.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def setUpClass(cls):
cls.dbus_con = cls.get_dbus(True)

if have_loginctl:
out = subprocess.check_output(["loginctl", "--version"], universal_newlines=True)
out = subprocess.check_output(["loginctl", "--version"], text=True)
cls.version = re.search(r"(\d+)", out.splitlines()[0]).group(1)

def setUp(self):
Expand All @@ -54,30 +54,30 @@ def test_empty(self):
cmd = ["loginctl"]
if self.version >= "209":
cmd.append("--no-legend")
out = subprocess.check_output([*cmd, "list-sessions"], universal_newlines=True)
out = subprocess.check_output([*cmd, "list-sessions"], text=True)
self.assertEqual(out, "")

out = subprocess.check_output([*cmd, "list-seats"], universal_newlines=True)
out = subprocess.check_output([*cmd, "list-seats"], text=True)
self.assertEqual(out, "")

out = subprocess.check_output([*cmd, "list-users"], universal_newlines=True)
out = subprocess.check_output([*cmd, "list-users"], text=True)
self.assertEqual(out, "")

def test_session(self):
(self.p_mock, obj_logind) = self.spawn_server_template("logind", {}, stdout=subprocess.PIPE)

obj_logind.AddSession("c1", "seat0", 500, "joe", True)

out = subprocess.check_output(["loginctl", "list-seats"], universal_newlines=True)
out = subprocess.check_output(["loginctl", "list-seats"], text=True)
self.assertRegex(out, r"(^|\n)seat0\s+")

out = subprocess.check_output(["loginctl", "show-seat", "seat0"], universal_newlines=True)
out = subprocess.check_output(["loginctl", "show-seat", "seat0"], text=True)
self.assertRegex(out, "Id=seat0")
if self.version <= "208":
self.assertRegex(out, "ActiveSession=c1")
self.assertRegex(out, "Sessions=c1")

out = subprocess.check_output(["loginctl", "list-users"], universal_newlines=True)
out = subprocess.check_output(["loginctl", "list-users"], text=True)
self.assertRegex(out, r"(^|\n)\s*500\s+joe\s*")

# note, this does an actual getpwnam() in the client, so we cannot call
Expand All @@ -90,10 +90,10 @@ def test_session(self):
# self.assertRegex(out, 'Sessions=c1')
# self.assertRegex(out, 'State=active')

out = subprocess.check_output(["loginctl", "list-sessions"], universal_newlines=True)
out = subprocess.check_output(["loginctl", "list-sessions"], text=True)
self.assertRegex(out, "c1 +500 +joe +seat0")

out = subprocess.check_output(["loginctl", "show-session", "c1"], universal_newlines=True)
out = subprocess.check_output(["loginctl", "show-session", "c1"], text=True)
self.assertRegex(out, "Id=c1")
self.assertRegex(out, "Class=user")
self.assertRegex(out, "Active=yes")
Expand All @@ -107,7 +107,7 @@ def test_session(self):
)
session_mock.SetLockedHint(True)

out = subprocess.check_output(["loginctl", "show-session", "c1"], universal_newlines=True)
out = subprocess.check_output(["loginctl", "show-session", "c1"], text=True)
self.assertRegex(out, "Id=c1")
self.assertRegex(out, "LockedHint=yes")

Expand All @@ -124,7 +124,7 @@ def test_inhibit(self):
fd = obj_logind.Inhibit("suspend", "testcode", "purpose", "delay")

# Our inhibitor is held
out = subprocess.check_output(["systemd-inhibit"], universal_newlines=True)
out = subprocess.check_output(["systemd-inhibit"], text=True)
self.assertRegex(
out.replace("\n", " "),
"(testcode +[0-9]+ +[^ ]* +[0-9]+ +[^ ]* +suspend purpose delay)|"
Expand All @@ -133,7 +133,7 @@ def test_inhibit(self):

del fd
# No inhibitor is held
out = subprocess.check_output(["systemd-inhibit"], universal_newlines=True)
out = subprocess.check_output(["systemd-inhibit"], text=True)
self.assertRegex(out, "No inhibitors|0 inhibitors listed")


Expand Down
16 changes: 8 additions & 8 deletions tests/test_networkmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,31 @@ def tearDown(self):
self.p_mock.wait()

def read_general(self):
return subprocess.check_output(["nmcli", "--nocheck", "general"], env=self.lang_env, universal_newlines=True)
return subprocess.check_output(["nmcli", "--nocheck", "general"], env=self.lang_env, text=True)

def read_networking(self):
return subprocess.check_output(
["nmcli", "--nocheck", "networking"], env=self.lang_env, universal_newlines=True
["nmcli", "--nocheck", "networking"], env=self.lang_env, text=True
)

def read_connection(self):
return subprocess.check_output(
["nmcli", "--nocheck", "connection"], env=self.lang_env, universal_newlines=True
["nmcli", "--nocheck", "connection"], env=self.lang_env, text=True
)

def read_active_connection(self):
return subprocess.check_output(
["nmcli", "--nocheck", "connection", "show", "--active"], env=self.lang_env, universal_newlines=True
["nmcli", "--nocheck", "connection", "show", "--active"], env=self.lang_env, text=True
)

def read_device(self):
return subprocess.check_output(["nmcli", "--nocheck", "dev"], env=self.lang_env, universal_newlines=True)
return subprocess.check_output(["nmcli", "--nocheck", "dev"], env=self.lang_env, text=True)

def read_device_wifi(self):
return subprocess.check_output(
["nmcli", "--nocheck", "dev", "wifi", "list", "--rescan", "no"],
env=self.lang_env,
universal_newlines=True,
text=True,
)

def test_one_eth_disconnected(self):
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_one_wifi_with_accesspoints(self):

# TODO: for connecting to password protected Wifi we need to implement secrets agent
# https://github.com/martinpitt/python-dbusmock/issues/216
out = subprocess.check_output(["nmcli", "--version"], universal_newlines=True)
out = subprocess.check_output(["nmcli", "--version"], text=True)
m = re.search(r"([1-9.]+[0-9])", out)
assert m, "could not parse version from " + out
if Version(m.group(1)) >= Version("1.49.3"):
Expand Down Expand Up @@ -254,7 +254,7 @@ def test_wifi_with_connection(self):
self.assertEqual(con1, "/org/freedesktop/NetworkManager/Settings/Mock_Con1")

settings = subprocess.check_output(
["nmcli", "--nocheck", "connection", "show", "The_SSID"], env=self.lang_env, universal_newlines=True
["nmcli", "--nocheck", "connection", "show", "The_SSID"], env=self.lang_env, text=True
)
self.assertRegex(settings, r"ipv4.method:\s*auto")
self.assertRegex(settings, r"ipv4.gateway:\s*--")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_notification_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import dbusmock

try:
notify_send_version = subprocess.check_output(["notify-send", "--version"], universal_newlines=True)
notify_send_version = subprocess.check_output(["notify-send", "--version"], text=True)
notify_send_version = notify_send_version.split()[-1]
except (OSError, subprocess.CalledProcessError):
notify_send_version = ""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ofono.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_hangup_all(self):
def test_list_operators(self):
"""list operators"""

out = subprocess.check_output([script_dir / "list-operators"], universal_newlines=True)
out = subprocess.check_output([script_dir / "list-operators"], text=True)
self.assertTrue(out.startswith("[ /ril_0 ]"), out)
self.assertIn("[ /ril_0/operator/op1 ]", out)
self.assertIn("Status = current", out)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_power_profiles_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@ def tearDown(self):
def test_list_profiles(self):
"""List Profiles and check active profile"""

out = subprocess.check_output(["powerprofilesctl"], universal_newlines=True)
out = subprocess.check_output(["powerprofilesctl"], text=True)

self.assertIn("performance:\n", out)
self.assertIn("\n* balanced:\n", out)

def test_change_profile(self):
"""Change ActiveProfile"""

subprocess.check_output(["powerprofilesctl", "set", "performance"], universal_newlines=True)
out = subprocess.check_output(["powerprofilesctl", "get"], universal_newlines=True)
subprocess.check_output(["powerprofilesctl", "set", "performance"], text=True)
out = subprocess.check_output(["powerprofilesctl", "get"], text=True)
self.assertEqual(out, "performance\n")

def run_powerprofilesctl_list_holds(self):
return subprocess.check_output(["powerprofilesctl", "list-holds"], universal_newlines=True)
return subprocess.check_output(["powerprofilesctl", "list-holds"], text=True)

def test_list_holds(self):
"""Test holds"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_timedated.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def tearDown(self):
self.p_mock.wait()

def run_timedatectl(self):
return subprocess.check_output(["timedatectl"], universal_newlines=True)
return subprocess.check_output(["timedatectl"], text=True)

def test_default_timezone(self):
out = self.run_timedatectl()
Expand Down
10 changes: 5 additions & 5 deletions tests/test_upower.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def tearDown(self):
self.p_mock.wait()

def test_no_devices(self):
out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
out = subprocess.check_output(["upower", "--dump"], text=True)
self.assertIn("/DisplayDevice\n", out)
# should not have any other device
for line in out.splitlines():
Expand All @@ -82,7 +82,7 @@ def test_one_ac(self):
b'emit /org/freedesktop/UPower org.freedesktop.UPower.DeviceAdded "/org/freedesktop/UPower/devices/mock_AC"\n',
)

out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
out = subprocess.check_output(["upower", "--dump"], text=True)
self.assertRegex(out, "Device: " + path)
# note, Add* is not magic: this just adds an object, not change
# properties
Expand All @@ -109,7 +109,7 @@ def test_discharging_battery(self):
b'emit /org/freedesktop/UPower org.freedesktop.UPower.DeviceAdded "/org/freedesktop/UPower/devices/mock_BAT"\n',
)

out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
out = subprocess.check_output(["upower", "--dump"], text=True)
self.assertRegex(out, "Device: " + path)
# note, Add* is not magic: this just adds an object, not change
# properties
Expand All @@ -129,7 +129,7 @@ def test_charging_battery(self):
b'emit /org/freedesktop/UPower org.freedesktop.UPower.DeviceAdded "/org/freedesktop/UPower/devices/mock_BAT"\n',
)

out = subprocess.check_output(["upower", "--dump"], universal_newlines=True)
out = subprocess.check_output(["upower", "--dump"], text=True)
self.assertRegex(out, "Device: " + path)
# note, Add* is not magic: this just adds an object, not change
# properties
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_setup_display_device(self):
except KeyError:
pass

out = subprocess.check_output(["upower", "--dump"], universal_newlines=True, env=env)
out = subprocess.check_output(["upower", "--dump"], text=True, env=env)
self.assertIn("/DisplayDevice\n", out)
self.assertIn(" battery\n", out) # type
self.assertRegex(out, r"state:\s+charging")
Expand Down