You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_printf.py 758 B

123456789101112131415161718192021222324252627
  1. import nilmdb
  2. from nilmdb.utils.printf import *
  3. from nose.tools import *
  4. from nose.tools import assert_raises
  5. from io import StringIO
  6. import sys
  7. from testutil.helpers import *
  8. class TestPrintf(object):
  9. def test_printf(self):
  10. old_stdout = sys.stdout
  11. sys.stdout = test1 = StringIO()
  12. test2 = StringIO()
  13. test3 = ""
  14. try:
  15. printf("hello, world: %d", 123)
  16. fprintf(test2, "hello too: %d", 123)
  17. test3 = sprintf("hello three: %d", 123)
  18. except Exception:
  19. sys.stdout = old_stdout
  20. raise
  21. sys.stdout = old_stdout
  22. eq_(test1.getvalue(), "hello, world: 123")
  23. eq_(test2.getvalue(), "hello too: 123")
  24. eq_(test3, "hello three: 123")