X-Git-Url: https://v.licheni.net/stack/cam.git/blobdiff_plain/de74ecfb399e9c18e476104744856fde67ea2e81..112c04e3926d62291efd902a1dcb0b2d24feeb59:/cam/tests/test_utils.py diff --git a/cam/tests/test_utils.py b/cam/tests/test_utils.py new file mode 100644 index 0000000..e583622 --- /dev/null +++ b/cam/tests/test_utils.py @@ -0,0 +1,38 @@ +import os +import unittest +import tempfile +from cam import utils + + +class UtilsTest(unittest.TestCase): + + def setUp(self): + self.old_template_dir = utils._template_dir + self.tmpdir = tempfile.mkdtemp() + utils._template_dir = self.tmpdir + + def tearDown(self): + os.system('rm -fr "%s"' % self.tmpdir) + utils._template_dir = self.old_template_dir + + def test_render(self): + tf = os.path.join(utils._template_dir, 'test') + tfd = open(tf, 'w') + tfd.write('this is a %(sub)s\n') + tfd.close() + of = os.path.join(self.tmpdir, 'test.out') + utils.render(of, 'test', {'sub':'TEST'}) + self.assert_(os.path.exists(of)) + output = open(of, 'r').read() + self.assertEquals('this is a TEST\n', output) + + def test_parse_bool(self): + self.assertTrue(utils.parse_bool('y')) + self.assertTrue(utils.parse_bool('1')) + self.assertTrue(utils.parse_bool('true')) + self.assertFalse(utils.parse_bool('false')) + self.assertFalse(utils.parse_bool('no')) + + +if __name__ == '__main__': + unittest.main()