2012-01-27 14:17:09 -05:00
|
|
|
import nilmdb
|
2012-12-31 15:52:28 -05:00
|
|
|
from nilmdb.utils.printf import *
|
2012-01-27 14:17:09 -05:00
|
|
|
|
|
|
|
from nose.tools import *
|
|
|
|
from nose.tools import assert_raises
|
|
|
|
from cStringIO import StringIO
|
|
|
|
import sys
|
|
|
|
|
2013-01-05 15:00:34 -05:00
|
|
|
from testutil.helpers import *
|
2012-03-29 17:43:05 -04:00
|
|
|
|
2012-01-27 14:17:09 -05:00
|
|
|
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)
|
2013-03-24 21:28:01 -04:00
|
|
|
except Exception:
|
2012-01-27 14:17:09 -05:00
|
|
|
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")
|