Adapt notes printing test to arbitrary notes
Marco Ricci

Marco Ricci commited on 2025-02-05 12:07:24
Zeige 1 geänderte Dateien mit 20 Einfügungen und 4 Löschungen.

... ...
@@ -1863,10 +1863,22 @@ class TestCLI:
1863 1863
             map(is_harmless_config_import_warning, caplog.record_tuples)
1864 1864
         ), 'unexpected error output'
1865 1865
 
1866
+    @hypothesis.given(
1867
+        notes=strategies.text(
1868
+            strategies.characters(
1869
+                min_codepoint=32,
1870
+                max_codepoint=126,
1871
+                include_characters='\n',
1872
+            ),
1873
+            max_size=256,
1874
+        ),
1875
+    )
1866 1876
     def test_207_service_with_notes_actually_prints_notes(
1867 1877
         self,
1878
+        notes: str,
1868 1879
     ) -> None:
1869 1880
         """Service notes are printed, if they exist."""
1881
+        hypothesis.assume('Error:' not in notes)
1870 1882
         runner = click.testing.CliRunner(mix_stderr=False)
1871 1883
         # TODO(the-13th-letter): Rewrite using parenthesized
1872 1884
         # with-statements.
... ...
@@ -1883,7 +1895,7 @@ class TestCLI:
1883 1895
                         },
1884 1896
                         'services': {
1885 1897
                             DUMMY_SERVICE: {
1886
-                                'notes': 'Some notes here',
1898
+                                'notes': notes,
1887 1899
                                 **DUMMY_CONFIG_SETTINGS,
1888 1900
                             },
1889 1901
                         },
... ...
@@ -1897,12 +1909,16 @@ class TestCLI:
1897 1909
         result = tests.ReadableResult.parse(result_)
1898 1910
         assert result.clean_exit(), 'expected clean exit'
1899 1911
         assert result.output, 'expected program output'
1900
-        assert result.output.strip() == DUMMY_RESULT_PASSPHRASE.decode('ascii'), 'expected known program output'
1901
-        assert result.stderr, 'expected stderr'
1912
+        assert result.output.strip() == DUMMY_RESULT_PASSPHRASE.decode(
1913
+            'ascii'
1914
+        ), 'expected known program output'
1915
+        assert result.stderr or not notes.strip(), 'expected stderr'
1902 1916
         assert 'Error:' not in result.stderr, (
1903 1917
             'expected no error messages on stderr'
1904 1918
         )
1905
-        assert result.stderr.strip() == 'Some notes here', 'expected known stderr contents'
1919
+        assert result.stderr.strip() == notes.strip(), (
1920
+            'expected known stderr contents'
1921
+        )
1906 1922
 
1907 1923
     @Parametrize.VAULT_CHARSET_OPTION
1908 1924
     def test_210_invalid_argument_range(
1909 1925