diff options
| author | Torsten Marek <shlomme@gmail.com> | 2014-03-30 11:59:11 -0700 |
|---|---|---|
| committer | Torsten Marek <shlomme@gmail.com> | 2014-03-30 11:59:11 -0700 |
| commit | 4a81459f3051dbc9be9ae2f5436d6efd0164ee0d (patch) | |
| tree | 52a2825875df08597215a6ba7c4f1f1d1eeb0157 /testutils.py | |
| parent | 753a264e10bbe534150ffd449c96fe7e2b3a64a7 (diff) | |
| download | pylint-4a81459f3051dbc9be9ae2f5436d6efd0164ee0d.tar.gz | |
Add a new command line option '-u' to test/test_func to automatically create or update expected messages files.
Diffstat (limited to 'testutils.py')
| -rw-r--r-- | testutils.py | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/testutils.py b/testutils.py index 17af707..818a576 100644 --- a/testutils.py +++ b/testutils.py @@ -237,6 +237,9 @@ class LintTestUsingModule(testlib.TestCase): for name, file in self.depends] self._test(tocheck) + def _check_result(self, got): + self.assertMultiLineEqual(self._get_expected(), got) + def _test(self, tocheck): if INFO_TEST_RGX.match(self.module): self.linter.enable('I') @@ -251,18 +254,17 @@ class LintTestUsingModule(testlib.TestCase): print ex ex.__str__ = exception_str raise - got = self.linter.reporter.finalize() - self.assertMultiLineEqual(self._get_expected(), got) + self._check_result(self.linter.reporter.finalize()) + def _has_output(self): + return not self.module.startswith('func_noerror_') def _get_expected(self): - if self.module.startswith('func_noerror_'): - expected = '' + if self._has_output() and self.output: + with open(self.output, 'U') as fobj: + return fobj.read().strip() + '\n' else: - output = open(self.output, 'U') - expected = output.read().strip() + '\n' - output.close() - return expected + return '' class LintTestUsingFile(LintTestUsingModule): @@ -274,6 +276,18 @@ class LintTestUsingFile(LintTestUsingModule): tocheck += [join(self.INPUT_DIR, name) for name, _file in self.depends] self._test(tocheck) +class LintTestUpdate(LintTestUsingModule): + + _TEST_TYPE = 'update' + + def _check_result(self, got): + if self._has_output(): + if got != self._get_expected(): + if not self.output: + self.output = join(self.MSG_DIR, '%s.txt' % (self.module,)) + with open(self.output, 'w') as fobj: + fobj.write(got) + # Callback def cb_test_gen(base_class): |
