def test_get_content(self): log = _log.Log(".") log.content = ["test"] self.assertEqual( log.get_content(), _strings.strings["prefix_timestamp_spacing"] + _strings.strings["prefix_spacing"] + _about.name + " " + _about.version + " \"" + _about.codename + "\" build date:" + _about.build_date + "\n\ntest\n")
def test_schedule(self): log = _log.Log("Tests/Temp") control = _control.Control("Tests/Temp") self.assertTrue(control.load(log)) now = datetime.datetime.now() control.schedule("itstime.json", 1) self.assertEqual( control.properties["itstime.json"], (now + datetime.timedelta(seconds=1)).strftime("%Y-%m-%d %H-%M-%S"))
def test_write(self): log = _log.Log("Tests/Temp") log.content = ["test"] log.write() fl = open(log.path, "r") text = fl.read() fl.close() self.assertEqual( text, _strings.strings["prefix_timestamp_spacing"] + _strings.strings["prefix_spacing"] + _about.name + " " + _about.version + " \"" + _about.codename + "\" build date:" + _about.build_date + "\n\ntest\n")
def test_write(self): log = _log.Log("Tests/Temp") control = _control.Control("Tests/Temp") self.assertTrue(control.load(log)) now = datetime.datetime.now() control.schedule("itstime.json", 1) self.assertTrue(control.write(log)) self.assertFalse(log.error_occurred) self.assertFalse(log.warning_occurred) self.assertFalse(log.sync_occurred) self.assertTrue(os.path.isfile(control.path)) log = _log.Log("Tests/Temp") log.path = "Tests/Temp/Logs/Error.txt" control = _control.Control("Tests/TempWRONG") self.assertFalse(control.load(log)) self.assertFalse(control.write(log)) self.assertTrue(log.error_occurred) self.assertFalse(log.warning_occurred) self.assertFalse(log.sync_occurred) # ensures that the log is written right away when needed (critical=True) self.assertTrue(os.path.isfile("Tests/Temp/Logs/Error.txt"))
def test_load(self): log = _log.Log("Tests/Temp") control = _control.Control("Tests/Temp") self.assertTrue(control.load(log)) self.assertFalse(log.error_occurred) self.assertFalse(log.warning_occurred) self.assertFalse(log.sync_occurred) control = _control.Control("Tests/TempWRONG") self.assertFalse(control.load(log)) self.assertTrue(log.error_occurred) self.assertFalse(log.warning_occurred) self.assertFalse(log.sync_occurred)
def test_insert(self): # will test all strings in all languages for language in _strings.languages: _strings.strings = _strings.languages[language] for string in _strings.strings.keys(): if string.startswith("email"): continue log = _log.Log(".") detail = "test" log.insert(string, detail=detail) self.assertEqual(log.content[0][18:], _strings.strings[string] + detail)
def test_init(self): log = _log.Log("Tests/Temp") self.assertTrue(log.path.startswith("Tests/Temp")) self.assertTrue(log.path.endswith(".txt")) self.assertFalse(log.error_occurred) self.assertFalse(log.warning_occurred) self.assertFalse(log.sync_occurred) self.assertEqual(log.content, []) self.assertEqual(log.summary, []) self.assertEqual(log.repeated_line, "") self.assertEqual(log.repeated_count, 0)
def test_report(self): # will test all strings in all languages for language in _strings.languages: _strings.strings = _strings.languages[language] for string in _strings.strings.keys(): if string.startswith("email"): continue log = _log.Log(".") detail = "test" log.report(string, detail=detail) if string.startswith("ok"): self.assertFalse(log.error_occurred) self.assertFalse(log.warning_occurred) self.assertFalse(log.sync_occurred) elif string.startswith("warning"): self.assertFalse(log.error_occurred) self.assertTrue(log.warning_occurred) self.assertFalse(log.sync_occurred) elif string.startswith("error"): self.assertTrue(log.error_occurred) self.assertFalse(log.warning_occurred) self.assertFalse(log.sync_occurred) elif string.startswith("message"): self.assertFalse(log.error_occurred) self.assertFalse(log.warning_occurred) self.assertFalse(log.sync_occurred) elif string.startswith("prefix"): self.assertFalse(log.error_occurred) self.assertFalse(log.warning_occurred) self.assertFalse(log.sync_occurred)
import _control import _paths import os import logging if __name__ == "__main__": logging.getLogger("eyed3").setLevel(logging.CRITICAL) # hides the eyed3 console output root = os.path.dirname(os.path.realpath(__file__)) # filesystem path to this python file first_run = True # helps with the startup delay while True: log = _log.Log(root) # logs all program operations config = _config.Config(root) # main configuration file control = _control.Control(root) # controls the sync schedule email = _email.Email() # email sent to the user, if asked if not config.load(log): # loads the main config file raise SystemExit # force close if an error occurred if not control.load(log): # loads the schedule file raise SystemExit # force close if an error occurred if first_run: # will sleep the startup delay if this is the first program loop first_run = False config.run_startup_delay(log) log.report("") # indentation of the log file
def test_its_time(self): log = _log.Log("Tests/Temp") control = _control.Control("Tests/Temp") self.assertTrue(control.load(log)) self.assertTrue(control.its_time("itstime.json")) self.assertFalse(control.its_time("notyet.json"))