1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
# Copyright 2012 Canonical
3
# Author: Thomi Richards
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 3, as published
7
# by the Free Software Foundation.
10
from os.path import exists
11
from tempfile import mktemp
12
from testtools.matchers import Contains, Not
13
from time import sleep
16
from autopilot.tests import AutopilotTestCase
17
from autopilot.emulators.unity import (
25
class UnityLoggingTests(AutopilotTestCase):
26
"""Tests for Unity's debug logging framework."""
28
def start_new_log_file(self):
30
start_log_to_file(fpath)
33
def test_new_file_created(self):
34
"""Unity must create log file when we call start_log_to_file.
36
fpath = self.start_new_log_file()
37
self.addCleanup(remove, fpath)
38
self.addCleanup(reset_logging)
40
self.assertTrue(exists(fpath))
42
def test_messages_arrive_in_file(self):
43
fpath = self.start_new_log_file()
44
log_unity_message("WARNING", "This is a warning of things to come")
48
with open(fpath, 'r') as f:
49
self.assertThat(f.read(), Contains("This is a warning of things to come"))
51
def test_default_log_level_unchanged(self):
52
fpath = self.start_new_log_file()
53
log_unity_message("DEBUG", "This is some INFORMATION")
56
with open(fpath, 'r') as f:
57
self.assertThat(f.read(), Not(Contains("This is some INFORMATION")))
59
def test_can_change_log_level(self):
60
fpath = self.start_new_log_file()
61
set_log_severity("", "DEBUG")
62
self.addCleanup(set_log_severity, "", "INFO")
63
log_unity_message("DEBUG", "This is some more INFORMATION")
66
with open(fpath, 'r') as f:
67
self.assertThat(f.read(), Contains("This is some more INFORMATION"))