summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2018-06-03 16:37:42 +0200
committerMatěj Cepl <mcepl@cepl.eu>2018-06-03 16:37:42 +0200
commiteecb91038ff27db8b1c71103a2bc3711e2a0b00d (patch)
tree00db272741c5265878815f8c7b375eb163bea691
parentf329e17cf7401eb8ab7f9ae1f6a3833af64b011b (diff)
downloadplay_with_bindings-master.tar.gz
More cffi beauty, some testsHEADmaster
-rw-r--r--rand.py (renamed from cffi_random.py)6
-rw-r--r--test/__init__.py0
-rw-r--r--test/test_rand.py31
3 files changed, 32 insertions, 5 deletions
diff --git a/cffi_random.py b/rand.py
index 5f62e43..285eb98 100644
--- a/cffi_random.py
+++ b/rand.py
@@ -73,10 +73,6 @@ def rand_pseudo_bytes(n: int) -> bytes:
if ret == -1:
RandError("Not supported by the current RAND method.")
elif ret in [0, 1]:
- return (blob, ret)
+ return (bytes(blob), ret)
else:
RandError("Unknown error in RAND_pseudo_bytes")
-
-
-if __name__=='__main__':
- print(rand_bytes())
diff --git a/test/__init__.py b/test/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/__init__.py
diff --git a/test/test_rand.py b/test/test_rand.py
new file mode 100644
index 0000000..76b4d24
--- /dev/null
+++ b/test/test_rand.py
@@ -0,0 +1,31 @@
+import sys
+import unittest
+
+import rand
+
+
+class RandTestCase(unittest.TestCase):
+ def test_rand_status(self):
+ self.assertEqual(rand.rand_status(), 1)
+
+ def test_rand_event(self):
+ if sys.platform == 'win32':
+ self.assertIsNotNone(rand.rand_event(1, 1, 1))
+ else:
+ self.assertIsNone(rand.rand_event(1, 1, 1))
+
+ def test_rand_bytes(self):
+ exp_length = 15
+ r = rand.rand_bytes(exp_length)
+ self.assertIsInstance(r, bytes)
+ self.assertEqual(len(r), exp_length)
+
+ def test_rand_pseudo_bytes(self):
+ exp_length = 15
+ r = rand.rand_pseudo_bytes(exp_length)
+ self.assertIsInstance(r[0], bytes)
+ self.assertEqual(len(r[0]), exp_length)
+ self.assertEqual(r[1], 1)
+
+if __name__ == '__main__':
+ unittest.main()