diff options
author | Peter Wu <peter@lekensteyn.nl> | 2018-11-13 02:17:33 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2018-11-14 05:00:37 +0000 |
commit | 4f61d77293c29c7363cca00b56a282eeeec575f1 (patch) | |
tree | 7fdcced832d170de4160cab7431fa5fae70782be /test/suite_unittests.py | |
parent | 50433f4b4dde42ce50b0e2d899671c2b2cef526d (diff) |
test: convert some more tests to use fixtures
Continue the conversion from use of globals (the config module) to
fixtures. If a program (like wmem_test or tshark) is unavailable, it
will be skipped now rather than failing the test.
The general conversion pattern is:
- Decorate each class with `@fixtures.uses_fixtures` and (for tests that
run tshark) `@fixtures.mark_usefixtures('test_env')`.
- Convert all `config.cmd_*` to `cmd_*` and add an argument.
- Convert all `config.*_dir` to `dirs.*_dir` and add an argument.
- Convert users of `os.path.join(dirs.capture_file, ...)` to use a new
'capture_file' fixture to reduce boilerplate code. Inline variables if
possible (this conversion was done in an automated way using regexes).
Some other changes: tests that do not require a test environment (like
wmem_test) will use 'base_env' which avoids copying config files,
`env=config.test_env` got removed since this is the default. Some test
classes in suite_clopts were combined. Removed unused imports.
Change-Id: Id5480ffaee7d8d56cf2cb3189a38ae9afa7605a1
Reviewed-on: https://code.wireshark.org/review/30591
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'test/suite_unittests.py')
-rw-r--r-- | test/suite_unittests.py | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/test/suite_unittests.py b/test/suite_unittests.py index 1233807a10..94621ed7fa 100644 --- a/test/suite_unittests.py +++ b/test/suite_unittests.py @@ -14,48 +14,49 @@ import config import difflib import os.path -import pprint import re import subprocesstest -import unittest +import fixtures + +@fixtures.uses_fixtures class case_unittests(subprocesstest.SubprocessTestCase): - def test_unit_exntest(self): + def test_unit_exntest(self, program, base_env): '''exntest''' - self.assertRun(os.path.join(config.program_path, 'exntest')) + self.assertRun(program('exntest'), env=base_env) - def test_unit_oids_test(self): + def test_unit_oids_test(self, program, base_env): '''oids_test''' - self.assertRun(os.path.join(config.program_path, 'oids_test')) + self.assertRun(program('oids_test'), env=base_env) - def test_unit_reassemble_test(self): + def test_unit_reassemble_test(self, program, base_env): '''reassemble_test''' - self.assertRun(os.path.join(config.program_path, 'reassemble_test')) + self.assertRun(program('reassemble_test'), env=base_env) - def test_unit_tvbtest(self): + def test_unit_tvbtest(self, program, base_env): '''tvbtest''' - self.assertRun(os.path.join(config.program_path, 'tvbtest')) + self.assertRun(program('tvbtest'), env=base_env) - def test_unit_wmem_test(self): + def test_unit_wmem_test(self, program, base_env): '''wmem_test''' - self.assertRun((os.path.join(config.program_path, 'wmem_test'), + self.assertRun((program('wmem_test'), '--verbose' - )) + ), env=base_env) - def test_unit_wmem_test(self): + def test_unit_wmem_test(self, program, base_env): '''wmem_test''' - self.assertRun((os.path.join(config.program_path, 'wmem_test'), + self.assertRun((program('wmem_test'), '--verbose' - )) + ), env=base_env) - def test_unit_fieldcount(self): + def test_unit_fieldcount(self, cmd_tshark, test_env): '''fieldcount''' - self.assertRun((config.cmd_tshark, '-G', 'fieldcount')) + self.assertRun((cmd_tshark, '-G', 'fieldcount'), env=test_env) def test_unit_ctest_coverage(self): '''Make sure CTest runs all of our tests.''' - with open(os.path.join(config.this_dir, '..', 'CMakeLists.txt')) as cml_fd: - group_re = re.compile('set *\( *_test_group_list') + with open(os.path.join(os.path.dirname(__file__), '..', 'CMakeLists.txt')) as cml_fd: + group_re = re.compile(r'set *\( *_test_group_list') in_list = False cml_groups = [] for cml_line in cml_fd: @@ -95,10 +96,12 @@ class Field: self.bitmask = int(data[6],0) self.blurb = data[7] + +@fixtures.uses_fixtures class case_unit_ftsanity(subprocesstest.SubprocessTestCase): - def test_unit_ftsanity(self): + def test_unit_ftsanity(self, cmd_tshark, base_env): """Looks for problems in field type definitions.""" - tshark_proc = self.assertRun((config.cmd_tshark, "-G", "fields")) + tshark_proc = self.assertRun((cmd_tshark, "-G", "fields"), env=base_env) lines = tshark_proc.stdout_str.splitlines() # XXX We don't currently check protos. |