nilmdb/tests/test_printf.py
Jim Paris f355c73209 Refactor utility classes into nilmdb.utils subdir/namespace
There's some bug with the testing harness where placing e.g.
  from du import du
in nilmdb/utils/__init__.py doesn't quite work -- sometimes the
module "du" replaces the function "du".  Not exactly sure why;
we work around that by just renaming files so they don't match
the imported names directly.
2012-12-31 15:55:36 -05:00

28 lines
751 B
Python

import nilmdb
from nilmdb.utils.printf import *
from nose.tools import *
from nose.tools import assert_raises
from cStringIO import StringIO
import sys
from test_helpers import *
class TestPrintf(object):
def test_printf(self):
old_stdout = sys.stdout
sys.stdout = test1 = StringIO()
test2 = StringIO()
test3 = ""
try:
printf("hello, world: %d", 123)
fprintf(test2, "hello too: %d", 123)
test3 = sprintf("hello three: %d", 123)
except:
sys.stdout = old_stdout
raise
sys.stdout = old_stdout
eq_(test1.getvalue(), "hello, world: 123")
eq_(test2.getvalue(), "hello too: 123")
eq_(test3, "hello three: 123")