mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
test_filesystem: try to sort out bytes vs str
This commit is contained in:
parent
c4289f2d47
commit
71360130e6
2 changed files with 15 additions and 17 deletions
|
@ -179,7 +179,7 @@ def test_json(tmp_path):
|
|||
|
||||
@pytest.fixture
|
||||
def test_yaml(tmp_path):
|
||||
test_yaml = yaml.dump({"foo": "bar"})
|
||||
test_yaml = yaml.dump({"foo": "bar"}, encoding='utf-8')
|
||||
test_file = tmp_path / "test.txt"
|
||||
test_file.write_bytes(test_yaml)
|
||||
return test_file
|
||||
|
@ -189,7 +189,7 @@ def test_yaml(tmp_path):
|
|||
def test_toml(tmp_path):
|
||||
test_toml = toml.dumps({"foo": "bar"})
|
||||
test_file = tmp_path / "test.txt"
|
||||
test_file.write_bytes(str(test_toml))
|
||||
test_file.write_bytes(test_toml.encode('utf-8'))
|
||||
return test_file
|
||||
|
||||
|
||||
|
@ -198,14 +198,14 @@ def test_ldif(tmp_path):
|
|||
test_file = tmp_path / "test.txt"
|
||||
from ldif import LDIFWriter
|
||||
|
||||
writer = LDIFWriter(open(str(test_file), "wb"))
|
||||
writer = LDIFWriter(open(str(test_file), "w"))
|
||||
|
||||
writer.unparse(
|
||||
"mail=alice@example.com",
|
||||
{
|
||||
"cn": ["Alice Alison"],
|
||||
"mail": ["alice@example.com"],
|
||||
"objectclass": ["top", "person"],
|
||||
"cn": [b"Alice Alison"],
|
||||
"mail": [b"alice@example.com"],
|
||||
"objectclass": [b"top", b"person"],
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
@ -121,16 +121,16 @@ def test_read_ldif(test_ldif):
|
|||
dn, entry = read_ldif(str(test_ldif))[0]
|
||||
|
||||
assert dn == "mail=alice@example.com"
|
||||
assert entry["mail"] == ["alice@example.com"]
|
||||
assert entry["objectclass"] == ["top", "person"]
|
||||
assert entry["cn"] == ["Alice Alison"]
|
||||
assert entry["mail"] == [b"alice@example.com"]
|
||||
assert entry["objectclass"] == [b"top", b"person"]
|
||||
assert entry["cn"] == [b"Alice Alison"]
|
||||
|
||||
dn, entry = read_ldif(str(test_ldif), ["objectclass"])[0]
|
||||
|
||||
assert dn == "mail=alice@example.com"
|
||||
assert entry["mail"] == ["alice@example.com"]
|
||||
assert entry["mail"] == [b"alice@example.com"]
|
||||
assert "objectclass" not in entry
|
||||
assert entry["cn"] == ["Alice Alison"]
|
||||
assert entry["cn"] == [b"Alice Alison"]
|
||||
|
||||
|
||||
def test_read_ldif_cannot_ioerror(test_ldif, mocker):
|
||||
|
@ -465,10 +465,9 @@ def test_chown_exception(test_file, mocker):
|
|||
chown(str(test_file), 1)
|
||||
|
||||
translation = m18n.g(
|
||||
"error_changing_file_permissions", path=test_file, error=str(error)
|
||||
"error_changing_file_permissions", path=str(test_file), error=str(error)
|
||||
)
|
||||
expected_msg = translation.format(path=test_file, error=str(error))
|
||||
assert expected_msg in str(exception)
|
||||
assert translation in str(exception)
|
||||
|
||||
|
||||
def test_chmod(test_file):
|
||||
|
@ -504,10 +503,9 @@ def test_chmod_exception(test_file, mocker):
|
|||
chmod(str(test_file), 0o000)
|
||||
|
||||
translation = m18n.g(
|
||||
"error_changing_file_permissions", path=test_file, error=str(error)
|
||||
"error_changing_file_permissions", path=str(test_file), error=str(error)
|
||||
)
|
||||
expected_msg = translation.format(path=test_file, error=str(error))
|
||||
assert expected_msg in str(exception)
|
||||
assert translation in str(exception)
|
||||
|
||||
|
||||
def test_remove_file(test_file):
|
||||
|
|
Loading…
Add table
Reference in a new issue