@@ -503,6 +503,7 @@ def mock_external_classes(self, mocker: MockerFixture, msg_box: MessageBox) -> N
503
503
topic_links = OrderedDict (),
504
504
message_links = OrderedDict (),
505
505
time_mentions = list (),
506
+ code_blocks = list (),
506
507
title = "Full Rendered Message" ,
507
508
)
508
509
@@ -555,6 +556,7 @@ def test_keypress_show_msg_info(
555
556
topic_links = OrderedDict (),
556
557
message_links = OrderedDict (),
557
558
time_mentions = list (),
559
+ code_blocks = list (),
558
560
)
559
561
560
562
@@ -579,6 +581,7 @@ def mock_external_classes(self, mocker: MockerFixture, msg_box: MessageBox) -> N
579
581
topic_links = OrderedDict (),
580
582
message_links = OrderedDict (),
581
583
time_mentions = list (),
584
+ code_blocks = list (),
582
585
title = "Full Raw Message" ,
583
586
)
584
587
@@ -631,6 +634,7 @@ def test_keypress_show_msg_info(
631
634
topic_links = OrderedDict (),
632
635
message_links = OrderedDict (),
633
636
time_mentions = list (),
637
+ code_blocks = list (),
634
638
)
635
639
636
640
@@ -654,6 +658,7 @@ def mock_external_classes(self, mocker: MockerFixture) -> None:
654
658
topic_links = OrderedDict (),
655
659
message_links = OrderedDict (),
656
660
time_mentions = list (),
661
+ code_blocks = list (),
657
662
title = "Edit History" ,
658
663
)
659
664
@@ -702,6 +707,7 @@ def test_keypress_show_msg_info(
702
707
topic_links = OrderedDict (),
703
708
message_links = OrderedDict (),
704
709
time_mentions = list (),
710
+ code_blocks = list (),
705
711
)
706
712
707
713
@pytest .mark .parametrize (
@@ -979,6 +985,7 @@ def mock_external_classes(
979
985
OrderedDict (),
980
986
OrderedDict (),
981
987
list (),
988
+ list (),
982
989
)
983
990
984
991
def test_init (self , message_fixture : Message ) -> None :
@@ -997,6 +1004,7 @@ def test_pop_up_info_order(self, message_fixture: Message) -> None:
997
1004
topic_links = topic_links ,
998
1005
message_links = message_links ,
999
1006
time_mentions = list (),
1007
+ code_blocks = list (),
1000
1008
)
1001
1009
msg_links = msg_info_view .button_widgets
1002
1010
assert msg_links == [message_links , topic_links ]
@@ -1045,6 +1053,7 @@ def test_keypress_edit_history(
1045
1053
topic_links = OrderedDict (),
1046
1054
message_links = OrderedDict (),
1047
1055
time_mentions = list (),
1056
+ code_blocks = list (),
1048
1057
)
1049
1058
size = widget_size (msg_info_view )
1050
1059
@@ -1056,6 +1065,7 @@ def test_keypress_edit_history(
1056
1065
topic_links = OrderedDict (),
1057
1066
message_links = OrderedDict (),
1058
1067
time_mentions = list (),
1068
+ code_blocks = list (),
1059
1069
)
1060
1070
else :
1061
1071
self .controller .show_edit_history .assert_not_called ()
@@ -1074,6 +1084,7 @@ def test_keypress_full_rendered_message(
1074
1084
topic_links = OrderedDict (),
1075
1085
message_links = OrderedDict (),
1076
1086
time_mentions = list (),
1087
+ code_blocks = list (),
1077
1088
)
1078
1089
size = widget_size (msg_info_view )
1079
1090
@@ -1084,6 +1095,7 @@ def test_keypress_full_rendered_message(
1084
1095
topic_links = OrderedDict (),
1085
1096
message_links = OrderedDict (),
1086
1097
time_mentions = list (),
1098
+ code_blocks = list (),
1087
1099
)
1088
1100
1089
1101
@pytest .mark .parametrize ("key" , keys_for_command ("FULL_RAW_MESSAGE" ))
@@ -1100,6 +1112,7 @@ def test_keypress_full_raw_message(
1100
1112
topic_links = OrderedDict (),
1101
1113
message_links = OrderedDict (),
1102
1114
time_mentions = list (),
1115
+ code_blocks = list (),
1103
1116
)
1104
1117
size = widget_size (msg_info_view )
1105
1118
@@ -1110,6 +1123,7 @@ def test_keypress_full_raw_message(
1110
1123
topic_links = OrderedDict (),
1111
1124
message_links = OrderedDict (),
1112
1125
time_mentions = list (),
1126
+ code_blocks = list (),
1113
1127
)
1114
1128
1115
1129
@pytest .mark .parametrize (
@@ -1138,13 +1152,14 @@ def test_keypress_view_in_browser(
1138
1152
assert self .controller .open_in_browser .called
1139
1153
1140
1154
def test_height_noreactions (self ) -> None :
1141
- expected_height = 8
1142
- # 6 = 1 (date & time) +1 (sender's name) +1 (sender's email)
1155
+ expected_height = 9
1156
+ # 3 = 1 (date & time) +1 (sender's name) +1 (sender's email)
1143
1157
# +1 (display group header)
1144
1158
# +1 (whitespace column)
1145
1159
# +1 (view message in browser)
1146
1160
# +1 (full rendered message)
1147
1161
# +1 (full raw message)
1162
+ # +1 (copy code block)
1148
1163
assert self .msg_info_view .height == expected_height
1149
1164
1150
1165
# FIXME This is the same parametrize as MessageBox:test_reactions_view
@@ -1211,10 +1226,11 @@ def test_height_reactions(
1211
1226
OrderedDict (),
1212
1227
OrderedDict (),
1213
1228
list (),
1229
+ list (),
1214
1230
)
1215
- # 12 = 7 labels + 2 blank lines + 1 'Reactions' (category)
1231
+ # 11 = 8 labels + 2 blank lines + 1 'Reactions' (category)
1216
1232
# + 4 reactions (excluding 'Message Links').
1217
- expected_height = 14
1233
+ expected_height = 15
1218
1234
assert self .msg_info_view .height == expected_height
1219
1235
1220
1236
@pytest .mark .parametrize (
@@ -1264,6 +1280,118 @@ def test_create_link_buttons(
1264
1280
assert link_w ._wrapped_widget .attr_map == expected_attr_map
1265
1281
assert link_width == expected_link_width
1266
1282
1283
+ @pytest .mark .parametrize (
1284
+ [
1285
+ "initial_code_block" ,
1286
+ "expected_code" ,
1287
+ "expected_attr_map" ,
1288
+ "expected_focus_map" ,
1289
+ ],
1290
+ [
1291
+ (
1292
+ [
1293
+ (
1294
+ "Python" ,
1295
+ [
1296
+ ("pygments:k" , "def" ),
1297
+ ("pygments:w" , " " ),
1298
+ ("pygments:nf" , "main" ),
1299
+ ("pygments:p" , "()" ),
1300
+ ("pygments:w" , "\n " ),
1301
+ ("pygments:nb" , "print" ),
1302
+ ("pygments:p" , "(" ),
1303
+ ("pygments:s2" , '"Hello"' ),
1304
+ ("pygments:p" , ")" ),
1305
+ ("pygments:w" , "\n " ),
1306
+ ],
1307
+ )
1308
+ ],
1309
+ '1: Python\n def main()\n print("Hello")...' ,
1310
+ {None : "popup_contrast" },
1311
+ {None : "selected" },
1312
+ ),
1313
+ (
1314
+ [
1315
+ (
1316
+ "JavaScript" ,
1317
+ [
1318
+ ("pygments:nx" , "console" ),
1319
+ ("pygments:p" , "." ),
1320
+ ("pygments:nx" , "log" ),
1321
+ ("pygments:p" , "(" ),
1322
+ ("pygments:s2" , '"Hello, world!"' ),
1323
+ ("pygments:p" , ");" ),
1324
+ ("pygments:w" , "\n " ),
1325
+ ],
1326
+ )
1327
+ ],
1328
+ '1: JavaScript\n console.log("Hello, world!");' ,
1329
+ {None : "popup_contrast" },
1330
+ {None : "selected" },
1331
+ ),
1332
+ (
1333
+ [
1334
+ (
1335
+ "C++" ,
1336
+ [
1337
+ ("pygments:cp" , "#include" ),
1338
+ ("pygments:w" , " " ),
1339
+ ("pygments:cpf" , "<iostream>" ),
1340
+ ("pygments:w" , "\n \n " ),
1341
+ ("pygments:kt" , "int" ),
1342
+ ("pygments:w" , " " ),
1343
+ ("pygments:nf" , "main" ),
1344
+ ("pygments:p" , "()" ),
1345
+ ("pygments:w" , " " ),
1346
+ ("pygments:p" , "{" ),
1347
+ ("pygments:w" , "\n " ),
1348
+ ("pygments:w" , " " ),
1349
+ ("pygments:n" , "std" ),
1350
+ ("pygments:o" , "::" ),
1351
+ ("pygments:n" , "cout" ),
1352
+ ("pygments:w" , " " ),
1353
+ ("pygments:o" , "<<" ),
1354
+ ("pygments:w" , " " ),
1355
+ ("pygments:s" , '"Hello World!"' ),
1356
+ ("pygments:p" , ";" ),
1357
+ ("pygments:w" , "\n " ),
1358
+ ("pygments:w" , " " ),
1359
+ ("pygments:k" , "return" ),
1360
+ ("pygments:w" , " " ),
1361
+ ("pygments:mi" , "0" ),
1362
+ ("pygments:p" , ";" ),
1363
+ ("pygments:w" , "\n " ),
1364
+ ("pygments:p" , "}" ),
1365
+ ("pygments:w" , "\n " ),
1366
+ ],
1367
+ )
1368
+ ],
1369
+ "1: C++\n #include <iostream>\n \n int main() {..." ,
1370
+ {None : "popup_contrast" },
1371
+ {None : "selected" },
1372
+ ),
1373
+ ],
1374
+ ids = [
1375
+ "with_python_code_block_two_lines" ,
1376
+ "with_javascript_code_block_one_line" ,
1377
+ "with_cpp_code_block_more_than_two_lines" ,
1378
+ ],
1379
+ )
1380
+ def test_create_code_block_buttons (
1381
+ self ,
1382
+ initial_code_block : List [Tuple [str , List [Tuple [str , str ]]]],
1383
+ expected_code : str ,
1384
+ expected_attr_map : Dict [None , str ],
1385
+ expected_focus_map : Dict [None , str ],
1386
+ ) -> None :
1387
+ [code_w ], _ = self .msg_info_view .create_code_block_buttons (
1388
+ self .controller , initial_code_block
1389
+ )
1390
+
1391
+ assert code_w ._wrapped_widget .original_widget .text == expected_code
1392
+ assert code_w ._wrapped_widget .focus_map == expected_focus_map
1393
+ assert code_w ._wrapped_widget .attr_map == expected_attr_map
1394
+
1267
1395
1268
1396
class TestStreamInfoView :
1269
1397
@pytest .fixture (autouse = True )
0 commit comments