From b193370d2018f4a9ba9abf9cfd265dfcfbb24557 Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Sat, 7 Sep 2024 15:58:10 +0200 Subject: [PATCH] Make a test more flexible When testing during packaging for Debian, {bin_name} is quite wide ("python3.12 -m unittest") causing `[--defaults]` to flow to the next line. --- CONTRIBUTORS.md | 1 + tests/test_macsyconfig.py | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 46c47327..518964c1 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -34,3 +34,4 @@ This is a list of people who have made contributions to Macsyfinder. * Nilesh Patra :bug: :computer: * Antônio Camargo :bug: * TrellixVulnTeam :computer: +* Michael R. Crusoe :white_check_mark: diff --git a/tests/test_macsyconfig.py b/tests/test_macsyconfig.py index 2ad6fa90..503327ab 100644 --- a/tests/test_macsyconfig.py +++ b/tests/test_macsyconfig.py @@ -22,19 +22,19 @@ # If not, see . # ########################################################################## import argparse -import os.path import io +import os.path +import re +import shutil import sys import tempfile -import shutil from unittest.mock import patch -from tests import MacsyTest - +import macsypy.scripts.macsyconfig as msf_cfg from macsypy import __version__ as msf_vers -from macsypy.config import MacsyDefaults, Config +from macsypy.config import Config, MacsyDefaults from macsypy.error import MacsypyError -import macsypy.scripts.macsyconfig as msf_cfg +from tests import MacsyTest class TestConfigParserWithComment(MacsyTest): @@ -598,9 +598,19 @@ def test_parse_args(self): # if the tests are ran from cmd line python tests/run_tes.py ... the bin name is run_test.py # if the tests are ran from setup python setup.py test the bin name is setup.py bin_name = os.path.split(sys.argv[0])[-1] - self.assertEqual(stderr, - f"""usage: {bin_name} [-h] [--no-color | --white-bg | --dark-bg] [--defaults] -{bin_name}: error: argument --dark-bg: not allowed with argument --white-bg""") + self.assertTrue( + re.match( + re.escape( + f"usage: {bin_name} [-h] [--no-color | --white-bg | --dark-bg]" + ) + + r"\s+" + + re.escape( + f"""[--defaults] +{bin_name}: error: argument --dark-bg: not allowed with argument --white-bg""" + ), + stderr, + ) + ) finally: argparse._sys.exit = real_sys_exit