import unittest from BaDCA import Logging from BaDCA.Testing import * class BaDCAbaseCATestCase(unittest.TestCase): def test01(self): """ Testing basic creation of Log instance """ l = Logging.Log() assert l.isValid() == 0, "Log should be invalid!" assert l.setDirectory('.') == 1, "Error setting directory" assert l.setDirectory('foo') == 0, "Error, able to set to non-existant directory!" def test02(self): """ Test creation of a log file """ l = Logging.Log(directory = 'tests/logs', name='basic') assert l.isValid(), "Log should be valid" assert l.openLog() == 1, "Error opening log file" assert l.closeLog() == 1, "Error closing log file" def test03(self): """ Test creation and writing to a log file with simple string""" l = Logging.Log(directory = 'tests/logs', name='basic2') assert l.isValid(), "Log should be valid" assert l.openLog() == 1, "Error opening log file" l.Log("Hello world") assert l.closeLog() == 1, "Error closing log file" def test04(self): """ Test creation and writing to a log file with strings """ l = Logging.Log(directory = 'tests/logs', name='basic3') assert l.isValid(), "Log should be valid" assert l.openLog() == 1, "Error opening log file" l.Log("%s %s", 'hello', 'world' ) assert l.closeLog() == 1, "Error closing log file" def test05(self): """ Test creation and writing to a log file with mixed types""" l = Logging.Log(directory = 'tests/logs', name='basic4') assert l.isValid(), "Log should be valid" assert l.openLog() == 1, "Error opening log file" l.Log("number = %d, string = '%s'", 123, 'hello world' ) assert l.closeLog() == 1, "Error closing log file" if __name__ == "__main__": unittest.main()