diff options
| author | Micah Anderson <micah@riseup.net> | 2013-11-14 16:35:32 -0500 | 
|---|---|---|
| committer | Micah Anderson <micah@riseup.net> | 2013-11-14 16:35:32 -0500 | 
| commit | c8b79bf686113c3418d8d65ff0a1920da2b409bc (patch) | |
| tree | 4c76ad4dcedcbd25d653d261ad5033bf21911f0f /tests/test_scrypt_py3x.py | |
initial commit
Diffstat (limited to 'tests/test_scrypt_py3x.py')
| -rw-r--r-- | tests/test_scrypt_py3x.py | 56 | 
1 files changed, 56 insertions, 0 deletions
| diff --git a/tests/test_scrypt_py3x.py b/tests/test_scrypt_py3x.py new file mode 100644 index 0000000..e03e098 --- /dev/null +++ b/tests/test_scrypt_py3x.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- + +from sys import version_info + +if ((version_info > (3, 2, 0, 'final', 0)) or +    (version_info > (2, 7, 0, 'final', 0) and version_info < (3, 0, 0, 'final', 0))): +    import unittest as testm +else: +    try: +        import unittest2 as testm +    except ImportError: +        print("Please install unittest2 to run the test suite") +        exit(-1) + +import scrypt + + +@testm.skipIf(version_info < (3, 0, 0, 'final', 0), "Tests for Python 3 only") +class TestScryptForPy3(testm.TestCase): + +    def setUp(self): +        self.input = "message" +        self.password = "password" +        self.byte_text = b'\xe1\x93\x84\xe1\x93\x87\xe1\x95\x97\xe1\x92\xbb\xe1\x92\xa5\xe1\x90\x85\xe1\x91\xa6' +        self.unicode_text = self.byte_text.decode('utf-8', "strict") + +    def test_py3_encrypt_allows_bytes_input(self): +        """Test Py3 encrypt allows unicode input""" +        s = scrypt.encrypt(self.byte_text, self.password, 0.1) +        m = scrypt.decrypt(s, self.password) +        self.assertEqual(bytes(m.encode("utf-8")), self.byte_text) + +    def test_py3_encrypt_allows_bytes_password(self): +        """Test Py3 encrypt allows unicode password""" +        s = scrypt.encrypt(self.input, self.byte_text, 0.1) +        m = scrypt.decrypt(s, self.byte_text) +        self.assertEqual(m, self.input) + +    def test_py3_encrypt_returns_bytes(self): +        """Test Py3 encrypt return bytes""" +        s = scrypt.encrypt(self.input, self.password, 0.1) +        self.assertTrue(isinstance(s, bytes)) + +    def test_py3_decrypt_returns_unicode_string(self): +        """Test Py3 decrypt returns Unicode UTF-8 string""" +        s = scrypt.encrypt(self.input, self.password, 0.1) +        m = scrypt.decrypt(s, self.password) +        self.assertTrue(isinstance(m, str)) + +    def test_py3_hash_returns_bytes(self): +        """Test Py3 hash return bytes""" +        h = scrypt.hash(self.input, self.password) +        self.assertTrue(isinstance(h, bytes)) + +if __name__ == "__main__": +    testm.main() | 
