OLD | NEW |
1 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) | 1 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions | 4 # modification, are permitted provided that the following conditions |
5 # are met: | 5 # are met: |
6 # 1. Redistributions of source code must retain the above copyright | 6 # 1. Redistributions of source code must retain the above copyright |
7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
8 # 2. Redistributions in binary form must reproduce the above copyright | 8 # 2. Redistributions in binary form must reproduce the above copyright |
9 # notice, this list of conditions and the following disclaimer in the | 9 # notice, this list of conditions and the following disclaimer in the |
10 # documentation and/or other materials provided with the distribution. | 10 # documentation and/or other materials provided with the distribution. |
(...skipping 15 matching lines...) Expand all Loading... |
26 logging module. | 26 logging module. |
27 | 27 |
28 Inherit from the LoggingTestCase class for basic testing needs. For | 28 Inherit from the LoggingTestCase class for basic testing needs. For |
29 more advanced needs (e.g. unit-testing methods that configure logging), | 29 more advanced needs (e.g. unit-testing methods that configure logging), |
30 see the TestLogStream class, and perhaps also the LogTesting class. | 30 see the TestLogStream class, and perhaps also the LogTesting class. |
31 """ | 31 """ |
32 | 32 |
33 import logging | 33 import logging |
34 import unittest | 34 import unittest |
35 | 35 |
| 36 # pylint: disable=invalid-name |
| 37 # Camel-case names are used here to match the style of the TestCase methods. |
| 38 |
36 | 39 |
37 class TestLogStream(object): | 40 class TestLogStream(object): |
38 """Represents a file-like object for unit-testing logging. | 41 """Represents a file-like object for unit-testing logging. |
39 | 42 |
40 This is meant for passing to the logging.StreamHandler constructor. | 43 This is meant for passing to the logging.StreamHandler constructor. |
41 Log messages captured by instances of this object can be tested | 44 Log messages captured by instances of this object can be tested |
42 using self.assertMessages() below. | 45 using self.assertMessages() below. |
43 """ | 46 """ |
44 | 47 |
45 def __init__(self, test_case): | 48 def __init__(self, test_case): |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 return self._log.messages() | 224 return self._log.messages() |
222 | 225 |
223 # FIXME: Add a clearMessages() method for cases where the caller | 226 # FIXME: Add a clearMessages() method for cases where the caller |
224 # deliberately doesn't want to assert every message. | 227 # deliberately doesn't want to assert every message. |
225 | 228 |
226 # See the docstring for LogTesting.assertMessages() for an explanation | 229 # See the docstring for LogTesting.assertMessages() for an explanation |
227 # of why we clear the array of messages after asserting its contents. | 230 # of why we clear the array of messages after asserting its contents. |
228 def assertLog(self, messages): | 231 def assertLog(self, messages): |
229 """Asserts the current array of log messages, and clear its contents.""" | 232 """Asserts the current array of log messages, and clear its contents.""" |
230 self._log.assertMessages(messages) | 233 self._log.assertMessages(messages) |
OLD | NEW |