Complete Python 3 runtime port of installed tools
Debian Trixie package bundle / packages (push) Successful in 22m2s
Debian Trixie package bundle / packages (push) Successful in 22m2s
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
# /****************************************************************************
|
||||
# * <Novell-copyright>
|
||||
# * Copyright (c) 2001 Novell, Inc. All Rights Reserved.
|
||||
# *
|
||||
# * This program is free software; you can redistribute it and/or
|
||||
# * modify it under the terms of version 2 of the GNU General Public License
|
||||
# * as published by the Free Software Foundation.
|
||||
# *
|
||||
# * This program is distributed in the hope that it will be useful,
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# * GNU General Public License for more details.
|
||||
# *
|
||||
# * You should have received a copy of the GNU General Public License
|
||||
# * along with this program; if not, contact Novell, Inc.
|
||||
# *
|
||||
# * To contact Novell about this file by physical or electronic mail, you
|
||||
# * may find current contact information at www.novell.com.
|
||||
# * </Novell-copyright>
|
||||
# ****************************************************************************/
|
||||
|
||||
import io
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from bongo import table
|
||||
from bongo.Console import wrap
|
||||
from bongo.external.simpletal import simpleTAL, simpleTALES
|
||||
from bongo.store.StoreClient import CalendarACL, StoreClient
|
||||
from bongo.storetool.ExportMailbox import MaildirMailbox, MboxMailbox
|
||||
|
||||
|
||||
class _Response:
|
||||
def __init__(self, code, message=""):
|
||||
self.code = code
|
||||
self.message = message
|
||||
|
||||
|
||||
class _Stream:
|
||||
def __init__(self, responses):
|
||||
self.responses = list(responses)
|
||||
self.lines = []
|
||||
self.raw = []
|
||||
|
||||
def Write(self, value):
|
||||
self.lines.append(value)
|
||||
|
||||
def WriteRaw(self, value):
|
||||
self.raw.append(value)
|
||||
|
||||
def GetResponse(self):
|
||||
return self.responses.pop(0)
|
||||
|
||||
|
||||
class Python3RuntimeTests(unittest.TestCase):
|
||||
def test_console_table_and_unicode_template_are_text(self):
|
||||
self.assertIsInstance(wrap("Grüße 世界", width=8), str)
|
||||
self.assertEqual(table.format_table(["Name"], [["Müller"]]),
|
||||
"Name\n------\nMüller")
|
||||
|
||||
context = simpleTALES.Context()
|
||||
context.addGlobal("name", "A&B")
|
||||
template = simpleTAL.compileHTMLTemplate(
|
||||
'<p tal:content="name">placeholder</p>')
|
||||
output = io.StringIO()
|
||||
template.expand(context, output)
|
||||
self.assertEqual(output.getvalue(), "<p>A&B</p>")
|
||||
|
||||
def test_store_wire_lengths_are_encoded_byte_lengths(self):
|
||||
client = object.__new__(StoreClient)
|
||||
client.stream = _Stream([
|
||||
_Response(2002), _Response(1000, "guid ok"),
|
||||
_Response(2002), _Response(1000),
|
||||
_Response(2002), _Response(1000, "guid ok"),
|
||||
])
|
||||
|
||||
client.Write("/mail/INBOX", 2, "Grüße")
|
||||
client.PropSet("guid", "display", "Grüße")
|
||||
client.Replace("guid", "Grüße")
|
||||
|
||||
expected = "Grüße".encode("utf-8")
|
||||
self.assertIn(" 7", client.stream.lines[0])
|
||||
self.assertTrue(client.stream.lines[1].endswith(" 7"))
|
||||
self.assertTrue(client.stream.lines[2].endswith(" 7"))
|
||||
self.assertEqual(client.stream.raw, [expected, expected, expected])
|
||||
|
||||
def test_calendar_share_token_uses_python3_hashlib(self):
|
||||
token = CalendarACL(None)._GetUid("calendar")
|
||||
self.assertEqual(len(token), 32)
|
||||
int(token, 16)
|
||||
|
||||
def test_mailbox_writers_accept_store_bytes(self):
|
||||
message = (
|
||||
b"From: sender@example.test\r\n"
|
||||
b"To: user@example.test\r\n"
|
||||
b"Subject: Python 3\r\n\r\nBody\r\n")
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
mbox_path = root / "mailbox"
|
||||
writer = MboxMailbox(str(mbox_path))
|
||||
writer.add(message)
|
||||
writer.write()
|
||||
self.assertIn(b"Subject: Python 3", mbox_path.read_bytes())
|
||||
|
||||
maildir_path = root / "maildir"
|
||||
writer = MaildirMailbox(str(maildir_path))
|
||||
writer.add(message)
|
||||
writer.write()
|
||||
payloads = [
|
||||
path.read_bytes()
|
||||
for folder in ("new", "cur")
|
||||
for path in (maildir_path / folder).iterdir()
|
||||
]
|
||||
self.assertEqual(len(payloads), 1)
|
||||
self.assertIn(b"Subject: Python 3", payloads[0])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user