mac and posix tests converted, removed BaseTestCase and unittest

This commit is contained in:
bigtedde 2023-07-26 21:59:12 -07:00
parent f33efc0a10
commit d2dd792164
1 changed files with 44 additions and 51 deletions

View File

@ -5,6 +5,8 @@ import sys
import tempfile import tempfile
import unittest import unittest
import pytest
from ..platformflags import is_win32 from ..platformflags import is_win32
from ..platform import acl_get, acl_set, swidth from ..platform import acl_get, acl_set, swidth
from ..platform import get_process_id, process_alive from ..platform import get_process_id, process_alive
@ -161,68 +163,59 @@ class PlatformLinuxTestCase(BaseTestCase):
self.assert_equal(acl_use_local_uid_gid(b"group:root:rw-:0"), b"group:0:rw-") self.assert_equal(acl_use_local_uid_gid(b"group:root:rw-:0"), b"group:0:rw-")
@unittest.skipUnless(sys.platform.startswith("darwin"), "macOS only test") @pytest.mark.skipif(not sys.platform.startswith("darwin"), reason="macOS only test")
@unittest.skipIf(fakeroot_detected(), "not compatible with fakeroot") @pytest.mark.skipif(fakeroot_detected(), reason="not compatible with fakeroot")
class PlatformDarwinTestCase(BaseTestCase): @pytest.mark.skipIf(not are_acls_working(), "ACLs do not work")
def setUp(self): def test_platform_darwin_access_acl(tmp_path):
self.tmpdir = tempfile.mkdtemp() def get_acl(path, numeric_ids=False):
def tearDown(self):
shutil.rmtree(self.tmpdir)
def get_acl(self, path, numeric_ids=False):
item = {} item = {}
acl_get(path, item, os.stat(path), numeric_ids=numeric_ids) acl_get(path, item, os.stat(path), numeric_ids=numeric_ids)
return item return item
def set_acl(self, path, acl, numeric_ids=False): def set_acl(path, acl, numeric_ids=False):
item = {"acl_extended": acl} item = {"acl_extended": acl}
acl_set(path, item, numeric_ids=numeric_ids) acl_set(path, item, numeric_ids=numeric_ids)
@unittest.skipIf(not are_acls_working(), "ACLs do not work") file = tempfile.NamedTemporaryFile()
def test_access_acl(self): file2 = tempfile.NamedTemporaryFile()
file = tempfile.NamedTemporaryFile() assert get_acl(file.name) == {}
file2 = tempfile.NamedTemporaryFile() set_acl(
self.assert_equal(self.get_acl(file.name), {}) file.name,
self.set_acl( b"!#acl 1\n"
file.name, b"group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000000:staff:0:allow:read\n"
b"!#acl 1\n" b"user:FFFFEEEE-DDDD-CCCC-BBBB-AAAA00000000:root:0:allow:read\n",
b"group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000000:staff:0:allow:read\n" numeric_ids=False,
b"user:FFFFEEEE-DDDD-CCCC-BBBB-AAAA00000000:root:0:allow:read\n", )
numeric_ids=False, assert b"group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000014:staff:20:allow:read" in get_acl(file.name)["acl_extended"]
) assert b"user:FFFFEEEE-DDDD-CCCC-BBBB-AAAA00000000:root:0:allow:read" in get_acl(file.name)["acl_extended"]
self.assert_in(
b"group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000014:staff:20:allow:read", self.get_acl(file.name)["acl_extended"] set_acl(
) file2.name,
self.assert_in( b"!#acl 1\n"
b"user:FFFFEEEE-DDDD-CCCC-BBBB-AAAA00000000:root:0:allow:read", self.get_acl(file.name)["acl_extended"] b"group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000000:staff:0:allow:read\n"
) b"user:FFFFEEEE-DDDD-CCCC-BBBB-AAAA00000000:root:0:allow:read\n",
self.set_acl( numeric_ids=True,
file2.name, )
b"!#acl 1\n" assert b"group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000000:wheel:0:allow:read" in get_acl(file2.name)["acl_extended"]
b"group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000000:staff:0:allow:read\n" assert (
b"user:FFFFEEEE-DDDD-CCCC-BBBB-AAAA00000000:root:0:allow:read\n", b"group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000000::0:allow:read"
numeric_ids=True, in get_acl(file2.name, numeric_ids=True)["acl_extended"]
) )
self.assert_in(
b"group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000000:wheel:0:allow:read", self.get_acl(file2.name)["acl_extended"]
)
self.assert_in(
b"group:ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000000::0:allow:read",
self.get_acl(file2.name, numeric_ids=True)["acl_extended"],
)
@unittest.skipUnless(sys.platform.startswith(("linux", "freebsd", "darwin")), "POSIX only tests") @pytest.mark.skipif(not sys.platform.startswith(("linux", "freebsd", "darwin")), reason="POSIX only tests")
class PlatformPosixTestCase(BaseTestCase): def test_platform_posix_swidth_ascii():
def test_swidth_ascii(self): assert swidth("borg") == 4
self.assert_equal(swidth("borg"), 4)
def test_swidth_cjk(self):
self.assert_equal(swidth("バックアップ"), 6 * 2)
def test_swidth_mixed(self): @pytest.mark.skipif(not sys.platform.startswith(("linux", "freebsd", "darwin")), reason="POSIX only tests")
self.assert_equal(swidth("borgバックアップ"), 4 + 6 * 2) def test_platform_posix_swidth_cjk():
assert swidth("バックアップ") == 6 * 2
@pytest.mark.skipif(not sys.platform.startswith(("linux", "freebsd", "darwin")), reason="POSIX only tests")
def test_splatform_posix_width_mixed():
assert swidth("borgバックアップ") == 4 + 6 * 2
def test_process_alive(free_pid): def test_process_alive(free_pid):