pgp: force protocol/micalg ordering in doctest output. master
authorW. Trevor King <wking@tremily.us>
Sun, 21 Oct 2012 20:05:16 +0000 (16:05 -0400)
committerW. Trevor King <wking@tremily.us>
Sun, 21 Oct 2012 20:05:19 +0000 (16:05 -0400)
The Content-Type header is eventually set by Message.add_header(),
which gets extra parameters from **_params and iterates over them with
_params.items().  _params is a dict, so .items() is not sorted.
Rather than using ELLIPSIS, I thought it was clearer if we explicitly
force our expected ordering in doctest output.

pgp_mime/pgp.py

index d709cfbcaebcc631bc79ca17af9d75a34a35bdab..8adb8083cff1210b6d39cb3f4c31546f556dea06 100644 (file)
@@ -54,7 +54,10 @@ def sign(message, **kwargs):
     >>> message = encodedMIMEText('Hi\nBye')
     >>> signed = sign(message, signers=['pgp-mime@invalid.com'])
     >>> signed.set_boundary('boundsep')
-    >>> print(signed.as_string())  # doctest: +ELLIPSIS, +REPORT_UDIFF
+    >>> print(signed.as_string().replace(
+    ...     'micalg="pgp-sha1"; protocol="application/pgp-signature"',
+    ...     'protocol="application/pgp-signature"; micalg="pgp-sha1"'))
+    ... # doctest: +ELLIPSIS, +REPORT_UDIFF
     Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg="pgp-sha1"; boundary="boundsep"
     MIME-Version: 1.0
     Content-Disposition: inline
@@ -85,7 +88,10 @@ def sign(message, **kwargs):
     >>> message.attach(encodedMIMEText('Part B'))
     >>> signed = sign(message, signers=['pgp-mime@invalid.com'])
     >>> signed.set_boundary('boundsep')
-    >>> print(signed.as_string())  # doctest: +ELLIPSIS, +REPORT_UDIFF
+    >>> print(signed.as_string().replace(
+    ...     'micalg="pgp-sha1"; protocol="application/pgp-signature"',
+    ...     'protocol="application/pgp-signature"; micalg="pgp-sha1"'))
+    ... # doctest: +ELLIPSIS, +REPORT_UDIFF
     Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg="pgp-sha1"; boundary="boundsep"
     MIME-Version: 1.0
     Content-Disposition: inline
@@ -149,7 +155,10 @@ def encrypt(message, recipients=None, **kwargs):
     >>> message['To'] = 'pgp-mime-test <pgp-mime@invalid.com>'
     >>> encrypted = encrypt(message, always_trust=True)
     >>> encrypted.set_boundary('boundsep')
-    >>> print(encrypted.as_string())  # doctest: +ELLIPSIS, +REPORT_UDIFF
+    >>> print(encrypted.as_string().replace(
+    ...     'micalg="pgp-sha1"; protocol="application/pgp-encrypted"',
+    ...     'protocol="application/pgp-encrypted"; micalg="pgp-sha1"'))
+    ... # doctest: +ELLIPSIS, +REPORT_UDIFF
     Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; micalg="pgp-sha1"; boundary="boundsep"
     MIME-Version: 1.0
     Content-Disposition: inline
@@ -180,7 +189,10 @@ def encrypt(message, recipients=None, **kwargs):
     >>> encrypted = encrypt(
     ...     message, recipients=['pgp-mime@invalid.com'], always_trust=True)
     >>> encrypted.set_boundary('boundsep')
-    >>> print(encrypted.as_string()) # doctest: +ELLIPSIS, +REPORT_UDIFF
+    >>> print(encrypted.as_string().replace(
+    ...     'micalg="pgp-sha1"; protocol="application/pgp-encrypted"',
+    ...     'protocol="application/pgp-encrypted"; micalg="pgp-sha1"'))
+    ... # doctest: +ELLIPSIS, +REPORT_UDIFF
     Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; micalg="pgp-sha1"; boundary="boundsep"
     MIME-Version: 1.0
     Content-Disposition: inline
@@ -243,7 +255,10 @@ def sign_and_encrypt(message, signers=None, recipients=None, **kwargs):
     >>> encrypted = sign_and_encrypt(
     ...     message, signers=['pgp-mime@invalid.com'], always_trust=True)
     >>> encrypted.set_boundary('boundsep')
-    >>> print(encrypted.as_string())  # doctest: +ELLIPSIS, +REPORT_UDIFF
+    >>> print(encrypted.as_string().replace(
+    ...     'micalg="pgp-sha1"; protocol="application/pgp-encrypted"',
+    ...     'protocol="application/pgp-encrypted"; micalg="pgp-sha1"'))
+    ... # doctest: +ELLIPSIS, +REPORT_UDIFF
     Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; micalg="pgp-sha1"; boundary="boundsep"
     MIME-Version: 1.0
     Content-Disposition: inline
@@ -275,7 +290,10 @@ def sign_and_encrypt(message, signers=None, recipients=None, **kwargs):
     ...     message, signers=['pgp-mime@invalid.com'],
     ...     recipients=['pgp-mime@invalid.com'], always_trust=True)
     >>> encrypted.set_boundary('boundsep')
-    >>> print(encrypted.as_string()) # doctest: +ELLIPSIS, +REPORT_UDIFF
+    >>> print(encrypted.as_string().replace(
+    ...     'micalg="pgp-sha1"; protocol="application/pgp-encrypted"',
+    ...     'protocol="application/pgp-encrypted"; micalg="pgp-sha1"'))
+    ... # doctest: +ELLIPSIS, +REPORT_UDIFF
     Content-Type: multipart/encrypted; protocol="application/pgp-encrypted"; micalg="pgp-sha1"; boundary="boundsep"
     MIME-Version: 1.0
     Content-Disposition: inline