aboutsummaryrefslogtreecommitdiffstats
path: root/test/suite_dfilter/dfiltertest.py
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-11-15 12:38:12 +0100
committerPeter Wu <peter@lekensteyn.nl>2018-11-15 22:57:40 +0000
commitd631c17eee0ade675f6f4a0612ce0b127e44ee72 (patch)
tree318ee4ce11cd510776d39b5c4941b1be9b833c44 /test/suite_dfilter/dfiltertest.py
parentd38ab1bde0f1183ecfdec2a4aa8d2d202c2302a9 (diff)
test: convert suite_dfilter to use fixtures
Stop using subprocesstest, drop the (now redundant) DFTestCase base class and use pytest-style fixtures to inject the dependency on tshark. This approach makes it easier to switch to pytest in the future. Most substitutions were automated, so no typos should be present. Change-Id: I3516029162f87423816937410ff63507ff82e96f Reviewed-on: https://code.wireshark.org/review/30649 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'test/suite_dfilter/dfiltertest.py')
-rw-r--r--test/suite_dfilter/dfiltertest.py53
1 files changed, 32 insertions, 21 deletions
diff --git a/test/suite_dfilter/dfiltertest.py b/test/suite_dfilter/dfiltertest.py
index 8ac1786ec8..52fb5f9d12 100644
--- a/test/suite_dfilter/dfiltertest.py
+++ b/test/suite_dfilter/dfiltertest.py
@@ -2,35 +2,46 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
-import config
-import os.path
-import subprocesstest
+import subprocess
+import fixtures
-class DFTestCase(subprocesstest.SubprocessTestCase):
- """Base class for all tests in this dfilter-test collection."""
-
- def runDFilter(self, dfilter, expected_return=0):
- # Create the tshark command
- return self.assertRun((config.cmd_tshark,
+@fixtures.fixture
+def dfilter_cmd(cmd_tshark, capture_file, request):
+ def wrapped(dfilter):
+ return (
+ cmd_tshark,
"-n", # No name resolution
"-r", # Next arg is trace file to read
- os.path.join(config.capture_dir, self.trace_file),
+ capture_file(request.instance.trace_file),
"-Y", # packet display filter (used to be -R)
dfilter
- ), expected_return=expected_return)
+ )
+ return wrapped
- def assertDFilterCount(self, dfilter, expected_count):
+@fixtures.fixture
+def checkDFilterCount(dfilter_cmd, base_env):
+ def checkDFilterCount_real(dfilter, expected_count):
"""Run a display filter and expect a certain number of packets."""
+ output = subprocess.check_output(dfilter_cmd(dfilter),
+ universal_newlines=True,
+ stderr=subprocess.STDOUT,
+ env=base_env)
- dfilter_proc = self.runDFilter(dfilter)
-
- dfp_count = self.countOutput()
+ dfp_count = output.count("\n")
msg = "Expected %d, got: %s" % (expected_count, dfp_count)
- self.assertEqual(dfp_count, expected_count, msg)
-
- def assertDFilterFail(self, dfilter):
- """Run a display filter and expect tshark to fail"""
-
- dfilter_proc = self.runDFilter(dfilter, expected_return=self.exit_error)
+ assert dfp_count == expected_count, msg
+ return checkDFilterCount_real
+
+
+@fixtures.fixture
+def checkDFilterFail(dfilter_cmd, base_env):
+ def checkDFilterFail_real(dfilter):
+ """Run a display filter and expect tshark to fail."""
+ exitcode = subprocess.call(dfilter_cmd(dfilter),
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.STDOUT,
+ env=base_env)
+ assert exitcode == 2, 'Expected process to fail, got %d' % (exitcode,)
+ return checkDFilterFail_real