[Git][reproducible-builds/diffoscope][master] 3 commits: Clarify the logic around the difference between --usage and --help.

Chris Lamb (@lamby) gitlab at salsa.debian.org
Tue May 31 10:12:11 UTC 2022



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
85ef2872 by Chris Lamb at 2022-05-31T11:03:35+01:00
Clarify the logic around the difference between --usage and --help.

- - - - -
60d7a058 by Chris Lamb at 2022-05-31T11:06:02+01:00
Test --help and --usage.

- - - - -
fb191c85 by Chris Lamb at 2022-05-31T11:11:21+01:00
Test that --help includes the file formats.

- - - - -


2 changed files:

- diffoscope/main.py
- tests/test_main.py


Changes:

=====================================
diffoscope/main.py
=====================================
@@ -487,7 +487,8 @@ class HelpFormatter(argparse.HelpFormatter):
     def format_help(self, *args, **kwargs):
         val = super().format_help(*args, **kwargs)
 
-        # Only append the file formats if --help is passed.
+        # Only append the file formats (etc.) if --help is passed; otherwise we
+        # are being called via --usage
         if not set(sys.argv) & {"--help", "-h"}:
             return val
 


=====================================
tests/test_main.py
=====================================
@@ -2,7 +2,7 @@
 # diffoscope: in-depth comparison of files, archives, and directories
 #
 # Copyright © 2015 Jérémy Bobbio <lunar at debian.org>
-# Copyright © 2016-2020 Chris Lamb <lamby at debian.org>
+# Copyright © 2016-2022 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -18,6 +18,7 @@
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
 import os
+import sys
 import pytest
 import signal
 import tempfile
@@ -173,3 +174,20 @@ def test_non_unicode_filename(capsys, tmpdir):
 
     assert ret == 0
     assert out == err == ""
+
+
+def test_help(capsys, monkeypatch):
+    # Fake --help in sys.argv so that we include out file formats in the output
+    monkeypatch.setattr(sys, "argv", ["diffoscope", "--help"])
+
+    ret, out, err = run(capsys, "--help")
+
+    assert err == ""
+    assert "file formats supported:" in out
+
+
+def test_usage(capsys):
+    ret, out, err = run(capsys, "--usage")
+
+    assert out == ""
+    assert "usage:" in err



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/457a208bc3ae53756a73950087f175176328a18d...fb191c8526765c4dc77ccc4860d4c05d3cb9bdc6

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/457a208bc3ae53756a73950087f175176328a18d...fb191c8526765c4dc77ccc4860d4c05d3cb9bdc6
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20220531/867d1682/attachment.htm>


More information about the rb-commits mailing list