@@ -506,6 +506,7 @@ def mock_external_classes(self, mocker: MockerFixture, msg_box: MessageBox) -> N
506
506
topic_links = OrderedDict (),
507
507
message_links = OrderedDict (),
508
508
time_mentions = list (),
509
+ code_blocks = list (),
509
510
title = "Full Rendered Message" ,
510
511
)
511
512
@@ -558,6 +559,7 @@ def test_keypress_show_msg_info(
558
559
topic_links = OrderedDict (),
559
560
message_links = OrderedDict (),
560
561
time_mentions = list (),
562
+ code_blocks = list (),
561
563
)
562
564
563
565
@@ -582,6 +584,7 @@ def mock_external_classes(self, mocker: MockerFixture, msg_box: MessageBox) -> N
582
584
topic_links = OrderedDict (),
583
585
message_links = OrderedDict (),
584
586
time_mentions = list (),
587
+ code_blocks = list (),
585
588
title = "Full Raw Message" ,
586
589
)
587
590
@@ -634,6 +637,7 @@ def test_keypress_show_msg_info(
634
637
topic_links = OrderedDict (),
635
638
message_links = OrderedDict (),
636
639
time_mentions = list (),
640
+ code_blocks = list (),
637
641
)
638
642
639
643
@@ -657,6 +661,7 @@ def mock_external_classes(self, mocker: MockerFixture) -> None:
657
661
topic_links = OrderedDict (),
658
662
message_links = OrderedDict (),
659
663
time_mentions = list (),
664
+ code_blocks = list (),
660
665
title = "Edit History" ,
661
666
)
662
667
@@ -705,6 +710,7 @@ def test_keypress_show_msg_info(
705
710
topic_links = OrderedDict (),
706
711
message_links = OrderedDict (),
707
712
time_mentions = list (),
713
+ code_blocks = list (),
708
714
)
709
715
710
716
@pytest .mark .parametrize (
@@ -982,6 +988,7 @@ def mock_external_classes(
982
988
OrderedDict (),
983
989
OrderedDict (),
984
990
list (),
991
+ list (),
985
992
)
986
993
987
994
def test_init (self , message_fixture : Message ) -> None :
@@ -1000,6 +1007,7 @@ def test_pop_up_info_order(self, message_fixture: Message) -> None:
1000
1007
topic_links = topic_links ,
1001
1008
message_links = message_links ,
1002
1009
time_mentions = list (),
1010
+ code_blocks = list (),
1003
1011
)
1004
1012
msg_links = msg_info_view .button_widgets
1005
1013
assert msg_links == [message_links , topic_links ]
@@ -1048,6 +1056,7 @@ def test_keypress_edit_history(
1048
1056
topic_links = OrderedDict (),
1049
1057
message_links = OrderedDict (),
1050
1058
time_mentions = list (),
1059
+ code_blocks = list (),
1051
1060
)
1052
1061
size = widget_size (msg_info_view )
1053
1062
@@ -1059,6 +1068,7 @@ def test_keypress_edit_history(
1059
1068
topic_links = OrderedDict (),
1060
1069
message_links = OrderedDict (),
1061
1070
time_mentions = list (),
1071
+ code_blocks = list (),
1062
1072
)
1063
1073
else :
1064
1074
self .controller .show_edit_history .assert_not_called ()
@@ -1077,6 +1087,7 @@ def test_keypress_full_rendered_message(
1077
1087
topic_links = OrderedDict (),
1078
1088
message_links = OrderedDict (),
1079
1089
time_mentions = list (),
1090
+ code_blocks = list (),
1080
1091
)
1081
1092
size = widget_size (msg_info_view )
1082
1093
@@ -1087,6 +1098,7 @@ def test_keypress_full_rendered_message(
1087
1098
topic_links = OrderedDict (),
1088
1099
message_links = OrderedDict (),
1089
1100
time_mentions = list (),
1101
+ code_blocks = list (),
1090
1102
)
1091
1103
1092
1104
@pytest .mark .parametrize ("key" , keys_for_command ("FULL_RAW_MESSAGE" ))
@@ -1103,6 +1115,7 @@ def test_keypress_full_raw_message(
1103
1115
topic_links = OrderedDict (),
1104
1116
message_links = OrderedDict (),
1105
1117
time_mentions = list (),
1118
+ code_blocks = list (),
1106
1119
)
1107
1120
size = widget_size (msg_info_view )
1108
1121
@@ -1113,6 +1126,7 @@ def test_keypress_full_raw_message(
1113
1126
topic_links = OrderedDict (),
1114
1127
message_links = OrderedDict (),
1115
1128
time_mentions = list (),
1129
+ code_blocks = list (),
1116
1130
)
1117
1131
1118
1132
@pytest .mark .parametrize (
@@ -1141,13 +1155,14 @@ def test_keypress_view_in_browser(
1141
1155
assert self .controller .open_in_browser .called
1142
1156
1143
1157
def test_height_noreactions (self ) -> None :
1144
- expected_height = 8
1145
- # 6 = 1 (date & time) +1 (sender's name) +1 (sender's email)
1158
+ expected_height = 9
1159
+ # 3 = 1 (date & time) +1 (sender's name) +1 (sender's email)
1146
1160
# +1 (display group header)
1147
1161
# +1 (whitespace column)
1148
1162
# +1 (view message in browser)
1149
1163
# +1 (full rendered message)
1150
1164
# +1 (full raw message)
1165
+ # +1 (copy code block)
1151
1166
assert self .msg_info_view .height == expected_height
1152
1167
1153
1168
# FIXME This is the same parametrize as MessageBox:test_reactions_view
@@ -1214,10 +1229,11 @@ def test_height_reactions(
1214
1229
OrderedDict (),
1215
1230
OrderedDict (),
1216
1231
list (),
1232
+ list (),
1217
1233
)
1218
- # 12 = 7 labels + 2 blank lines + 1 'Reactions' (category)
1234
+ # 11 = 8 labels + 2 blank lines + 1 'Reactions' (category)
1219
1235
# + 4 reactions (excluding 'Message Links').
1220
- expected_height = 14
1236
+ expected_height = 15
1221
1237
assert self .msg_info_view .height == expected_height
1222
1238
1223
1239
@pytest .mark .parametrize (
@@ -1267,6 +1283,118 @@ def test_create_link_buttons(
1267
1283
assert link_w ._wrapped_widget .attr_map == expected_attr_map
1268
1284
assert link_width == expected_link_width
1269
1285
1286
+ @pytest .mark .parametrize (
1287
+ [
1288
+ "initial_code_block" ,
1289
+ "expected_code" ,
1290
+ "expected_attr_map" ,
1291
+ "expected_focus_map" ,
1292
+ ],
1293
+ [
1294
+ (
1295
+ [
1296
+ (
1297
+ "Python" ,
1298
+ [
1299
+ ("pygments:k" , "def" ),
1300
+ ("pygments:w" , " " ),
1301
+ ("pygments:nf" , "main" ),
1302
+ ("pygments:p" , "()" ),
1303
+ ("pygments:w" , "\n " ),
1304
+ ("pygments:nb" , "print" ),
1305
+ ("pygments:p" , "(" ),
1306
+ ("pygments:s2" , '"Hello"' ),
1307
+ ("pygments:p" , ")" ),
1308
+ ("pygments:w" , "\n " ),
1309
+ ],
1310
+ )
1311
+ ],
1312
+ '1: Python\n def main()\n print("Hello")...' ,
1313
+ {None : "popup_contrast" },
1314
+ {None : "selected" },
1315
+ ),
1316
+ (
1317
+ [
1318
+ (
1319
+ "JavaScript" ,
1320
+ [
1321
+ ("pygments:nx" , "console" ),
1322
+ ("pygments:p" , "." ),
1323
+ ("pygments:nx" , "log" ),
1324
+ ("pygments:p" , "(" ),
1325
+ ("pygments:s2" , '"Hello, world!"' ),
1326
+ ("pygments:p" , ");" ),
1327
+ ("pygments:w" , "\n " ),
1328
+ ],
1329
+ )
1330
+ ],
1331
+ '1: JavaScript\n console.log("Hello, world!");' ,
1332
+ {None : "popup_contrast" },
1333
+ {None : "selected" },
1334
+ ),
1335
+ (
1336
+ [
1337
+ (
1338
+ "C++" ,
1339
+ [
1340
+ ("pygments:cp" , "#include" ),
1341
+ ("pygments:w" , " " ),
1342
+ ("pygments:cpf" , "<iostream>" ),
1343
+ ("pygments:w" , "\n \n " ),
1344
+ ("pygments:kt" , "int" ),
1345
+ ("pygments:w" , " " ),
1346
+ ("pygments:nf" , "main" ),
1347
+ ("pygments:p" , "()" ),
1348
+ ("pygments:w" , " " ),
1349
+ ("pygments:p" , "{" ),
1350
+ ("pygments:w" , "\n " ),
1351
+ ("pygments:w" , " " ),
1352
+ ("pygments:n" , "std" ),
1353
+ ("pygments:o" , "::" ),
1354
+ ("pygments:n" , "cout" ),
1355
+ ("pygments:w" , " " ),
1356
+ ("pygments:o" , "<<" ),
1357
+ ("pygments:w" , " " ),
1358
+ ("pygments:s" , '"Hello World!"' ),
1359
+ ("pygments:p" , ";" ),
1360
+ ("pygments:w" , "\n " ),
1361
+ ("pygments:w" , " " ),
1362
+ ("pygments:k" , "return" ),
1363
+ ("pygments:w" , " " ),
1364
+ ("pygments:mi" , "0" ),
1365
+ ("pygments:p" , ";" ),
1366
+ ("pygments:w" , "\n " ),
1367
+ ("pygments:p" , "}" ),
1368
+ ("pygments:w" , "\n " ),
1369
+ ],
1370
+ )
1371
+ ],
1372
+ "1: C++\n #include <iostream>\n \n int main() {..." ,
1373
+ {None : "popup_contrast" },
1374
+ {None : "selected" },
1375
+ ),
1376
+ ],
1377
+ ids = [
1378
+ "with_python_code_block_two_lines" ,
1379
+ "with_javascript_code_block_one_line" ,
1380
+ "with_cpp_code_block_more_than_two_lines" ,
1381
+ ],
1382
+ )
1383
+ def test_create_code_block_buttons (
1384
+ self ,
1385
+ initial_code_block : List [Tuple [str , List [Tuple [str , str ]]]],
1386
+ expected_code : str ,
1387
+ expected_attr_map : Dict [None , str ],
1388
+ expected_focus_map : Dict [None , str ],
1389
+ ) -> None :
1390
+ [code_w ], _ = self .msg_info_view .create_code_block_buttons (
1391
+ self .controller , initial_code_block
1392
+ )
1393
+
1394
+ assert code_w ._wrapped_widget .original_widget .text == expected_code
1395
+ assert code_w ._wrapped_widget .focus_map == expected_focus_map
1396
+ assert code_w ._wrapped_widget .attr_map == expected_attr_map
1397
+
1270
1398
1271
1399
class TestStreamInfoView :
1272
1400
@pytest .fixture (autouse = True )
0 commit comments