aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Ionite <[email protected]>2023-02-22 16:24:56 -0500
committerGravatar Ionite <[email protected]>2023-02-22 16:24:56 -0500
commitd29e8c6c4240a5e9cb5293788529621ee919c0b7 (patch)
tree81080f443bd99efc85ecc10c32e3fa5a656939a2
parentUpdate budget lines and chars for text to be shared with stdout (diff)
Use PurePosixPath so tests work on windows
-rw-r--r--bot/exts/utils/snekbox/_io.py9
-rw-r--r--tests/bot/exts/utils/snekbox/test_io.py6
2 files changed, 5 insertions, 10 deletions
diff --git a/bot/exts/utils/snekbox/_io.py b/bot/exts/utils/snekbox/_io.py
index 404681936..9be396335 100644
--- a/bot/exts/utils/snekbox/_io.py
+++ b/bot/exts/utils/snekbox/_io.py
@@ -4,7 +4,7 @@ from __future__ import annotations
from base64 import b64decode, b64encode
from dataclasses import dataclass
from io import BytesIO
-from pathlib import Path
+from pathlib import PurePosixPath
import regex
from discord import File
@@ -64,12 +64,12 @@ class FileAttachment:
@property
def suffix(self) -> str:
"""Return the file suffix."""
- return Path(self.path).suffix
+ return PurePosixPath(self.path).suffix
@property
def name(self) -> str:
"""Return the file name."""
- return Path(self.path).name
+ return PurePosixPath(self.path).name
@classmethod
def from_dict(cls, data: dict, size_limit: int = FILE_SIZE_LIMIT) -> FileAttachment:
@@ -98,6 +98,5 @@ class FileAttachment:
def to_file(self) -> File:
"""Convert to a discord.File."""
- name = Path(self.path).name
- name = normalize_discord_file_name(name)
+ name = normalize_discord_file_name(self.name)
return File(BytesIO(self.content), filename=name)
diff --git a/tests/bot/exts/utils/snekbox/test_io.py b/tests/bot/exts/utils/snekbox/test_io.py
index a544a2056..bcf1162b8 100644
--- a/tests/bot/exts/utils/snekbox/test_io.py
+++ b/tests/bot/exts/utils/snekbox/test_io.py
@@ -1,5 +1,4 @@
-import platform
-from unittest import TestCase, skipIf
+from unittest import TestCase
# noinspection PyProtectedMember
from bot.exts.utils.snekbox import _io
@@ -7,9 +6,6 @@ from bot.exts.utils.snekbox import _io
class SnekboxIOTests(TestCase):
# noinspection SpellCheckingInspection
- # Skip Windows since both pathlib and os strips the escape sequences
- # and many of these aren't valid Windows file paths
- @skipIf(platform.system() == "Windows", "File names normalizer tests requires Unix-like OS.")
def test_normalize_file_name(self):
"""Invalid file names should be normalized."""
cases = [