launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #14501
[Merge] lp:~jtv/maas/sample-binary-data into lp:maas
Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/sample-binary-data into lp:maas.
Commit message:
Make sample "tough testing" binary data reusable.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jtv/maas/sample-binary-data/+merge/135870
This takes some diff distraction out of the main branch I'm working on. I'm adding yet more uses of this sample data which we already had in two places. It's important to test binary-data functionality against the nastiest data possible, or we will miss subtle bugs. So we need to make it easy to get right!
No pre-imp; I think the change is obvious enough.
Jeroen
--
https://code.launchpad.net/~jtv/maas/sample-binary-data/+merge/135870
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/sample-binary-data into lp:maas.
=== modified file 'src/maasserver/tests/test_filestorage.py'
--- src/maasserver/tests/test_filestorage.py 2012-11-08 06:34:48 +0000
+++ src/maasserver/tests/test_filestorage.py 2012-11-23 11:22:34 +0000
@@ -12,12 +12,12 @@
__metaclass__ = type
__all__ = []
-import codecs
from io import BytesIO
from maasserver.models import FileStorage
from maasserver.testing.factory import factory
from maasserver.testing.testcase import TestCase
+from maastesting.utils import sample_binary_data
class FileStorageTest(TestCase):
@@ -55,21 +55,8 @@
(storage.filename, storage.content))
def test_stores_binary_data(self):
- # This horrible binary data could never, ever, under any
- # encoding known to man be interpreted as text(1). Switch the
- # bytes of the byte-order mark around and by design you get an
- # invalid codepoint; put a byte with the high bit set between bytes
- # that have it cleared, and you have a guaranteed non-UTF-8
- # sequence.
- #
- # (1) Provided, of course, that man know only about ASCII and
- # UTF.
- binary_data = codecs.BOM64_LE + codecs.BOM64_BE + b'\x00\xff\x00'
-
- # And yet, because FileStorage supports binary data, it comes
- # out intact.
- storage = factory.make_file_storage(filename="x", content=binary_data)
- self.assertEqual(binary_data, storage.content)
+ storage = factory.make_file_storage(content=sample_binary_data)
+ self.assertEqual(sample_binary_data, storage.content)
def test_overwrites_file(self):
# If a file of the same name has already been stored, the
=== modified file 'src/maastesting/utils.py'
--- src/maastesting/utils.py 2012-07-16 10:19:46 +0000
+++ src/maastesting/utils.py 2012-11-23 11:22:34 +0000
@@ -17,8 +17,10 @@
"get_write_time",
"preexec_fn",
"retries",
+ "sample_binary_data",
]
+import codecs
import os
import re
import signal
@@ -90,3 +92,16 @@
sleep(min(delay, end - now))
else:
break
+
+
+# Some horrible binary data that could never, ever, under any encoding
+# known to man(1) survive mis-interpretation as text.
+#
+# The data contains a nul byte to trip up accidental string termination.
+# Switch the bytes of the byte-order mark around and by design you get
+# an invalid codepoint; put a byte with the high bit set between bytes
+# that have it cleared, and you have a guaranteed non-UTF-8 sequence.
+#
+# (1) Provided, of course, that man know only about ASCII and
+# UTF.
+sample_binary_data = codecs.BOM64_LE + codecs.BOM64_BE + b'\x00\xff\x00'
=== modified file 'src/metadataserver/tests/test_commissioningscript.py'
--- src/metadataserver/tests/test_commissioningscript.py 2012-11-22 11:53:01 +0000
+++ src/metadataserver/tests/test_commissioningscript.py 2012-11-23 11:22:34 +0000
@@ -12,11 +12,11 @@
__metaclass__ = type
__all__ = []
-import codecs
from random import randint
from maasserver.testing.factory import factory
from maasserver.testing.testcase import TestCase
+from maastesting.utils import sample_binary_data
from metadataserver.fields import Bin
from metadataserver.models import CommissioningScript
@@ -35,9 +35,7 @@
def test_scripts_may_be_binary(self):
name = make_script_name()
- # Some binary data that would break just about any kind of text
- # interpretation.
- binary = Bin(codecs.BOM64_LE + codecs.BOM64_BE + b'\x00\xff\x00')
- CommissioningScript.objects.create(name=name, content=binary)
+ CommissioningScript.objects.create(
+ name=name, content=Bin(sample_binary_data))
stored_script = CommissioningScript.objects.get(name=name)
- self.assertEqual(binary, stored_script.content)
+ self.assertEqual(sample_binary_data, stored_script.content)