1+ import re
2+
13import pytest
2- from PyQt6 .QtWidgets import QWidget
4+ from PyQt6 .QtWidgets import QApplication , QPushButton , QWidget
35
4- from ert .config import ErrorInfo
6+ from ert .config import ErrorInfo , WarningInfo
57from ert .gui .ertwidgets import Suggestor
8+ from ert .gui .ertwidgets .suggestor .suggestor import _CopyAllButton
69
710
811@pytest .mark .parametrize (
@@ -21,3 +24,56 @@ def test_suggestor_combines_errors_with_the_same_message(qtbot, errors, expected
2124 msg_layout = msgs .layout ()
2225 assert msg_layout is not None
2326 assert msg_layout .count () == expected_num
27+
28+
29+ def test_that_copy_all_button_concatenates_errors_warnings_and_deprecations (qtbot ):
30+ errors = [ErrorInfo ("error" , filename = "script.py" , line = "5" )]
31+ warnings = [WarningInfo ("warning" , filename = "script.py" , line = "6" )]
32+ deprecations = [
33+ WarningInfo ("deprecation" , filename = "script.py" , line = "7" , is_deprecation = True )
34+ ]
35+ suggestor = Suggestor (errors , warnings , deprecations , lambda : None )
36+
37+ all_buttons = suggestor .findChildren (QPushButton )
38+ copy_all_button = next (
39+ button for button in all_buttons if isinstance (button , _CopyAllButton )
40+ )
41+ copy_all_button .click ()
42+
43+ expected_clipboard = """error
44+ script.py: Line 5
45+
46+ warning
47+ script.py: Line 6
48+
49+ deprecation
50+ script.py: Line 7"""
51+
52+ def remove_whitespaces (s : str ) -> str :
53+ return re .sub (r"\s+" , "" , s )
54+
55+ assert remove_whitespaces (QApplication .clipboard ().text ()) == remove_whitespaces (
56+ expected_clipboard
57+ )
58+
59+
60+ @pytest .mark .parametrize (
61+ "errors" ,
62+ [
63+ [ErrorInfo ("error" )] * 2 ,
64+ [ErrorInfo ("error" , filename = "script.py" , line = "5" )] * 2 ,
65+ ],
66+ )
67+ def test_that_copy_all_button_separates_messages_with_double_newlines (qtbot , errors ):
68+ """This test ensures that _CopyAllButton consistently inserts two newlines between
69+ each message regardless of locational context."""
70+ suggestor = Suggestor (errors , [], [], lambda : None )
71+
72+ all_buttons = suggestor .findChildren (QPushButton )
73+ copy_all_button = next (
74+ button for button in all_buttons if isinstance (button , _CopyAllButton )
75+ )
76+ copy_all_button .click ()
77+
78+ assert "\n " * 2 in QApplication .clipboard ().text ()
79+ assert "\n " * 3 not in QApplication .clipboard ().text ()
0 commit comments