Skip to content
This repository
Browse code

Adding unit tests for new subprocessio module.

  • Loading branch information...
commit acd899398729c2a105c7e7ed0410a40d4ebe0601 1 parent 9e73752
D. Dotsenko authored January 30, 2011

Showing 1 changed file with 78 additions and 0 deletions. Show diff stats Hide diff stats

  1. 78  test_subprocessio.py
78  test_subprocessio.py
... ...
@@ -0,0 +1,78 @@
  1
+import random
  2
+import unittest
  3
+import subprocessio
  4
+import tempfile
  5
+
  6
+class MainTestCase(unittest.TestCase):
  7
+
  8
+    def getiter(self, cmd, input):
  9
+        try:
  10
+            return subprocessio.SubprocessIOChunker(
  11
+                cmd,
  12
+                input,
  13
+                buffer_size = 65536,
  14
+                chunk_size = 4096
  15
+                )
  16
+        except (EnvironmentError) as e:
  17
+            # just because.
  18
+            print str(e)
  19
+            raise e
  20
+
  21
+    def setUp(self):
  22
+        pass
  23
+
  24
+    def tearDown(self):
  25
+        pass
  26
+
  27
+    def test_01_string_throughput(self):
  28
+        cmd = 'cat'
  29
+        input = 'This is a test string'
  30
+        _r = self.getiter(
  31
+            cmd,
  32
+            input
  33
+            )
  34
+        self.assertEqual(
  35
+            "".join(_r),
  36
+            input
  37
+            )
  38
+
  39
+    def test_02_io_throughput(self):
  40
+        cmd = 'cat'
  41
+        size = 128000
  42
+        i = size
  43
+        input = tempfile.TemporaryFile()
  44
+        checksum = 0
  45
+        while i:
  46
+            _r = random.randrange(32,255)
  47
+            checksum += _r
  48
+            input.write(chr(_r))
  49
+            i -= 1
  50
+        input.seek(0)
  51
+
  52
+        _r = self.getiter(
  53
+            cmd,
  54
+            input
  55
+            )
  56
+
  57
+        for e in _r:
  58
+            size -= len(e)
  59
+            for l in e:
  60
+                checksum -= ord(l)
  61
+
  62
+        self.assertEqual(
  63
+            size,
  64
+            0
  65
+            )
  66
+
  67
+        self.assertEqual(
  68
+            checksum,
  69
+            0
  70
+            )
  71
+
  72
+
  73
+if __name__ == "__main__":
  74
+    unittest.TextTestRunner(verbosity=2).run(
  75
+        unittest.TestSuite([
  76
+            unittest.TestLoader().loadTestsFromTestCase(MainTestCase),
  77
+        ])
  78
+    )

0 notes on commit acd8993

Please sign in to comment.
Something went wrong with that request. Please try again.