wireshark/test
Jeff Widman 8d7ebc732e Fix issues discovered by common python linters
Fix some issues discovered by common python linters including:
* switch `None` comparisons to use `is` rather than `==`. Identity !=
equality, and I've spent 40+ hours before tracking down a subtle bug
caused by exactly this issue. Note that this may introduce a problem if
one of the scripts is depending on this behavior, in which case the
comparison should be changed to `True`/`False` rather than `None`.
* Use `except Exception:` as bare `except:` statements have been
discouraged for years. Ideally for some of these we'd examine if there
were specific exceptions that should be caught, but for now I simply
caught all. Again, this could introduce very subtle behavioral changes
under Python 2, but IIUC, that was all fixed in Python 3, so safe to
move to `except Exception:`.
* Use more idiomatic `if not x in y`--> `if x not in y`
* Use more idiomatic 2 blank lines. I only did this at the beginning,
until I realized how overwhelming this was going to be to apply, then I
stopped.
* Add a TODO where an undefined function name is called, so will fail
whenever that code is run.
* Add more idiomatic spacing around `:`. This is also only partially
cleaned up, as I gave up when I saw how `asn2wrs.py` was clearly
infatuated with the construct.
* Various other small cleanups, removed some trailing whitespace and
improper indentation that wasn't a multiple of 4, etc.

There is still _much_ to do, but I haven't been heavily involved with
this project before, so thought this was a sufficient amount to put up
and see what the feedback is.

Linters that I have enabled which highlighted some of these issues
include:
* `pylint`
* `flake8`
* `pycodestyle`
2020-09-26 04:38:18 +00:00
..
baseline A Community ID implementation for Wireshark. 2020-09-16 09:25:38 -07:00
captures SMB2: add tests for chained compression and pattern_v1 2020-09-26 02:23:23 +00:00
config
keys
lua
suite_dfilter
suite_dissectors
README.test Qt: Add a packet diagram view. 2020-08-10 18:17:50 +00:00
conftest.py
fixtures.py Fix issues discovered by common python linters 2020-09-26 04:38:18 +00:00
fixtures_ws.py
hosts.custom
hosts.global
hosts.personal
matchers.py
sampleif.py
subprocesstest.py Fix issues discovered by common python linters 2020-09-26 04:38:18 +00:00
suite_capture.py Fix issues discovered by common python linters 2020-09-26 04:38:18 +00:00
suite_clopts.py Fix issues discovered by common python linters 2020-09-26 04:38:18 +00:00
suite_decryption.py Test: Normalize the line endings of subprocess output. 2020-09-16 13:35:11 -07:00
suite_dissection.py SMB2: add tests for chained compression and pattern_v1 2020-09-26 02:23:23 +00:00
suite_extcaps.py
suite_fileformats.py
suite_follow.py Test: Normalize the line endings of subprocess output. 2020-09-16 13:35:11 -07:00
suite_io.py
suite_mergecap.py
suite_nameres.py
suite_outputformats.py
suite_release.py
suite_sharkd.py
suite_text2pcap.py Update our issue tracker URL in some places. 2020-09-16 01:29:07 +00:00
suite_unittests.py
suite_wslua.py
test.py Test: Remove an unused routine. 2020-07-08 05:08:23 +00:00
travis-upload-artifacts.sh
util_dump_dhcp_pcap.py

README.test

Wireshark Tests

The recommended steps to prepare for and to run tests:

* Install two Python packages, pytest: `pip install pytest pytest-xdist`
* Build programs (“wireshark”, “tshark”, etc.): `ninja`
* Build additional programs for the “unittests” suite: `ninja test-programs`
* Run tests in the build directory: `pytest`

Replace `ninja test-programs` by `make test-programs` as needed.

See the “Wireshark Tests” chapter of the Developer's Guide for details:
https://www.wireshark.org/docs/wsdg_html_chunked/ChapterTests.html

If you need to update the baseline files use the following commands (on a Linux system)
mkdir ~/.config/wireshark/profiles/ctest
TZ=UTC WIRESHARK_RUN_FROM_BUILD_DIRECTORY=1 build/run/tshark -C ctest -T ek -r test/captures/dhcp.pcap > test/baseline/dhcp.ek
TZ=UTC WIRESHARK_RUN_FROM_BUILD_DIRECTORY=1 build/run/tshark -C ctest -T json -r test/captures/dhcp.pcap > test/baseline/dhcp.json
TZ=UTC WIRESHARK_RUN_FROM_BUILD_DIRECTORY=1 build/run/tshark -C ctest -T jsonraw -r test/captures/dhcp.pcap > test/baseline/dhcp.jsonraw
TZ=UTC WIRESHARK_RUN_FROM_BUILD_DIRECTORY=1 build/run/tshark -C ctest -T ek -r test/captures/dhcp.pcap -x > test/baseline/dhcp-raw.ek