Commits

Gora Khargosh committed 6952ddc

Migrates all code to use mom.tests instead.

* Doctests are simply stupid.

Signed-off-by: Gora Khargosh <gora.khargosh@gmail.com>

Comments (0)

Files changed (13)

mom/codec/__init__.py

 
 This is the same as doing::
 
-    >>> import math
-    >>> math.log(64, 2)    # number 64, base 2.
+    import math
+    math.log(64, 2)    # 6.0; number 64, base 2.
     6.0
 
 read as "logarithm to the base 2 of 64" which gives 6. That is, if
 The concept of **roots** or radicals is also related. Roots help you find the
 base (radix) given the exponent and the number. So::
 
-    >>> root(8, 3)   # cube root. exponent 3, number 8.
-    2.0              # base
+    root(8, 3)   # 2.0; cube root. exponent 3, number 8.
 
 .. pull-quote::
 
 we would need a way to represent each of the 256**4 (4294967296) values with
 our encoding::
 
-    >>> 256**4
-    4294967296
-    >>> 2**32
-    4294967296
+    256**4 # 4294967296
+    2**32  # 4294967296
 
 Given an encoding alphabet of 85 ASCII characters, for example, we need
 to find an exponent (logarithm) that allows us to represent each one of these
 4294967296 values::
 
-    >>> 85**4
-    52200625
-    >>> 85**5
-    4437053125
+    85**4 # 52200625
+    85**5 # 4437053125
+
     >>> 85**5 >= 2**32
     True
 
 Done using logarithms::
 
-    >>> import math
-    >>> math(2**32, 85)
-    4.9926740807112
+    import math
+    math.log(2**32, 85)   # 4.9926740807111996
 
 Therefore, we would need 5 characters from this encoding alphabet to represent
 4 bytes. Since 85 is not a power of 2, there is going to be a little wastage
 byte sequence will be more compact than its base-16 (hexadecimal)
 representation, for example::
 
-    >>> import math
-    >>> math(2**32, 16)
-    8.0
+    import math
+    math.log(2**32, 16)   # 8.0
 
 As you can see, if we used hexadecimal representation instead, each 4-byte
 chunk would be represented using 8 characters from the encoding alphabet.

mom/tests/constants.py

 from mom._compat import have_python3
 
 if have_python3:
-    from tests.py3kconstants import \
+    from mom.tests.py3kconstants import \
         unicode_string, unicode_string2, foo, ufoo, \
         json_foo, json_ufoo, json_unicode_value, unicode_value, x_byte, \
         utf8_bytes, utf8_bytes2, latin1_bytes
 else:
-    from tests.py2kconstants import \
+    from mom.tests.py2kconstants import \
         unicode_string, unicode_string2, foo, ufoo, \
         json_foo, json_ufoo, json_unicode_value, unicode_value, x_byte, \
         utf8_bytes, utf8_bytes2, latin1_bytes

mom/tests/py3kconstants.py

 #!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
+from mom.builtins import b
+
 unicode_string = '\u00ae'
 unicode_string2 = '深入 Python'
-foo = b'foo'
+foo = b('foo')
 ufoo = 'foo'
-json_foo = b'"foo"'
+json_foo = b('"foo"')
 json_ufoo = '"foo"'
 json_unicode_value = '"\u00e9"'
 unicode_value = '\u00e9'
-x_byte = b"\xe9"
-utf8_bytes = b'\xc2\xae'
-utf8_bytes2 = b'\xe6\xb7\xb1\xe5\x85\xa5 Python'
-latin1_bytes = b"\xe9"
+x_byte = b("\xe9")
+utf8_bytes = b('\xc2\xae')
+utf8_bytes2 = b('\xe6\xb7\xb1\xe5\x85\xa5 Python')
+latin1_bytes = b("\xe9")

mom/tests/test_mom_builtins.py

 import struct
 from mom._alt_builtins import integer_byte_length_shift_counting, integer_byte_length_word_aligned, integer_bit_length_shift_counting, integer_bit_length_word_aligned
 from mom._compat import get_word_alignment, MACHINE_WORD_SIZE, UINT64_MAX, UINT32_MAX, UINT16_MAX, UINT8_MAX, ZERO_BYTE
-from mom.functional import leading, trailing
 from mom.security.random import generate_random_bytes
 from mom.builtins import \
     is_unicode, \
     integer_byte_length, \
     integer_bit_length, \
     is_sequence,\
-\
     is_odd, \
     is_even, \
     is_negative, \
 
 try:
     unicode
-    from tests.constants import unicode_string, unicode_string2, \
+    from mom.tests.constants import unicode_string, unicode_string2, \
         utf8_bytes, utf8_bytes2, latin1_bytes
 except NameError:
-    from tests.py3kconstants import unicode_string, unicode_string2, \
+    from mom.tests.py3kconstants import unicode_string, unicode_string2, \
         utf8_bytes, utf8_bytes2, latin1_bytes
 
 unicode_string = unicode_string

