Skip to content

Commit cbf772b

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 1ef64c8 commit cbf772b

1 file changed

Lines changed: 22 additions & 20 deletions

File tree

test/test_dummy.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2020
#
2121

22+
import contextlib
2223
import datetime
2324
import os.path
2425
import pathlib
@@ -387,46 +388,47 @@ def test_getnextfile(self) -> None:
387388
def test_save_ringtone_permissions(self) -> None:
388389
"""Test that SaveRingtone creates files with restrictive permissions."""
389390
# Create a simple ringtone dictionary
390-
ringtone = {
391-
"Name": "Test",
392-
"Notes": [
393-
{"Note": "C", "Duration": 4, "Scale": 1}
394-
]
395-
}
396-
391+
ringtone = {"Name": "Test", "Notes": [{"Note": "C", "Duration": 4, "Scale": 1}]}
392+
397393
# Create a unique temporary file path using a secure method
398394
# We need to close and delete it so SaveRingtone can create it
399-
with tempfile.NamedTemporaryFile(mode='wb', delete=False, suffix='.rttl') as f:
395+
with tempfile.NamedTemporaryFile(mode="wb", delete=False, suffix=".rttl") as f:
400396
temp_file = f.name
401397
os.unlink(temp_file) # Remove it so SaveRingtone can create it fresh
402-
398+
403399
try:
404400
# Save the ringtone
405401
gammu.SaveRingtone(temp_file, ringtone, "rttl")
406-
402+
407403
# Check that the file was created
408404
assert os.path.exists(temp_file)
409-
405+
410406
# Check file permissions - should be owner read/write only
411407
# Skip permission check on Windows as it handles permissions differently
412408
if platform.system() != "Windows":
413409
file_stat = os.stat(temp_file)
414410
file_mode = stat.S_IMODE(file_stat.st_mode)
415-
411+
416412
# File should have owner read/write permissions (0o600)
417413
# Check that group and others don't have any permissions
418-
assert (file_mode & stat.S_IRWXG) == 0, f"Group has permissions: {oct(file_mode)}"
419-
assert (file_mode & stat.S_IRWXO) == 0, f"Others have permissions: {oct(file_mode)}"
420-
414+
assert (file_mode & stat.S_IRWXG) == 0, (
415+
f"Group has permissions: {oct(file_mode)}"
416+
)
417+
assert (file_mode & stat.S_IRWXO) == 0, (
418+
f"Others have permissions: {oct(file_mode)}"
419+
)
420+
421421
# Verify owner has read and write permissions
422-
assert (file_mode & stat.S_IRUSR) != 0, f"Owner missing read permission: {oct(file_mode)}"
423-
assert (file_mode & stat.S_IWUSR) != 0, f"Owner missing write permission: {oct(file_mode)}"
422+
assert (file_mode & stat.S_IRUSR) != 0, (
423+
f"Owner missing read permission: {oct(file_mode)}"
424+
)
425+
assert (file_mode & stat.S_IWUSR) != 0, (
426+
f"Owner missing write permission: {oct(file_mode)}"
427+
)
424428
finally:
425429
# Clean up - use try-except to handle case where file doesn't exist
426-
try:
430+
with contextlib.suppress(FileNotFoundError):
427431
os.unlink(temp_file)
428-
except FileNotFoundError:
429-
pass
430432

431433
def test_incoming_call(self) -> None:
432434
self.check_incoming_call()

0 commit comments

Comments
 (0)