mom/tests/test_mom_codec.py

     bytes_to_uint, \
     uint_to_bytes
 from mom.prime_sieve import sieve
-from tests.test_mom_builtins import unicode_string
+from mom.tests.test_mom_builtins import unicode_string
 
 # Generates a 1024-bit strength random byte string.
 random_bytes_1024 = generate_random_bytes(1024 >> 3)

mom/tests/test_mom_codec_base85.py

 import os
 import unittest2
 from mom.builtins import b
-from tests.constants import unicode_string
-from tests.test_mom_builtins import unicode_string2
+from mom.tests.constants import unicode_string
+from mom.tests.test_mom_builtins import unicode_string2
 
 from mom.codec.base85 import b85decode, b85encode, ipv6_b85encode, \
     ipv6_b85decode, ASCII85_PREFIX, ASCII85_SUFFIX, rfc1924_b85encode, \

mom/tests/test_mom_codec_json.py

 import unittest2
 from mom.codec.json import json_encode, json_decode
 from mom.codec.text import utf8_encode
-try:
-    unicode
-    from tests.constants import ufoo, json_ufoo, json_foo, \
-        json_unicode_value, unicode_value, x_byte
-except NameError:
-    from tests.py3kconstants import ufoo, json_ufoo, json_foo, \
-        json_unicode_value, unicode_value, x_byte
-
+from mom.tests.constants import *
 
 class Test_decode(unittest2.TestCase):
     def test_decode(self):

mom/tests/test_mom_codec_text.py

     to_unicode_if_bytes, bytes_to_unicode, utf8_encode, \
     utf8_encode_recursive, bytes_to_unicode_recursive, \
     utf8_decode, utf8_decode_if_bytes
-
-from tests.test_mom_builtins import \
-    unicode_string, utf8_bytes, unicode_string2, utf8_bytes2, latin1_bytes
-
+from mom.tests.constants import *
 
 class Test_to_utf8_if_unicode(unittest2.TestCase):
     def test_encodes_unicode_strings(self):

mom/tests/test_mom_net_scheme_data.py

 from mom.builtins import b
 from mom.codec import base64_decode
 from mom.net.scheme.data import data_urlencode, data_urlparse
-from tests.test_mom_builtins import unicode_string
+from mom.tests.constants import unicode_string
 
 png = b('''\
 \x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x05\x00\x00\x00\x05\

mom/tests/test_mom_security_hash.py

 from mom.security.hash import sha1_hex_digest, md5_digest, \
     sha1_digest, sha1_base64_digest, md5_hex_digest, md5_base64_digest, \
     hmac_sha1_digest, hmac_sha1_base64_digest
-
-from tests.test_mom_builtins import unicode_string, unicode_string2
+from mom.tests.constants import unicode_string, unicode_string2
 
 input_md5_digest = b('\xe8\x0bP\x17\t\x89P\xfcX\xaa\xd8<\x8c\x14\x97\x8e')
 input_sha1_digest = b('\x1f\x8a\xc1\x0f#\xc5\xb5\xbc\x11g\xbd\xa8K\x83>\\\x05zw\xd2')

run_speed_tests.py

 # -*- coding: utf-8 -*-
 
 import sys
-from tests.speed import report
+from mom.tests.speed import report
 
 setups = [
     "from mom.codec.base58 import b58encode; import os; b = os.urandom(3079)",
 import unittest2 as unittest
 
 current_path = os.path.abspath(os.path.dirname(__file__))
-tests_path = os.path.join(current_path, 'tests')
+tests_path = os.path.join(current_path, 'mom', 'tests')
 sys.path[0:0] = [
     current_path,
     tests_path,
 envlist = py25,py26,py27,py32,pypy
 
 [pytest]
-addopts = -n4 -v --cov mom --cov-report term-missing --doctest-modules
+# Add -v for verbosity.
+addopts = -n4 --cov mom --cov-report term-missing --doctest-modules
 
 [testenv]
-#commands=coverage erase
-#         coverage run run_tests.py
-#         coverage report -m
-#         #coverage html -d htmlcov
-#commands=coverage run py.test
 commands=py.test []
 
 [testenv:py25]
      PyTest
      pytest-xdist
      pytest-cov
+     sphinx
 
 [testenv:py26]
 deps=pyasn1 >=0.0.13
      PyTest
      pytest-xdist
      pytest-cov
+     sphinx
 
 [testenv:py27]
 deps=pyasn1 >=0.0.13
      PyTest
      pytest-xdist
      pytest-cov
+     sphinx
 
 [testenv:py32]
 deps=coverage >= 3.5
      PyTest
      pytest-xdist
      pytest-cov
+     sphinx
 
 [testenv:pypy]
 deps=pyasn1 >=0.0.13
      coverage >= 3.5
+     PyCrypto >=2.3
      unittest2
      PyTest
      pytest-xdist
      pytest-cov
+     sphinx