1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171
|
"""
Graphviz regression tests
The test cases in this file relate to previously observed bugs. A failure of one
of these indicates that a past bug has been reintroduced.
"""
import dataclasses
import hashlib
import io
import json
import math
import os
import platform
import re
import shlex
import shutil
import signal
import stat
import statistics
import subprocess
import sys
import tempfile
import textwrap
import time
import xml.etree.ElementTree as ET
from pathlib import Path
from typing import Iterator, Optional, Union
import pexpect
import pytest
from PIL import Image
sys.path.append(os.path.dirname(__file__))
from gvtest import ( # pylint: disable=wrong-import-position
compile_c,
dot,
gvpr,
is_asan_instrumented,
is_autotools,
is_cmake,
is_macos,
is_mingw,
is_rocky,
is_rocky_8,
is_static_build,
plugin_version,
remove_asan_summary,
remove_xtype_warnings,
run,
run_c,
run_raw,
which,
)
def is_ndebug_defined() -> bool:
"""
are assertions disabled in the Graphviz build under test?
"""
# the Windows release builds set NDEBUG
if os.environ.get("configuration") == "Release":
return True
return False
def test_14():
"""
using ortho and twopi in combination should not cause an assertion failure
https://gitlab.com/graphviz/graphviz/-/issues/14
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "14.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz
dot("svg", input)
@pytest.mark.skipif(which("neato") is None, reason="neato not available")
def test_42():
"""
check for a former crash in neatogen
https://gitlab.com/graphviz/graphviz/-/issues/42
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "42.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz
neato = which("neato")
run_raw([neato, "-n2", "-Tpng", input], stdout=subprocess.DEVNULL)
def test_56():
"""
parsing a particular graph should not cause a Trapezoid-table overflow
assertion failure
https://gitlab.com/graphviz/graphviz/-/issues/56
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "56.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz
dot("svg", input)
def test_121():
"""
test a graph that previously caused an assertion failure in `merge_chain`
https://gitlab.com/graphviz/graphviz/-/issues/121
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "121.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz
dot("pdf", input)
def test_131():
"""
PIC back end should produce valid output
https://gitlab.com/graphviz/graphviz/-/issues/131
"""
# a basic graph
src = "digraph { a -> b; c -> d; }"
# ask Graphviz to process this to PIC
pic = dot("pic", source=src)
if which("gpic") is None:
pytest.skip("GNU PIC not available")
# ask GNU PIC to process the Graphviz output
run(["gpic"], input=pic, stdout=subprocess.DEVNULL)
@pytest.mark.parametrize("testcase", ("144_no_ortho.dot", "144_ortho.dot"))
def test_144(testcase: str):
"""
using ortho should not result in head/tail confusion
https://gitlab.com/graphviz/graphviz/-/issues/144
"""
# locate our associated test cases in this directory
input = Path(__file__).parent / testcase
assert input.exists(), "unexpectedly missing test case"
# process the non-ortho one into JSON
out = dot("json", input)
data = json.loads(out)
# find the nodes “A”, “B” and “C”
A = [x for x in data["objects"] if x["name"] == "A"][0]
B = [x for x in data["objects"] if x["name"] == "B"][0]
C = [x for x in data["objects"] if x["name"] == "C"][0]
# find the straight A→B and the angular A→C edges
straight_edge = [
x for x in data["edges"] if x["tail"] == A["_gvid"] and x["head"] == B["_gvid"]
][0]
angular_edge = [
x for x in data["edges"] if x["tail"] == A["_gvid"] and x["head"] == C["_gvid"]
][0]
# the A→B edge should have been routed vertically down
straight_points = straight_edge["_draw_"][1]["points"]
xs = [x for x, _ in straight_points]
ys = [y for _, y in straight_points]
assert all(x == xs[0] for x in xs), "A->B not routed vertically"
assert ys == sorted(ys, reverse=True), "A->B is not routed down"
# determine Graphviz’ idea of head and tail ends
straight_head_point = straight_edge["_hdraw_"][3]["points"][0]
straight_tail_point = straight_edge["_tdraw_"][3]["points"][0]
assert straight_head_point[1] < straight_tail_point[1], "A->B head/tail confusion"
# the A→C edge should have been routed in zigzag down and right
angular_points = angular_edge["_draw_"][1]["points"]
xs = [x for x, _ in angular_points]
ys = [y for _, y in angular_points]
assert xs == sorted(xs), "A->B is not routed down"
assert ys == sorted(ys, reverse=True), "A->B is not routed right"
# determine Graphviz’ idea of head and tail ends
angular_head_point = angular_edge["_hdraw_"][3]["points"][0]
angular_tail_point = angular_edge["_tdraw_"][3]["points"][0]
assert angular_head_point[0] > angular_tail_point[0], "A->C head/tail confusion"
def test_146():
"""
dot should respect an alpha channel value of 0 when writing SVG
https://gitlab.com/graphviz/graphviz/-/issues/146
"""
# a graph using white text but with 0 alpha
source = (
"graph {\n"
' n[style="filled", fontcolor="#FFFFFF00", label="hello world"];\n'
"}"
)
# ask Graphviz to process this
svg = dot("svg", source=source)
# the SVG should be setting opacity
opacity = re.search(r'\bfill-opacity="(\d+(\.\d+)?)"', svg)
assert opacity is not None, "transparency not set for alpha=0 color"
# it should be zeroed
assert (
float(opacity.group(1)) == 0
), "alpha=0 color set to something non-transparent"
def test_162():
"""
`minlen=0` should not duplicate edges
https://gitlab.com/graphviz/graphviz/-/issues/162
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "162.dot"
assert input.exists(), "unexpectedly missing test case"
# lay this out
layout = dot("dot", input)
# find an inter-cluster edge
m = re.search(
r'\bC\s*->\s*D\s*\[\s*minlen\s*=\s*0\s*,\s*pos\s*=\s*"(?P<position>[^"]*)"',
layout,
)
assert m is not None, "could not locate C->D edge"
edge_count = len(re.findall(r"\be\b", m.group("position")))
assert edge_count == 1, "incorrect number of inter-cluster edges"
def test_165():
"""
dot should be able to produce properly escaped xdot output
https://gitlab.com/graphviz/graphviz/-/issues/165
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "165.dot"
assert input.exists(), "unexpectedly missing test case"
# ask Graphviz to translate it to xdot
output = dot("xdot", input)
# find the line containing the _ldraw_ attribute
ldraw = re.search(r"^\s*_ldraw_\s*=(?P<value>.*?)$", output, re.MULTILINE)
assert ldraw is not None, "no _ldraw_ attribute in graph"
# this should contain the label correctly escaped
assert r"hello \\\" world" in ldraw.group("value"), "unexpected ldraw contents"
def test_165_2():
"""
variant of test_165() that checks a similar problem for edges
https://gitlab.com/graphviz/graphviz/-/issues/165
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "165_2.dot"
assert input.exists(), "unexpectedly missing test case"
# ask Graphviz to translate it to xdot
output = dot("xdot", input)
# find the lines containing _ldraw_ attributes
ldraw = re.findall(r"^\s*_ldraw_\s*=(.*?)$", output, re.MULTILINE)
assert ldraw is not None, "no _ldraw_ attributes in graph"
# one of these should contain the label correctly escaped
assert any(r"hello \\\" world" in l for l in ldraw), "unexpected ldraw contents"
def test_165_3():
"""
variant of test_165() that checks a similar problem for graph labels
https://gitlab.com/graphviz/graphviz/-/issues/165
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "165_3.dot"
assert input.exists(), "unexpectedly missing test case"
# ask Graphviz to translate it to xdot
output = dot("xdot", input)
# find the lines containing _ldraw_ attributes
ldraw = re.findall(r"^\s*_ldraw_\s*=(.*?)$", output, re.MULTILINE)
assert ldraw is not None, "no _ldraw_ attributes in graph"
# one of these should contain the label correctly escaped
assert any(r"hello \\\" world" in l for l in ldraw), "unexpected ldraw contents"
def test_167():
"""
using concentrate=true should not result in a segfault
https://gitlab.com/graphviz/graphviz/-/issues/167
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "167.dot"
assert input.exists(), "unexpectedly missing test case"
# process this with dot
ret = subprocess.call(["dot", "-Tpdf", "-o", os.devnull, input])
# Graphviz should not have caused a segfault
assert ret != -signal.SIGSEGV, "Graphviz segfaulted"
def test_191():
"""
a comma-separated list without quotes should cause a hard error, not a warning
https://gitlab.com/graphviz/graphviz/-/issues/191
"""
source = (
"graph {\n"
' "Trackable" [fontcolor=grey45,labelloc=c,fontname=Vera Sans, '
"DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,shape=box,"
'height=0.3,align=center,fontsize=10,style="setlinewidth(0.5)"];\n'
"}"
)
with subprocess.Popen(
["dot", "-Tdot"],
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
) as p:
_, stderr = p.communicate(source)
assert "syntax error" in stderr, "missing error message for unquoted list"
assert p.returncode != 0, "syntax error was only a warning, not an error"
def test_218():
"""
out-of-spec font names should cause warnings in the core PS renderer
https://gitlab.com/graphviz/graphviz/-/issues/218
"""
# a graph using a font name with a space in it
source = 'graph { a[fontname="PT Sans"]; }'
# render it to PS
warnings = run(
["dot", "-Tps", "-o", os.devnull],
stderr=subprocess.STDOUT,
input=source,
)
assert warnings.strip() != "", "no warning issued for a font name containing space"
@pytest.mark.parametrize("test_case", ("241_0.dot", "241_1.dot"))
def test_241(test_case: str):
"""
processing a graph with a `splines=…` setting should not causes warnings
https://gitlab.com/graphviz/graphviz/-/issues/241
"""
# locate our associated test case in this directory
input = Path(__file__).parent / test_case
assert input.exists(), "unexpectedly missing test case"
proc = subprocess.run(
["dot", "-Tsvg", "-o", os.devnull, input],
stderr=subprocess.PIPE,
text=True,
check=True,
)
assert (
"Something is probably seriously wrong" not in proc.stderr
), "splines setting caused warnings"
def test_258():
"""
cluster edges should not be duplicated
https://gitlab.com/graphviz/graphviz/-/issues/258
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "258.dot"
assert input.exists(), "unexpectedly missing test case"
# lay this out
layout = dot("dot", input)
# find an inter-cluster edge
m = re.search(
r'\bB\s*->\s*D\s*\[\s*constraint\s*=\s*none\s*,\s*pos\s*=\s*"(?P<position>[^"]*)"',
layout,
)
assert m is not None, "could not locate B->D edge"
edge_count = len(re.findall(r"\be\b", m.group("position")))
assert edge_count == 1, "incorrect number of inter-cluster edges"
def test_358():
"""
setting xdot version to 1.7 should enable font characteristics
https://gitlab.com/graphviz/graphviz/-/issues/358
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "358.dot"
assert input.exists(), "unexpectedly missing test case"
# process this with dot
xdot = dot("xdot", input)
for i in range(6):
m = re.search(f"\\bt {1 << i}\\b", xdot)
assert m is not None, f"font characteristic {1 << i} not enabled in xdot 1.7"
@pytest.mark.parametrize("attribute", ("samehead", "sametail"))
def test_452(attribute: str):
"""
more than 5 unique `samehead` and `sametail` values should be usable
https://gitlab.com/graphviz/graphviz/-/issues/452
"""
# a graph using more than 5 of the same attribute with the same node on one
# side of each edge
graph = io.StringIO()
graph.write("digraph {\n")
for i in range(6):
if attribute == "samehead":
graph.write(f" m{i} -> n1")
else:
graph.write(f" n1 -> m{i}")
graph.write(f'[{attribute}="foo{i}"];\n')
graph.write("}\n")
# process this with dot
dot("svg", source=graph.getvalue())
def test_510():
"""
HSV colors should also support an alpha channel
https://gitlab.com/graphviz/graphviz/-/issues/510
"""
# a graph with a turquoise, partially transparent node
source = 'digraph { a [color="0.482 0.714 0.878 0.5"]; }'
# process this with dot
svg = dot("svg", source=source)
# see if we can locate an opacity adjustment
m = re.search(r'\bstroke-opacity="(?P<opacity>\d*.\d*)"', svg)
assert m is not None, "no stroke-opacity set; alpha channel ignored?"
# it should be something in-between transparent and opaque
opacity = float(m.group("opacity"))
assert opacity > 0, "node set transparent; misinterpreted alpha channel?"
assert opacity < 1, "node set opaque; misinterpreted alpha channel?"
@pytest.mark.skipif(
which("gv2gxl") is None or which("gxl2gv") is None, reason="GXL tools not available"
)
def test_517():
"""
round tripping a graph through gv2gxl should not lose HTML labels
https://gitlab.com/graphviz/graphviz/-/issues/517
"""
# our test case input
input = (
"digraph{\n"
" A[label=<<TABLE><TR><TD>(</TD><TD>A</TD><TD>)</TD></TR></TABLE>>]\n"
' B[label="<TABLE><TR><TD>(</TD><TD>B</TD><TD>)</TD></TR></TABLE>"]\n'
"}"
)
# translate it to GXL
gv2gxl = which("gv2gxl")
gxl = run([gv2gxl], input=input)
# translate this back to Dot
gxl2gv = which("gxl2gv")
dot_output = run([gxl2gv], input=gxl)
# the result should have both expected labels somewhere
assert (
"label=<<TABLE><TR><TD>(</TD><TD>A</TD><TD>)</TD></TR></TABLE>>" in dot_output
), "HTML label missing"
assert (
'label="<TABLE><TR><TD>(</TD><TD>B</TD><TD>)</TD></TR></TABLE>"' in dot_output
), "regular label missing"
def test_793():
"""
Graphviz should not crash when using VRML output with a non-writable current
directory
https://gitlab.com/graphviz/graphviz/-/issues/793
"""
# create a non-writable directory
with tempfile.TemporaryDirectory() as tmp:
t = Path(tmp)
t.chmod(t.stat().st_mode & ~stat.S_IWRITE)
# ask the VRML back end to handle a simple graph, using the above as the
# current working directory
with subprocess.Popen(["dot", "-Tvrml", "-o", os.devnull], cwd=t) as p:
p.communicate("digraph { a -> b; }")
# Graphviz should not have caused a segfault
assert p.returncode != -signal.SIGSEGV, "Graphviz segfaulted"
def test_797():
"""
“&;” should not be considered an XML escape sequence
https://gitlab.com/graphviz/graphviz/-/issues/797
"""
# some input containing the invalid escape
input = 'digraph tree {\n"1" [shape="box", label="& &;", URL="a"];\n}'
# process this with the client-side imagemap back end
output = dot("cmapx", source=input)
# the escape sequences should have been preserved
assert "& &" in output
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/813"
)
def test_813():
"""
nodes with multiple peripheries should still have a stable rendering
https://gitlab.com/graphviz/graphviz/-/issues/813
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "813.dot"
assert input.exists(), "unexpectedly mising test case"
# render this to dot
reference = dot("dot", input)
# run it through multiple passes
iterated = reference
for _ in range(4):
iterated = dot("dot", source=iterated)
assert (
reference == iterated
), "rendering of shapes with multiple peripheries is unstable"
def test_827():
"""
Graphviz should not crash when processing the b15.gv example
https://gitlab.com/graphviz/graphviz/-/issues/827
"""
b15gv = Path(__file__).parent / "graphs/b15.gv"
assert b15gv.exists(), "missing test case file"
dot("svg", b15gv)
def test_925():
"""
spaces should be handled correctly in UTF-8-containing labels in record shapes
https://gitlab.com/graphviz/graphviz/-/issues/925
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "925.dot"
assert input.exists(), "unexpectedly mising test case"
# process this with dot
svg = dot("svg", input)
# The output should include the correctly spaced UTF-8 label. Note that these
# are not ASCII capital As in this string, but rather UTF-8 Cyrillic Capital
# Letter As.
assert "ААА ААА ААА" in svg, "incorrect spacing in UTF-8 label"
@pytest.mark.parametrize("testcase", ("1213-1.dot", "1213-2.dot"))
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/1213"
)
def test_1213(testcase: str):
"""
clustering should not trigger “trouble in init_rank” errors
https://gitlab.com/graphviz/graphviz/-/issues/1213
"""
# locate our associated test case in this directory
input = Path(__file__).parent / testcase
assert input.exists(), "unexpectedly mising test case"
# process this with dot
dot("png", input)
def test_1221():
"""
assigning a node to two clusters with newrank should not cause a crash
https://gitlab.com/graphviz/graphviz/-/issues/1221
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1221.dot"
assert input.exists(), "unexpectedly missing test case"
# process this with dot
dot("svg", input)
@pytest.mark.skipif(which("gv2gml") is None, reason="gv2gml not available")
def test_1276():
"""
quotes within a label should be escaped in translation to GML
https://gitlab.com/graphviz/graphviz/-/issues/1276
"""
# DOT input containing a label with quotes
src = 'digraph test {\n x[label=<"Label">];\n}'
# process this to GML
gv2gml = which("gv2gml")
gml = run([gv2gml], input=src)
# the unescaped label should not appear in the output
assert '""Label""' not in gml, "quotes not escaped in label"
# the escaped label should appear in the output
assert (
'""Label""' in gml or '""Label""' in gml
), "escaped label not found in GML output"
def test_1308():
"""
processing a minimized graph found by Google Autofuzz should not crash
https://gitlab.com/graphviz/graphviz/-/issues/1308
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1308.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("svg", input)
def test_1308_1():
"""
processing a malformed graph found by Google Autofuzz should not crash
https://gitlab.com/graphviz/graphviz/-/issues/1308
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1308_1.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
ret = subprocess.call(["dot", "-Tsvg", "-o", os.devnull, input])
assert ret in (0, 1), "Graphviz crashed when processing malformed input"
assert ret == 1, "Graphviz did not reject malformed input"
def test_1314():
"""
test that a large font size that produces an overflow in Pango is rejected
https://gitlab.com/graphviz/graphviz/-/issues/1314
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1314.dot"
assert input.exists(), "unexpectedly missing test case"
# ask Graphviz to process it, which should fail
with pytest.raises(subprocess.CalledProcessError):
dot("svg", input)
def test_1318():
"""
processing a large number in a comment should not trigger integer overflow
https://gitlab.com/graphviz/graphviz/-/issues/1318
"""
# sample input consisting of a large number in a comment
source = "#8828066547613302784"
# processing this should succeed
dot("svg", source=source)
@pytest.mark.parametrize("testcase", ("1323.dot", "1323_1.dot"))
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/1323"
)
def test_1323(testcase: str):
"""
these graphs should not generate triangulation warnings/errors
https://gitlab.com/graphviz/graphviz/-/issues/1323
"""
# locate our associated test case in this directory
input = Path(__file__).parent / testcase
assert input.exists(), "unexpectedly missing test case"
stderr = run(["dot", "-Tpng", "-o", os.devnull, input], stderr=subprocess.STDOUT)
assert (
re.search(r"\btriangulation failed\b", stderr) is None
), "triangulation warnings were produced"
assert re.search(r"\bError\b", stderr) is None, "error messages were produced"
def test_1328():
"""
a node with conflicting rank constraints should not cause a crash
https://gitlab.com/graphviz/graphviz/-/issues/1328
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1328.dot"
assert input.exists(), "unexpectedly missing test case"
proc = subprocess.run(
["dot", "-Tsvg", "-o", os.devnull, input],
stderr=subprocess.PIPE,
check=False,
text=True,
)
assert proc.returncode in (0, 1), "multiple rank constraints caused a crash"
def test_1332():
"""
Triangulation calculation on the associated example should succeed.
A prior change that was intended to increase accuracy resulted in the
example in this test now failing some triangulation calculations. It is not
clear whether the outcome before or after is correct, but this test ensures
that the older behavior users are accustomed to is preserved.
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1332.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz
warnings = run(["dot", "-Tpdf", "-o", os.devnull, input], stderr=subprocess.STDOUT)
# work around macOS warnings
warnings = remove_xtype_warnings(warnings).strip()
# no warnings should have been printed
assert (
warnings == ""
), "warnings were printed when processing graph involving triangulation"
def test_1367():
"""
this graph should not generate a null pointer dereference
https://gitlab.com/graphviz/graphviz/-/issues/1367
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1367.dot"
assert input.exists(), "unexpectedly missing test case"
# Pass it through Graphviz. Do not use `dot(…)` because input and output contain
# invalid UTF-8.
run_raw(["dot", "-Txdot:xdot:core", "-o", os.devnull, input])
def test_1408():
"""
parsing particular ortho layouts should not cause an assertion failure
https://gitlab.com/graphviz/graphviz/-/issues/1408
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1408.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz
dot("svg", input)
def test_1411():
"""
parsing strings containing newlines should not disrupt line number tracking
https://gitlab.com/graphviz/graphviz/-/issues/1411
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1411.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz (should fail)
with subprocess.Popen(
["dot", "-Tsvg", "-o", os.devnull, input],
stderr=subprocess.PIPE,
text=True,
) as p:
_, output = p.communicate()
assert p.returncode != 0, "Graphviz accepted broken input"
assert (
"syntax error in line 17 near '\\'" in output
), "error message did not identify correct location"
def test_1425():
"""
tooltips should propagate to SVG even without an HREF
https://gitlab.com/graphviz/graphviz/-/issues/1425
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1425.dot"
assert input.exists(), "unexpectedly missing test case"
# translate this to SVG
svg = dot("svg", input)
assert re.search(r"\btable tip\b", svg) is not None, "tooltip not propagated to SVG"
def test_1425_1():
"""
tooltips should propagate to SVG even without an HREF
https://gitlab.com/graphviz/graphviz/-/issues/1425
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1425_1.dot"
assert input.exists(), "unexpectedly missing test case"
# translate this to SVG
svg = dot("svg", input)
assert (
re.search(r"\bgreek to me\b", svg) is not None
), "tooltip not propagated to SVG"
assert re.search(r"\benglish\b", svg) is not None, "tooltip not propagated to SVG"
assert (
re.search(r"\bleave a tip\b", svg) is not None
), "tooltip not propagated to SVG"
assert (
re.search(r"\bcell tool tip\b", svg) is not None
), "tooltip not propagated to SVG"
assert re.search(r"\btd tip\b", svg) is not None, "tooltip not propagated to SVG"
assert re.search(r"\btable tip\b", svg) is not None, "tooltip not propagated to SVG"
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/1435"
)
def test_1435():
"""
triangulation paths should be findable on this graph
https://gitlab.com/graphviz/graphviz/-/issues/1435
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1435.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz
err = run(["dot", "-Tpng", "-o", os.devnull, input], stderr=subprocess.STDOUT)
assert err.strip() == "", "errors were printed"
def test_1436():
"""
test a segfault from https://gitlab.com/graphviz/graphviz/-/issues/1436 has
not reappeared
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1436.dot"
assert input.exists(), "unexpectedly missing test case"
# ask Graphviz to process it, which should generate a segfault if this bug
# has been reintroduced
dot("svg", input)
def test_1444():
"""
specifying 'headport' as an edge attribute should work regardless of what
order attributes appear in
https://gitlab.com/graphviz/graphviz/-/issues/1444
"""
# locate the first of our associated tests
input1 = Path(__file__).parent / "1444.dot"
assert input1.exists(), "unexpectedly missing test case"
# ask Graphviz to process it
with subprocess.Popen(
["dot", "-Tsvg", input1],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
) as p:
stdout1, stderr = p.communicate()
assert p.returncode == 0, "failed to process a headport edge"
stderr = remove_xtype_warnings(stderr).strip()
stderr = remove_asan_summary(stderr)
assert stderr == "", "emitted an error for a legal graph"
# now locate our second variant, that simply has the attributes swapped
input2 = Path(__file__).parent / "1444-2.dot"
assert input2.exists(), "unexpectedly missing test case"
# process it identically
with subprocess.Popen(
["dot", "-Tsvg", input2],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
) as p:
stdout2, stderr = p.communicate()
assert p.returncode == 0, "failed to process a headport edge"
stderr = remove_xtype_warnings(stderr).strip()
assert stderr == "", "emitted an error for a legal graph"
assert stdout1 == stdout2, "swapping edge attributes altered the output graph"
def test_1447():
"""
graphs should not fail assertions in maze.c
https://gitlab.com/graphviz/graphviz/-/issues/1447
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1447.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("svg", input)
def test_1447_1():
"""
graphs should not fail assertions in maze.c
https://gitlab.com/graphviz/graphviz/-/issues/1447
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1447_1.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("png", input)
def test_1449():
"""
using the SVG color scheme should not cause warnings
https://gitlab.com/graphviz/graphviz/-/issues/1449
"""
# start Graphviz
with subprocess.Popen(
["dot", "-Tsvg", "-o", os.devnull],
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
) as p:
# pass it some input that uses the SVG color scheme
_, stderr = p.communicate('graph g { colorscheme="svg"; }')
assert p.returncode == 0, "Graphviz exited with non-zero status"
assert stderr.strip() == "", "SVG color scheme use caused warnings"
def test_1453():
"""
`splines=curved` should not result in segfaults
https://gitlab.com/graphviz/graphviz/-/issues/1453
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1453.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("svg", input)
def test_1472():
"""
processing a malformed graph found by Google Autofuzz should not crash
https://gitlab.com/graphviz/graphviz/-/issues/1472
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1472.dot"
assert input.exists(), "unexpectedly missing test case"
# run this through Graphviz
proc = subprocess.run(
["dot", "-o", os.devnull, input], stderr=subprocess.PIPE, check=True
)
assert (
re.search(rb"\bAddressSanitizer: heap-buffer-overflow\b", proc.stderr) is None
), "malformed input caused a buffer overflow"
assert (
re.search(rb"\bAddressSanitizer: heap-use-after-free\b", proc.stderr) is None
), "malformed input caused a use-after-free"
def test_1474():
"""
processing this input found by fuzzing should not trigger a buffer overflow
https://gitlab.com/graphviz/graphviz/-/issues/1474
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1474.dot"
assert input.exists(), "unexpectedly missing test case"
# run this through Graphviz
proc = subprocess.run(
["dot", "-o", os.devnull, input], stderr=subprocess.PIPE, check=False
)
assert proc.returncode != 0, "invalid input was not rejected"
assert (
re.search(rb"\bAddressSanitizer: heap-buffer-overflow\b", proc.stderr) is None
), "malformed input caused a buffer overflow"
def test_1489():
"""
processing this input found by fuzzing should not trigger an invalid read
https://gitlab.com/graphviz/graphviz/-/issues/1489
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1489.dot"
assert input.exists(), "unexpectedly missing test case"
# run this through Graphviz
proc = subprocess.run(
["dot", "-o", os.devnull, input], stderr=subprocess.PIPE, check=False
)
assert proc.returncode != 0, "invalid input was not rejected"
assert (
re.search(rb"\bAddressSanitizer: SEGV\b", proc.stderr) is None
), "malformed input caused an invalid memory access"
def test_1494():
"""
processing this input found by fuzzing should not trigger a double-free
https://gitlab.com/graphviz/graphviz/-/issues/1494
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1494.dot"
assert input.exists(), "unexpectedly missing test case"
# run this through Graphviz
proc = subprocess.run(
["dot", "-o", os.devnull, input], stderr=subprocess.PIPE, check=False
)
assert proc.returncode != 0, "invalid input was not rejected"
assert (
re.search(rb"\bAddressSanitizer: double-free\b", proc.stderr) is None
), "malformed input caused a double free()"
def test_1514():
"""
processing this input should not trigger an assertion failure
https://gitlab.com/graphviz/graphviz/-/issues/1514
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1514.dot"
assert input.exists(), "unexpectedly missing test case"
# run this through Graphviz
proc = subprocess.run(
["dot", "-o", os.devnull, input], stderr=subprocess.PIPE, check=False
)
assert (
re.search(rb"\bAssertion `v' failed\b", proc.stderr) is None
), "malformed input caused an assertion failure"
def test_1554():
"""
small distances between nodes should not cause a crash in majorization
https://gitlab.com/graphviz/graphviz/-/issues/1554
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1554.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
output = dot("svg", input)
# the output should not have NaN values, indicating out of bounds computation
assert (
re.search(r"\bnan\b", output, flags=re.IGNORECASE) is None
), "computation exceeded bounds"
def test_1581():
"""
this example found by fuzzing should not cause an out-of-bounds write
https://gitlab.com/graphviz/graphviz/-/issues/1581
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1581.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
p = subprocess.run(["dot", "-Tsvg", "-o", os.devnull, input], check=False)
assert p.returncode != 42, "Address Sanitizer detect memory safety violations"
def test_1585():
"""
clustering nodes should not reverse their horizontal layout
https://gitlab.com/graphviz/graphviz/-/issues/1585
"""
# locate our associated test cases in this directory
no_cluster = Path(__file__).parent / "1585_0.dot"
assert no_cluster.exists(), "unexpectedly missing test case"
cluster = Path(__file__).parent / "1585_1.dot"
assert cluster.exists(), "unexpectedly missing test case"
def find_node_xs(svg_output: str) -> Iterator[float]:
"""
yield 3 floats representing the X positions of nodes b, c, d in the
given graph
"""
# parse the SVG
root = ET.fromstring(svg_output)
# find `b`
b = root.findall(
".//{http://www.w3.org/2000/svg}title[.='b']../{http://www.w3.org/2000/svg}ellipse"
)
assert len(b) == 1, "could not find node 'b'"
yield float(b[0].attrib["cx"])
# find `c`
c = root.findall(
".//{http://www.w3.org/2000/svg}title[.='c']../{http://www.w3.org/2000/svg}ellipse"
)
assert len(c) == 1, "could not find node 'c'"
yield float(c[0].attrib["cx"])
# find `d`
d = root.findall(
".//{http://www.w3.org/2000/svg}title[.='d']../{http://www.w3.org/2000/svg}ellipse"
)
assert len(d) == 1, "could not find node 'd'"
yield float(d[0].attrib["cx"])
# render the one without clusters and get its nodes’ X positions
no_cluster_out = dot("svg", no_cluster)
b, c, d = list(find_node_xs(no_cluster_out))
# confirm we got a left → right ordering
assert b < c, "unexpected horizontal node ordering"
assert c < d, "unexpected horizontal node ordering"
# now try the same thing with the clustered graph
cluster_out = dot("svg", cluster)
b, c, d = list(find_node_xs(cluster_out))
assert b < c, "clustering altered nodes’ horizontal ordering"
assert c < d, "clustering altered nodes’ horizontal ordering"
@pytest.mark.skipif(which("gvpr") is None, reason="GVPR not available")
def test_1594():
"""
GVPR should give accurate line numbers in error messages
https://gitlab.com/graphviz/graphviz/-/issues/1594
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1594.gvpr"
# run GVPR with our (malformed) input program
gvprbin = which("gvpr")
with subprocess.Popen(
[gvprbin, "-f", input],
stdin=subprocess.PIPE,
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
text=True,
) as p:
_, stderr = p.communicate()
assert p.returncode != 0, "GVPR did not reject malformed program"
assert "line 3:" in stderr, "GVPR did not identify correct line of syntax error"
@pytest.mark.parametrize(
"device", ("png:cairo:gd", "png:cairo:gdiplus", "png:cairo:gdk", "png:cairo:quartz")
)
def test_1617(device: str):
"""
DPI should be propagated to PNG outputs
https://gitlab.com/graphviz/graphviz/-/issues/1617
"""
# check if Graphviz was built with the plugin that provides this device
p = subprocess.run(
["dot", "-Tpng:unrecognized", "-o", os.devnull, os.devnull],
stderr=subprocess.PIPE,
check=False,
text=True,
)
if re.search(rf"\b{device}\b", p.stderr) is None:
pytest.skip(f'"{device}" output device not supported')
# run an example with DPI through Graphviz
graph = 'digraph G { dpi = "300"; B->C; B->D; C->B; D->A; D->C; }'
png = dot(device, source=graph)
# interpret this with Pillow
data = io.BytesIO(png)
img = Image.open(data)
# we should see the DPI propagated to the image
default = 72
dpi = img.info.get("dpi", (default, default))
assert math.isclose(dpi[0], 300, abs_tol=1), "DPI not propagated to output"
assert math.isclose(dpi[1], 300, abs_tol=1), "DPI not propagated to output"
@pytest.mark.parametrize("long,short", (("--help", "-?"), ("--version", "-V")))
def test_1618(long: str, short: str):
"""
Graphviz should understand `--help` and `--version`
https://gitlab.com/graphviz/graphviz/-/issues/1618
"""
# run Graphviz with the short form of the argument
p1 = subprocess.run(["dot", short], capture_output=True, check=True)
# run it with the long form of the argument
p2 = subprocess.run(["dot", long], capture_output=True, check=True)
# output from both should match
assert (
p1.stdout == p2.stdout
), f"`dot {long}` wrote differing output than `dot {short}`"
assert (
p1.stderr == p2.stderr
), f"`dot {long}` wrote differing output than `dot {short}`"
@pytest.mark.parametrize(
"test_case", ("1622_0.dot", "1622_1.dot", "1622_2.dot", "1622_3.dot")
)
def test_1622(test_case: str):
"""
Narrow HTML table cells should not cause assertion failures
https://gitlab.com/graphviz/graphviz/-/issues/1622
"""
# locate our associated test case in this directory
input = Path(__file__).parent / test_case
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz
dot("png:cairo:cairo", input)
def test_1624():
"""
record shapes should be usable
https://gitlab.com/graphviz/graphviz/-/issues/1624
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1624.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz
dot("svg", input)
def test_1644():
"""
neato results should be deterministic
https://gitlab.com/graphviz/graphviz/-/issues/1644
"""
# get our baseline reference
input = Path(__file__).parent / "1644.dot"
assert input.exists(), "unexpectedly missing test case"
neato = which("neato")
ref = run([neato, input])
# now repeat this, expecting it not to change
for _ in range(20):
out = run([neato, input])
assert ref == out, "repeated rendering changed output"
@pytest.mark.parametrize("fmt", ("dot", "gif", "svg", "xdot"))
@pytest.mark.parametrize("layerselect", range(1, 6))
def test_1648(fmt: str, layerselect: int):
"""
`layerselect` should not cause crashes
https://gitlab.com/graphviz/graphviz/-/issues/1648
Args:
fmt: output format (`-T…`) to test
layerselect: which layer to choose
"""
# a graph with layers
input = Path(__file__).parent / "graphs/layer.gv"
assert input.exists(), "unexpectedly missing test case"
# run this through Graphviz
run(["dot", f"-Glayerselect={layerselect}", f"-T{fmt}", "-o", os.devnull, input])
@pytest.mark.parametrize(
"fmt",
(
"bmp",
"canon",
"cmap",
"cmapx",
"cmapx_np",
"dot",
"dot_json",
"eps",
"fig",
"gv",
pytest.param(
"ico",
marks=pytest.mark.skipif(
platform.system() == "Windows",
reason="no 'ico'-supporting plugin available on Windows",
),
),
"imap",
"imap_np",
"ismap",
"jpe",
"jpeg",
"jpg",
"json",
"json0",
"kitty",
"kittyz",
"pdf",
"pic",
"plain",
"plain-ext",
"png",
"pov",
"ps",
"ps2",
"svg",
"svg_inline",
"svgz",
"tif",
"tiff",
"tk",
"vt",
"vt-24bit",
"vt-4up",
"vt-6up",
"vt-8up",
pytest.param(
"x11",
marks=pytest.mark.skipif(
platform.system() != "Linux",
reason="xlib plugin only available on Linux",
),
),
"xdot",
"xdot1.2",
"xdot1.4",
"xdot_json",
pytest.param(
"xlib",
marks=pytest.mark.skipif(
platform.system() != "Linux",
reason="xlib plugin only available on Linux",
),
),
),
)
def test_1648_1(fmt: str):
"""
`layerselect` should not cause crashes
https://gitlab.com/graphviz/graphviz/-/issues/1648
https://forum.graphviz.org/t/segmentation-fault-when-using-layerselect/3077
Args:
fmt: output format (`-T…`) to test
"""
# a simple arbitrary graph
source = "graph {}"
# run this through Graphviz
run(
["dot", f"-T{fmt}", "-Glayers=a, b", "-Glayerselect=b", "-o", os.devnull],
input=source,
)
def test_1658():
"""
the graph associated with this test case should not crash Graphviz
https://gitlab.com/graphviz/graphviz/-/issues/1658
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1658.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz
dot("png", input)
def test_1676():
"""
https://gitlab.com/graphviz/graphviz/-/issues/1676
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1676.dot"
assert input.exists(), "unexpectedly missing test case"
# run Graphviz with this input
ret = subprocess.call(["dot", "-Tsvg", "-o", os.devnull, input])
# this malformed input should not have caused Graphviz to crash
assert ret != -signal.SIGSEGV, "Graphviz segfaulted"
@pytest.mark.skipif(which("gvpr") is None, reason="GVPR not available")
def test_1702():
"""
GVPR library program `depath` should work on arbitrary examples
https://gitlab.com/graphviz/graphviz/-/issues/1702
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1702.dot"
assert input.exists(), "unexpectedly missing test case"
# find the library program
depath = Path(__file__).parents[1] / "cmd/gvpr/lib/depath"
assert depath.exists(), "GVPR library program depath missing"
# run GVPR
gvpr_bin = which("gvpr")
proc = subprocess.run(
[gvpr_bin, "-c", "-o", os.devnull, "-f", depath, input],
stderr=subprocess.PIPE,
text=True,
check=True,
)
assert proc.stderr.strip() == "", "depath errored on tests/1702.dot"
def test_1724():
"""
passing malformed node and newrank should not cause segfaults
https://gitlab.com/graphviz/graphviz/-/issues/1724
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1724.dot"
assert input.exists(), "unexpectedly missing test case"
# run Graphviz with this input
ret = subprocess.call(["dot", "-Tsvg", "-o", os.devnull, input])
assert ret != -signal.SIGSEGV, "Graphviz segfaulted"
@pytest.mark.skipif(
is_static_build(),
reason="dynamic libraries are unavailable to link against in static builds",
)
def test_1767():
"""
using the Pango plugin multiple times should produce consistent results
https://gitlab.com/graphviz/graphviz/-/issues/1767
"""
# find co-located test source
c_src = (Path(__file__).parent / "1767.c").resolve()
assert c_src.exists(), "missing test case"
# find our co-located dot input
src = (Path(__file__).parent / "1767.dot").resolve()
assert src.exists(), "missing test case"
stdout, _ = run_c(c_src, [src], link=["cgraph", "gvc"])
assert stdout.splitlines() == [
"Loaded graph:clusters",
"cluster_0 contains 5 nodes",
"cluster_1 contains 1 nodes",
"cluster_2 contains 3 nodes",
"cluster_3 contains 3 nodes",
"Loaded graph:clusters",
"cluster_0 contains 5 nodes",
"cluster_1 contains 1 nodes",
"cluster_2 contains 3 nodes",
"cluster_3 contains 3 nodes",
]
@pytest.mark.skipif(which("gvpr") is None, reason="GVPR not available")
@pytest.mark.skipif(platform.system() != "Windows", reason="only relevant on Windows")
def test_1780():
"""
GVPR should accept programs at absolute paths
https://gitlab.com/graphviz/graphviz/-/issues/1780
"""
# get absolute path to an arbitrary GVPR program
clustg = Path(__file__).resolve().parent.parent / "cmd/gvpr/lib/clustg"
# GVPR should not fail when given this path
gvpr(clustg)
def test_1783():
"""
Graphviz should not segfault when passed large edge weights
https://gitlab.com/graphviz/graphviz/-/issues/1783
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1783.dot"
assert input.exists(), "unexpectedly missing test case"
# run Graphviz with this input
ret = subprocess.call(["dot", "-Tsvg", "-o", os.devnull, input])
assert ret != 0, "Graphviz accepted illegal edge weight"
assert ret != -signal.SIGSEGV, "Graphviz segfaulted"
@pytest.mark.skipif(which("gvedit") is None, reason="Gvedit not available")
def test_1813():
"""
gvedit -? should show usage
https://gitlab.com/graphviz/graphviz/-/issues/1813
"""
environ_copy = os.environ.copy()
environ_copy.pop("DISPLAY", None)
gvedit = which("gvedit")
output = run([gvedit, "-?"], env=environ_copy)
assert "Usage" in output, "gvedit -? did not show usage"
def test_1845():
"""
rendering sequential graphs to PS should not segfault
https://gitlab.com/graphviz/graphviz/-/issues/1845
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1845.dot"
assert input.exists(), "unexpectedly missing test case"
# generate a multipage PS file from this input
dot("ps", input)
@pytest.mark.xfail(strict=True) # FIXME
def test_1856():
"""
headports and tailports should be respected
https://gitlab.com/graphviz/graphviz/-/issues/1856
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1856.dot"
assert input.exists(), "unexpectedly missing test case"
# process it into JSON
out = dot("json", input)
data = json.loads(out)
# find the two nodes, “3” and “5”
three = [x for x in data["objects"] if x["name"] == "3"][0]
five = [x for x in data["objects"] if x["name"] == "5"][0]
# find the edge from “3” to “5”
edge = [
x
for x in data["edges"]
if x["tail"] == three["_gvid"] and x["head"] == five["_gvid"]
][0]
# The edge should look something like:
#
# ┌─┐
# │3│
# └┬┘
# ┌────┘
# ┌┴┐
# │5│
# └─┘
#
# but a bug causes port constraints to not be respected and the edge comes out
# more like:
#
# ┌─┐
# │3│
# └┬┘
# │
# ┌─┐ │
# ├5̶┼───┘
# └─┘
#
# So validate that the edge’s path does not dip below the top of the “5” node.
top_of_five = max(y for _, y in five["_draw_"][1]["points"])
waypoints_y = [y for _, y in edge["_draw_"][1]["points"]]
assert all(y >= top_of_five for y in waypoints_y), "edge dips below 5"
@pytest.mark.skipif(which("fdp") is None, reason="fdp not available")
def test_1865():
"""
fdp should not read out of bounds when processing node names
https://gitlab.com/graphviz/graphviz/-/issues/1865
Note, the crash this test tries to provoke may only occur when run under
Address Sanitizer or Valgrind
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1865.dot"
assert input.exists(), "unexpectedly missing test case"
# fdp should not crash when processing this file
fdp = which("fdp")
run_raw([fdp, "-o", os.devnull, input])
@pytest.mark.skipif(which("gv2gml") is None, reason="gv2gml not available")
@pytest.mark.skipif(which("gml2gv") is None, reason="gml2gv not available")
@pytest.mark.parametrize(
"penwidth",
(pytest.param("1.0", id="penwidth=1.0"), pytest.param("1", id="pendwidth=1")),
)
def test_1871(penwidth: str):
"""
round tripping something with either an integer or real `penwidth` through
gv2gml→gml2gv should return the correct `penwidth`
"""
# a trivial graph
input = f"graph {{ a [penwidth={penwidth}] }}"
# pass it through gv2gml
gv2gml = which("gv2gml")
gv = run([gv2gml], input=input)
# pass this through gml2gv
gml2gv = which("gml2gv")
gml = run([gml2gv], input=gv)
# the result should have a `penwidth` of 1
has_1 = re.search(r"\bpenwidth\s*=\s*1[^\.]", gml) is not None
has_1_0 = re.search(r"\bpenwidth\s*=\s*1\.0\b", gml) is not None
assert (
has_1 or has_1_0
), f"incorrect penwidth from round tripping through GML (output {gml})"
@pytest.mark.skipif(which("fdp") is None, reason="fdp not available")
def test_1876():
"""
fdp should not rename nodes with internal names
https://gitlab.com/graphviz/graphviz/-/issues/1876
"""
# a trivial graph to provoke this issue
input = "graph { a }"
# process this with fdp
fdp = which("fdp")
try:
output = run([fdp], input=input)
except subprocess.CalledProcessError as e:
raise RuntimeError("fdp failed to process trivial graph") from e
# we should not see any internal names like "%3"
assert "%" not in output, "internal name in fdp output"
@pytest.mark.skipif(which("fdp") is None, reason="fdp not available")
def test_1877():
"""
fdp should not fail an assertion when processing cluster edges
https://gitlab.com/graphviz/graphviz/-/issues/1877
"""
# simple input with a cluster edge
input = "graph {subgraph cluster_a {}; cluster_a -- b}"
# fdp should be able to process this
fdp = which("fdp")
run([fdp, "-o", os.devnull], input=input)
def test_1880():
"""
parsing a particular graph should not cause a Trapezoid-table overflow
assertion failure
https://gitlab.com/graphviz/graphviz/-/issues/1880
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1880.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz
dot("png", input)
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/1887"
)
def test_1887():
"""
empty strings as labels should be propagated to dot output
https://gitlab.com/graphviz/graphviz/-/issues/1887
"""
# find co-located test source
c_src = (Path(__file__).parent / "1887.c").resolve()
assert c_src.exists(), "missing test case"
# generate a graph and pass it through dot
stdout, _ = run_c(c_src, link=["cgraph"])
assert (
re.search(r'label\s*=\s*""', stdout) is not None
), "empty label missing in output"
def test_1896():
"""
this graph should not crash Graphviz
https://gitlab.com/graphviz/graphviz/-/issues/1896
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1896.dot"
assert input.exists(), "unexpectedly missing test case"
for _ in range(10):
dot("xdot1.2", input)
def test_1898():
"""
test a segfault from https://gitlab.com/graphviz/graphviz/-/issues/1898 has
not reappeared
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1898.dot"
assert input.exists(), "unexpectedly missing test case"
# ask Graphviz to process it, which should generate a segfault if this bug
# has been reintroduced
dot("svg", input)
def test_1902():
"""
test a segfault from https://gitlab.com/graphviz/graphviz/-/issues/1902 has
not reappeared
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1902.dot"
assert input.exists(), "unexpectedly missing test case"
# ask Graphviz to process it, which should generate a segfault if this bug
# has been reintroduced
dot("svg", input)
# root directory of this checkout
ROOT = Path(__file__).parent.parent.resolve()
def test_1855():
"""
SVGs should have a scale with sufficient precision
https://gitlab.com/graphviz/graphviz/-/issues/1855
"""
# locate our associated test case in this directory
src = Path(__file__).parent / "1855.dot"
assert src.exists(), "unexpectedly missing test case"
# run it through Graphviz
svg = dot("svg", src)
# find the graph element
root = ET.fromstring(svg)
graph = root[0]
assert graph.get("class") == "graph", "could not find graph element"
# extract its `transform` attribute
transform = graph.get("transform")
# this should begin with a scale directive
m = re.match(r"scale\((?P<x>\d+(\.\d*)?) (?P<y>\d+(\.\d*))\)", transform)
assert m is not None, f"failed to find 'scale' in '{transform}'"
x = m.group("x")
y = m.group("y")
# the scale should be somewhere in reasonable range of what is expected
assert float(x) >= 0.32 and float(x) <= 0.34, "inaccurate x scale"
assert float(y) >= 0.32 and float(y) <= 0.34, "inaccurate y scale"
# two digits of precision are insufficient for this example, so require a
# greater number of digits in both scale components
assert len(x) > 4, "insufficient precision in x scale"
assert len(y) > 4, "insufficient precision in y scale"
@pytest.mark.parametrize("variant", [1, 2])
@pytest.mark.skipif(which("gml2gv") is None, reason="gml2gv not available")
def test_1869(variant: int):
"""
gml2gv should be able to parse the style, outlineStyle, width and
outlineWidth GML attributes and map them to the DOT attributes
style and penwidth respectively
https://gitlab.com/graphviz/graphviz/-/issues/1869
"""
# locate our associated test case in this directory
input = Path(__file__).parent / f"1869-{variant}.gml"
assert input.exists(), "unexpectedly missing test case"
# ask gml2gv to translate it to DOT
gml2gv = which("gml2gv")
output = run([gml2gv, input])
assert "style=dashed" in output, "style=dashed not found in DOT output"
assert "penwidth=2" in output, "penwidth=2 not found in DOT output"
def test_1879():
"""https://gitlab.com/graphviz/graphviz/-/issues/1879"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1879.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with DOT
stdout = run(
["dot", "-Tsvg", "-o", os.devnull, input],
cwd=Path(__file__).parent,
stderr=subprocess.STDOUT,
)
# check we did not trigger an assertion failure
assert re.search(r"\bAssertion\b.*\bfailed\b", stdout) is None
def test_1879_2():
"""
another variant of lhead/ltail + compound
https://gitlab.com/graphviz/graphviz/-/issues/1879
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1879-2.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with DOT
run_raw(["dot", "-Gmargin=0", "-Tpng", "-o", os.devnull, input])
def test_1893():
"""
an HTML label containing just a ] should work
https://gitlab.com/graphviz/graphviz/-/issues/1893
"""
# a graph containing a node with an HTML label with a ] in a table cell
input = "digraph { 0 [label=<<TABLE><TR><TD>]</TD></TR></TABLE>>] }"
# ask Graphviz to process this
dot("svg", source=input)
# we should be able to do the same with an escaped ]
input = "digraph { 0 [label=<<TABLE><TR><TD>]</TD></TR></TABLE>>] }"
dot("svg", source=input)
def test_1906():
"""
graphs that generate large rectangles should be accepted
https://gitlab.com/graphviz/graphviz/-/issues/1906
"""
# one of the rtest graphs is sufficient to provoke this
input = Path(__file__).parent / "graphs/root.gv"
assert input.exists(), "unexpectedly missing test case"
# use Circo to translate it to DOT
run_raw(["dot", "-Kcirco", "-Tgv", "-o", os.devnull, input])
@pytest.mark.skipif(which("twopi") is None, reason="twopi not available")
def test_1907():
"""
SVG edges should have title elements that match their names
https://gitlab.com/graphviz/graphviz/-/issues/1907
"""
# a trivial graph to provoke this issue
input = "digraph { A -> B -> C }"
# generate an SVG from this input with twopi
twopi = which("twopi")
output = run([twopi, "-Tsvg"], input=input)
assert "<title>A->B</title>" in output, "element title not found in SVG"
@pytest.mark.skipif(which("gvpr") is None, reason="gvpr not available")
def test_1909():
"""
GVPR should not output internal names
https://gitlab.com/graphviz/graphviz/-/issues/1909
"""
# locate our associated test case in this directory
prog = Path(__file__).parent / "1909.gvpr"
graph = Path(__file__).parent / "1909.dot"
# run GVPR with the given input
gvprbin = which("gvpr")
output = run([gvprbin, "-c", "-f", prog, graph])
# we should have produced this graph without names like "%2" in it
assert re.search(r"%\d+\b", output) is None
@pytest.mark.skipif(
is_static_build(),
reason="dynamic libraries are unavailable to link against in static builds",
)
def test_1910():
"""
Repeatedly using agmemread() should have consistent results
https://gitlab.com/graphviz/graphviz/-/issues/1910
"""
# find co-located test source
c_src = (Path(__file__).parent / "1910.c").resolve()
assert c_src.exists(), "missing test case"
# run the test
_, _ = run_c(c_src, link=["cgraph", "gvc"])
def test_1913():
"""
ALIGN attributes in <BR> tags should be parsed correctly
https://gitlab.com/graphviz/graphviz/-/issues/1913
"""
# a template of a trivial graph using an ALIGN attribute
graph = (
"digraph {{\n"
' table1[label=<<table><tr><td align="text">hello world'
'<br align="{}"/></td></tr></table>>];\n'
"}}"
)
def execute(input):
"""
run Dot with the given input and return its exit status and stderr
"""
with subprocess.Popen(
["dot", "-Tsvg", "-o", os.devnull],
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
) as p:
_, stderr = p.communicate(input)
return p.returncode, remove_asan_summary(remove_xtype_warnings(stderr))
# Graphviz should accept all legal values for this attribute
for align in ("left", "right", "center"):
input = align
ret, stderr = execute(graph.format(input))
assert ret == 0
assert stderr.strip() == ""
# these attributes should also be valid when title cased
input = f"{align[0].upper()}{align[1:]}"
ret, stderr = execute(graph.format(input))
assert ret == 0
assert stderr.strip() == ""
# similarly, they should be valid when upper cased
input = align.upper()
ret, stderr = execute(graph.format(input))
assert ret == 0
assert stderr.strip() == ""
# various invalid things that have the same prefix or suffix as a valid
# alignment should be rejected
for align in ("lamp", "deft", "round", "might", "circle", "venter"):
input = align
_, stderr = execute(graph.format(input))
assert f"Warning: Illegal value {input} for ALIGN - ignored" in stderr
# these attributes should also fail when title cased
input = f"{align[0].upper()}{align[1:]}"
_, stderr = execute(graph.format(input))
assert f"Warning: Illegal value {input} for ALIGN - ignored" in stderr
# similarly, they should fail when upper cased
input = align.upper()
_, stderr = execute(graph.format(input))
assert f"Warning: Illegal value {input} for ALIGN - ignored" in stderr
@pytest.mark.skipif(which("gvpr") is None, reason="GVPR not available")
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/1925"
)
def test_1925():
"""
GVPR `hasAttr` should work accurately
https://gitlab.com/graphviz/graphviz/-/issues/1925
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1925.dot"
assert input.exists(), "unexpectedly missing test case"
script = Path(__file__).parent / "1925.gvpr"
assert script.exists(), "unexpectedly missing test case"
# run GVPR
gvpr_bin = which("gvpr")
stdout = run([gvpr_bin, "-c", "-f", script, input])
# check we got expected results
styled = set(["L"])
minlened = set(["S->T"])
active = None
for line in stdout.split("\n"):
if m := re.match("// (NODE|EDGE): (?P<name>.*)$", line):
active = m.group("name")
continue
if m := re.match(r"//\s+style :: (?P<value>0|1)$", line):
assert active is not None, "style line with no known node/edge"
if m.group("value") == "0":
assert (
active not in styled
), f"{active} incorrectly considered to have 'style' attribute"
else:
assert (
active in styled
), f"{active} incorrectly considered to not have 'style' attribute"
if m := re.match(r"//\s+minlen :: (?P<value>0|1)$", line):
assert active is not None, "minlen line with no known node/edge"
if m.group("value") == "0":
assert (
active not in minlened
), f"{active} incorrectly considered to have 'minlen' attribute"
else:
assert (
active in minlened
), f"{active} incorrectly considered to not have 'minlen' attribute"
def test_1931():
"""
New lines within strings should not be discarded during parsing
https://gitlab.com/graphviz/graphviz/-/issues/1931
"""
# a graph with \n inside of strings
graph = (
"graph {\n"
' node1 [label="line 1\n'
"line 2\n"
'"];\n'
' node2 [label="line 3\n'
'line 4"];\n'
" node1 -- node2\n"
' node2 -- "line 5\n'
'line 6"\n'
"}"
)
# ask Graphviz to process this to dot output
xdot = dot("xdot", source=graph)
# all new lines in strings should have been preserved
assert "line 1\nline 2\n" in xdot
assert "line 3\nline 4" in xdot
assert "line 5\nline 6" in xdot
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/1939"
)
def test_1939():
"""
clustering should not cause “trouble in init_rank” errors
https://gitlab.com/graphviz/graphviz/-/issues/1939
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1939.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("svg", input)
def test_1949():
"""
rankdir=LR + compound=true should not lead to an assertion failure
https://gitlab.com/graphviz/graphviz/-/issues/1949
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1949.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("png", input)
@pytest.mark.skipif(which("edgepaint") is None, reason="edgepaint not available")
def test_1971():
"""
edgepaint should reject invalid command line options
https://gitlab.com/graphviz/graphviz/-/issues/1971
"""
# a basic graph that edgepaint can process
input = (
"digraph {\n"
' graph [bb="0,0,54,108"];\n'
' node [label="\\N"];\n'
" a [height=0.5,\n"
' pos="27,90",\n'
" width=0.75];\n"
" b [height=0.5,\n"
' pos="27,18",\n'
" width=0.75];\n"
' a -> b [pos="e,27,36.104 27,71.697 27,63.983 27,54.712 27,46.112"];\n'
"}"
)
# run edgepaint with an invalid option, `-rabbit`, that happens to have the
# same first character as valid options
args = [which("edgepaint"), "-rabbit"]
with subprocess.Popen(args, stdin=subprocess.PIPE, text=True) as p:
p.communicate(input)
assert p.returncode != 0, "edgepaint incorrectly accepted '-rabbit'"
def test_1990():
"""
using ortho and circo in combination should not cause an assertion failure
https://gitlab.com/graphviz/graphviz/-/issues/14
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "1990.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz
circo = which("circo")
run_raw([circo, "-Tsvg", "-o", os.devnull, input])
@pytest.mark.skipif(
is_static_build(),
reason="dynamic libraries are unavailable to link against in static builds",
)
def test_2057():
"""
gvToolTred should be usable by user code
https://gitlab.com/graphviz/graphviz/-/issues/2057
"""
# find co-located test source
c_src = (Path(__file__).parent / "2057.c").resolve()
assert c_src.exists(), "missing test case"
# run the test
_, _ = run_c(c_src, link=["gvc"])
def test_2078():
"""
Incorrectly using the "layout" attribute on a subgraph should result in a
sensible error.
https://gitlab.com/graphviz/graphviz/-/issues/2078
"""
# our sample graph that incorrectly uses layout
input = "graph {\n subgraph {\n layout=osage\n }\n}"
# run it through Graphviz
with subprocess.Popen(
["dot", "-Tcanon", "-o", os.devnull],
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
) as p:
_, stderr = p.communicate(input)
assert p.returncode != 0, "layout on subgraph was incorrectly accepted"
assert (
"layout attribute is invalid except on the root graph" in stderr
), "expected warning not found"
# a graph that correctly uses layout
input = "graph {\n layout=osage\n subgraph {\n }\n}"
# ensure this one does not trigger warnings
with subprocess.Popen(
["dot", "-Tcanon", "-o", os.devnull],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
) as p:
stdout, stderr = p.communicate(input)
assert p.returncode == 0, f"correct layout use was rejected: {stdout}{stderr}"
assert stdout.strip() == "", "unexpected output"
assert (
"layout attribute is invalid except on the root graph" not in stderr
), "incorrect warning output"
def test_2082():
"""
Check a bug in inside_polygon has not been reintroduced.
https://gitlab.com/graphviz/graphviz/-/issues/2082
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2082.dot"
assert input.exists(), "unexpectedly missing test case"
# ask Graphviz to process it, which should generate an assertion failure if
# this bug has been reintroduced
dot("png", input)
def test_2087():
"""
spline routing should be aware of and ignore concentrated edges
https://gitlab.com/graphviz/graphviz/-/issues/2087
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2087.dot"
assert input.exists(), "unexpectedly missing test case"
# process it with Graphviz
warnings = run(["dot", "-Tpng", "-o", os.devnull, input], stderr=subprocess.STDOUT)
# work around macOS warnings
warnings = remove_xtype_warnings(warnings).strip()
# work around ASan informational printing
warnings = remove_asan_summary(warnings)
# no warnings should have been printed
assert (
warnings == ""
), "warnings were printed when processing concentrated duplicate edges"
@pytest.mark.parametrize("html_like_first", (False, True))
def test_2089(html_like_first: bool):
"""
HTML-like and non-HTML-like strings should peacefully coexist
https://gitlab.com/graphviz/graphviz/-/issues/2089
"""
# a graph using an HTML-like string and a non-HTML-like string
if html_like_first:
graph = 'graph {\n a[label=<foo>];\n b[label="foo"];\n}'
else:
graph = 'graph {\n a[label="foo"];\n b[label=<foo>];\n}'
# normalize the graph
canonical = dot("dot", source=graph)
assert "label=foo" in canonical, "non-HTML-like label not found"
assert "label=<foo>" in canonical, "HTML-like label not found"
def test_2089_2():
"""
HTML-like and non-HTML-like strings should peacefully coexist
https://gitlab.com/graphviz/graphviz/-/issues/2089
"""
# find co-located test source
c_src = (Path(__file__).parent / "2089.c").resolve()
assert c_src.exists(), "missing test case"
# run it
link = ["cgraph"]
if is_static_build():
# in static builds, we also need transitive dependencies
link += ["cdt"]
_, _ = run_c(c_src, link=link)
@pytest.mark.skipif(which("dot2gxl") is None, reason="dot2gxl not available")
def test_2092():
"""
an empty node ID should not cause a dot2gxl NULL pointer dereference
https://gitlab.com/graphviz/graphviz/-/issues/2092
"""
dot2gxl = which("dot2gxl")
p = subprocess.run([dot2gxl, "-d"], input='<node id="">', check=False, text=True)
assert p.returncode != 0, "dot2gxl accepted invalid input"
assert p.returncode == 1, "dot2gxl crashed"
@pytest.mark.skipif(which("dot2gxl") is None, reason="dot2gxl not available")
def test_2093():
"""
dot2gxl should handle elements with no ID
https://gitlab.com/graphviz/graphviz/-/issues/2093
"""
dot2gxl = which("dot2gxl")
with subprocess.Popen([dot2gxl, "-d"], stdin=subprocess.PIPE, text=True) as p:
p.communicate('<graph x="">')
assert p.returncode == 1, "dot2gxl did not reject missing ID"
@pytest.mark.skipif(which("dot2gxl") is None, reason="dot2gxl not available")
def test_2094():
"""
dot2gxl should not crash when decoding a closing node tag after a closing
graph tag
https://gitlab.com/graphviz/graphviz/-/issues/2094
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2094.xml"
assert input.exists(), "unexpectedly missing test case"
dot2gxl = which("dot2gxl")
ret = subprocess.call([dot2gxl, "-d", input])
assert ret in (
0,
1,
), "dot2gxl crashed when processing a closing node tag after a closing graph tag"
assert ret == 1, "dot2gxl did not reject malformed XML"
def test_2095():
"""
Exceeding 1000 boxes during computation should not cause a crash
https://gitlab.com/graphviz/graphviz/-/issues/2095
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2095.dot"
assert input.exists(), "unexpectedly missing test case"
# ask Graphviz to process it
dot("pdf", input)
def test_2095_1():
"""
more than 1000 boxes should still be processed in reasonable time
https://gitlab.com/graphviz/graphviz/-/issues/2095
https://gitlab.com/graphviz/graphviz/-/merge_requests/2854
https://gitlab.com/graphviz/graphviz/-/merge_requests/2857
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2095.dot"
assert input.exists(), "unexpectedly missing test case"
timeout = 60 # seconds
if platform.system() == "Windows":
timeout *= 2
# this typically takes ~1s to run, so give a wide margin of error and require that
# that Graphviz finishes within that
run_raw(["dot", "-Tpdf", "-o", os.devnull, input], timeout=timeout)
@pytest.mark.skipif(which("gv2gml") is None, reason="gv2gml not available")
def test_2131():
"""
gv2gml should be able to process basic Graphviz input
https://gitlab.com/graphviz/graphviz/-/issues/2131
"""
# a trivial graph
input = "digraph { a -> b; }"
# ask gv2gml what it thinks of this
gv2gml = which("gv2gml")
try:
run([gv2gml], input=input)
except subprocess.CalledProcessError as e:
raise RuntimeError("gv2gml rejected a basic graph") from e
@pytest.mark.skipif(which("gvpr") is None, reason="gvpr not available")
@pytest.mark.parametrize("examine", ("indices", "tokens"))
def test_2138(examine: str):
"""
gvpr splitting and tokenizing should not result in trailing garbage
https://gitlab.com/graphviz/graphviz/-/issues/2138
"""
# find our co-located GVPR program
script = (Path(__file__).parent / "2138.gvpr").resolve()
assert script.exists(), "missing test case"
# run it with NUL input
gvprbin = which("gvpr")
out = run_raw([gvprbin, "-f", script], stdin=subprocess.DEVNULL)
# Decode into text. We do this instead of `text=True` above because the trailing
# garbage can contain invalid UTF-8 data causing cryptic failures. We want to
# correctly surface this as trailing garbage, not an obscure UTF-8 decoding error.
result = out.decode("utf-8", "replace")
if examine == "indices":
# check no indices are miscalculated
index_re = (
r"^// index of space \(st\) :\s*(?P<index>-?\d+)\s*<< must "
r"NOT be less than -1$"
)
for m in re.finditer(index_re, result, flags=re.MULTILINE):
index = int(m.group("index"))
assert index >= -1, "illegal index computed"
if examine == "tokens":
# check for text the author of 2138.gvpr expected to find
assert (
"// tok[3] >>3456789<< should NOT include trailing spaces or "
"junk chars" in result
), "token 3456789 not found or has trailing garbage"
assert (
"// tok[7] >>012<< should NOT include trailing spaces or "
"junk chars" in result
), "token 012 not found or has trailing garbage"
def test_2159():
"""
space for HTML TDs should be allocated equally when expanding to fill a TR
https://gitlab.com/graphviz/graphviz/-/issues/2159
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2159.dot"
assert input.exists(), "unexpectedly missing test case"
# translate this to SVG
svg = dot("svg", input)
# load it as XML
root = ET.fromstring(svg)
# the first node is expected to contain:
# • 1 polygon for the top column-spanning cell
# • 5 polygons for the bottom row’s cells
# • 1 polygon for the outer table border
polygons = root.findall(
".//{http://www.w3.org/2000/svg}title[.='node1']/../{http://www.w3.org/2000/svg}polygon"
)
assert len(polygons) == 7
# extract the points delimiting the top row
top_row = polygons[0]
points = [
[float(n) for n in p.split(",")] for p in top_row.get("points").split(" ")
]
assert len(points) == 5, "polygon not rectangular"
(ul_x, _), (ll_x, _), (lr_x, _), (ur_x, _), (orig_x, _) = points
assert ul_x == ll_x, "polygon left edge is not vertical"
assert lr_x == ur_x, "polygon right edge is not vertical"
assert orig_x == ul_x, "polygon is not closed"
left = ul_x
right = ur_x
# extract the points for each cell in the bottom row
bottom_row = []
for cell in polygons[1:-1]:
bottom_row += [
[[float(n) for n in p.split(",")] for p in cell.get("points").split(" ")]
]
assert len(bottom_row[-1]) == 5, "polygon not rectangular"
# extract the widths of each cell in the bottom row
widths = []
for cell in bottom_row:
(ul_x, _), _, _, (ur_x, _), _ = cell
widths += [ur_x - ul_x]
# these should approximately sum to the width of the top row
assert math.isclose(
sum(widths), right - left, abs_tol=10
), "bottom row not expanded to fill the space"
# the width of each cell should be approximately equal
for width in widths[1:]:
assert math.isclose(width, widths[0], abs_tol=5), "cells not evenly expanded"
def test_2168():
"""
using spline routing should not cause fdp/neato to infinite loop
https://gitlab.com/graphviz/graphviz/-/issues/2168
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2168.dot"
assert input.exists(), "unexpectedly missing test case"
timeout = 5
if platform.system() == "Windows":
timeout *= 2
fdp = which("fdp")
run_raw([fdp, "-o", os.devnull, input], timeout=timeout)
def test_2168_1():
"""
using spline routing should not cause fdp/neato to infinite loop
https://gitlab.com/graphviz/graphviz/-/issues/2168
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2168_1.dot"
assert input.exists(), "unexpectedly missing test case"
timeout = 5
if platform.system() == "Windows":
timeout *= 2
fdp = which("fdp")
run_raw([fdp, "-o", os.devnull, input], timeout=timeout)
def test_2168_2():
"""
using spline routing should not cause fdp/neato to infinite loop
https://gitlab.com/graphviz/graphviz/-/issues/2168
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2168_2.dot"
assert input.exists(), "unexpectedly missing test case"
timeout = 5
if platform.system() == "Windows":
timeout *= 2
fdp = which("fdp")
run_raw([fdp, "-o", os.devnull, input], timeout=timeout)
def test_2168_3():
"""
using spline routing should not cause fdp/neato to infinite loop
https://gitlab.com/graphviz/graphviz/-/issues/2168
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2168_3.dot"
assert input.exists(), "unexpectedly missing test case"
timeout = 5
if platform.system() == "Windows":
timeout *= 2
fdp = which("fdp")
run_raw([fdp, "-o", os.devnull, input], timeout=timeout)
def test_2168_4():
"""
using spline routing should not cause fdp/neato to infinite loop
https://gitlab.com/graphviz/graphviz/-/issues/2168
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2168_4.dot"
assert input.exists(), "unexpectedly missing test case"
timeout = 5
if platform.system() == "Windows":
timeout *= 2
fdp = which("fdp")
run_raw([fdp, "-o", os.devnull, input], timeout=timeout)
def test_2168_5():
"""
using spline routing should not cause fdp/neato to infinite loop
https://gitlab.com/graphviz/graphviz/-/issues/2168
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2168_5.dot"
assert input.exists(), "unexpectedly missing test case"
fdp = which("fdp")
out = run([fdp, "-o", os.devnull, input], stderr=subprocess.STDOUT)
assert (
"Warning: the bounding boxes of some nodes touch - falling back to straight line edges"
in out
)
def test_2179():
"""
processing a label with an empty line should not yield a warning
https://gitlab.com/graphviz/graphviz/-/issues/2179
"""
# a graph containing a label with an empty line
input = 'digraph "" {\n 0 -> 1 [fontname="Lato",label=<<br/>1>]\n}'
# run a graph with an empty label through Graphviz
with subprocess.Popen(
["dot", "-Tsvg", "-o", os.devnull],
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
) as p:
_, stderr = p.communicate(input)
assert p.returncode == 0
assert (
"Warning: no hard-coded metrics for" not in stderr
), "incorrect warning triggered"
def test_2179_1():
"""
processing a label with a line containing only a space should not yield a
warning
https://gitlab.com/graphviz/graphviz/-/issues/2179
"""
# a graph containing a label with a line containing only a space
input = 'digraph "" {\n 0 -> 1 [fontname="Lato",label=< <br/>1>]\n}'
# run a graph with an empty label through Graphviz
with subprocess.Popen(
["dot", "-Tsvg", "-o", os.devnull],
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
) as p:
_, stderr = p.communicate(input)
assert p.returncode == 0
assert (
"Warning: no hard-coded metrics for" not in stderr
), "incorrect warning triggered"
def test_2183():
"""
processing `splines=ortho`, `concentrate=true` should not crash
https://gitlab.com/graphviz/graphviz/-/issues/2183
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2183.dot"
assert input.exists(), "unexpectedly missing test case"
run_raw(["dot", "-Tsvg", "-G8.5,11!", "-o", os.devnull, input])
@pytest.mark.skipif(which("nop") is None, reason="nop not available")
def test_2184_1():
"""
nop should not reposition labelled graph nodes
https://gitlab.com/graphviz/graphviz/-/issues/2184
"""
# run `nop` on a sample with a labelled graph node at the end
source = Path(__file__).parent / "2184.dot"
assert source.exists(), "missing test case"
nop = which("nop")
nopped = run([nop, source])
# the normalized output should have a graph with no label within
# `clusterSurround1`
m = re.search(
r"\bclusterSurround1\b.*\bgraph\b.*\bcluster1\b", nopped, flags=re.DOTALL
)
assert m is not None, "nop rearranged a graph in a not-semantically-preserving way"
def test_2184_2():
"""
canonicalization should not reposition labelled graph nodes
https://gitlab.com/graphviz/graphviz/-/issues/2184
"""
# canonicalize a sample with a labelled graph node at the end
source = Path(__file__).parent / "2184.dot"
assert source.exists(), "missing test case"
canonicalized = dot("canon", source)
# the canonicalized output should have a graph with no label within
# `clusterSurround1`
m = re.search(
r"\bclusterSurround1\b.*\bgraph\b.*\bcluster1\b", canonicalized, flags=re.DOTALL
)
assert (
m is not None
), "`dot -Tcanon` rearranged a graph in a not-semantically-preserving way"
def test_2185_1():
"""
GVPR should deal with strings correctly
https://gitlab.com/graphviz/graphviz/-/issues/2185
"""
# find our collocated GVPR program
script = Path(__file__).parent / "2185.gvpr"
assert script.exists(), "missing test case"
# run this with NUL input, checking output is valid UTF-8
gvpr(script)
def test_2185_2():
"""
GVPR should deal with strings correctly
https://gitlab.com/graphviz/graphviz/-/issues/2185
"""
# find our collocated GVPR program
script = Path(__file__).parent / "2185.gvpr"
assert script.exists(), "missing test case"
# run this with NUL input
gvprbin = which("gvpr")
out = run_raw([gvprbin, "-f", script], stdin=subprocess.DEVNULL)
# decode output in a separate step to gracefully cope with garbage unicode
out = out.decode("utf-8", "replace")
# deal with Windows eccentricities
eol = "\r\n" if platform.system() == "Windows" else "\n"
expected = f"one two three{eol}"
# check the first line is as expected
assert out.startswith(expected), "incorrect GVPR interpretation"
def test_2185_3():
"""
GVPR should deal with strings correctly
https://gitlab.com/graphviz/graphviz/-/issues/2185
"""
# find our collocated GVPR program
script = Path(__file__).parent / "2185.gvpr"
assert script.exists(), "missing test case"
# run this with NUL input
gvprbin = which("gvpr")
out = run_raw([gvprbin, "-f", script], stdin=subprocess.DEVNULL)
# decode output in a separate step to gracefully cope with garbage unicode
out = out.decode("utf-8", "replace")
# deal with Windows eccentricities
eol = "\r\n" if platform.system() == "Windows" else "\n"
expected = f"one two three{eol}one five three{eol}"
# check the first two lines are as expected
assert out.startswith(expected), "incorrect GVPR interpretation"
def test_2185_4():
"""
GVPR should deal with strings correctly
https://gitlab.com/graphviz/graphviz/-/issues/2185
"""
# find our collocated GVPR program
script = Path(__file__).parent / "2185.gvpr"
assert script.exists(), "missing test case"
# run this with NUL input
gvprbin = which("gvpr")
out = run_raw([gvprbin, "-f", script], stdin=subprocess.DEVNULL)
# decode output in a separate step to gracefully cope with garbage unicode
out = out.decode("utf-8", "replace")
# deal with Windows eccentricities
eol = "\r\n" if platform.system() == "Windows" else "\n"
expected = f"one two three{eol}one five three{eol}99{eol}"
# check the first three lines are as expected
assert out.startswith(expected), "incorrect GVPR interpretation"
def test_2185_5():
"""
GVPR should deal with strings correctly
https://gitlab.com/graphviz/graphviz/-/issues/2185
"""
# find our collocated GVPR program
script = Path(__file__).parent / "2185.gvpr"
assert script.exists(), "missing test case"
# run this with NUL input
gvprbin = which("gvpr")
out = run_raw([gvprbin, "-f", script], stdin=subprocess.DEVNULL)
# decode output in a separate step to gracefully cope with garbage unicode
out = out.decode("utf-8", "replace")
# deal with Windows eccentricities
eol = "\r\n" if platform.system() == "Windows" else "\n"
expected = f"one two three{eol}one five three{eol}99{eol}Constant{eol}"
# check the first four lines are as expected
assert out.startswith(expected), "incorrect GVPR interpretation"
@pytest.mark.xfail(strict=True) # FIXME
def test_2193():
"""
the canonical format should be stable
https://gitlab.com/graphviz/graphviz/-/issues/2193
"""
# find our collocated test case
input = Path(__file__).parent / "2193.dot"
assert input.exists(), "unexpectedly missing test case"
# derive the initial canonicalization
canonical = dot("canon", input)
# now canonicalize this again to see if it changes
new = dot("canon", source=canonical)
assert canonical == new, "canonical translation is not stable"
@pytest.mark.skipif(which("gvpr") is None, reason="GVPR not available")
def test_2211():
"""
GVPR’s `index` function should return correct results
https://gitlab.com/graphviz/graphviz/-/issues/2211
"""
# find our collocated test case
program = Path(__file__).parent / "2211.gvpr"
assert program.exists(), "unexpectedly missing test case"
# run it through GVPR
output = gvpr(program)
# it should have found the right string indices for characters
assert (
output == "index: 9 should be 9\n"
"index: 3 should be 3\n"
"index: -1 should be -1\n"
)
def test_2215():
"""
Graphviz should not crash with `-v`
https://gitlab.com/graphviz/graphviz/-/issues/2215
"""
# try it on a simple graph
input = "graph g { a -- b; }"
run(["dot", "-v"], input=input)
# try the same on a labelled version of this graph
input = 'graph g { node[label=""] a -- b; }'
run(["dot", "-v"], input=input)
@pytest.mark.xfail(
is_rocky(),
strict=True,
reason="https://gitlab.com/graphviz/graphviz/-/issues/2241",
)
def test_2241():
"""
a graph with two nodes and one edge in each direction should be rendered
with two visually distinct edges when using the neato engine and
splines=true, not two edges on top of each other, visually looking like a
single edge with both head and tail arrowheads.
https://gitlab.com/graphviz/graphviz/-/issues/2241
"""
# find our collocated test case
input = Path(__file__).parent / "2241.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
svg = dot("svg", input)
# load this as XML
root = ET.fromstring(svg)
# the output is expected to contain two paths which are well separated
paths = root.findall(".//{http://www.w3.org/2000/svg}path")
assert len(paths) == 2, "expected two paths in output"
ellipses = root.findall(".//{http://www.w3.org/2000/svg}ellipse")
assert len(ellipses) == 2, "expected two ellipses in output"
# calculate the x coordinate of a vertical line which is equidistant from the two nodes
x = statistics.mean(float(ellipse.get("cx")) for ellipse in ellipses)
# for each edge path, get the y coordinate of a point on a line between the edge's endpoints
# where the line intersects the node equidistant vertical line
y_coordinates = []
for path in paths:
d_attribute = path.get("d")
points_str = re.split("[ C]", d_attribute.replace("M", ""))
assert (
len(points_str) == 4
), "expected four points in the 'd' attribute of the 'path' element"
points = [
(float(x_str), float(y_str))
for x_str, y_str in [point_str.split(",") for point_str in points_str]
]
dx = points[3][0] - points[0][0]
dy = points[3][1] - points[0][1]
y = points[0][1] + dy / dx * (x - points[0][0])
y_coordinates.append(y)
# check that the lines are well separated vertically where they intersect the node equidistant
# vertical line
y_coordinates_abs_difference = abs(y_coordinates[1] - y_coordinates[0])
y_coordinates_abs_difference_when_ok = 11.5004437538844
y_coordinates_abs_difference_when_not_ok = 0.00658290568043185
min_y_coordinates_abs_difference = (
y_coordinates_abs_difference_when_ok + y_coordinates_abs_difference_when_not_ok
) / 2
assert y_coordinates_abs_difference > min_y_coordinates_abs_difference
def test_2242():
"""
repeated runs of a graph with subgraphs should yield a stable result
https://gitlab.com/graphviz/graphviz/-/issues/2242
"""
# get our baseline reference
input = Path(__file__).parent / "2242.dot"
assert input.exists(), "unexpectedly missing test case"
ref = dot("png", input)
# now repeat this, expecting it not to change
for _ in range(20):
png = dot("png", input)
assert ref == png, "repeated rendering changed output"
@pytest.mark.skipif(
is_static_build(),
reason="dynamic libraries are unavailable to link against in static builds",
)
@pytest.mark.skipif(
platform.system() == "Windows"
and which("dot") is not None
and is_asan_instrumented(which("dot")),
reason="ASan runs out of memory in its internal pool on Windows",
)
def test_2331(tmp_path: Path):
"""
the example in this test should not cause a double-free
https://gitlab.com/graphviz/graphviz/-/issues/2331
"""
# find co-located test source
c_src = (Path(__file__).parent / "2331.c").resolve()
assert c_src.exists(), "missing test case"
# From here, we essentially want to `run_c(c_src, …)`. However we cannot easily do
# this because we want to directly link against plugins (instead of `dlopen` them),
# libraries that are not in the linker’s search path. So instead we have to take a
# more manual approach.
# find the plugins we need to link against
core = _find_plugin_so("core")
assert core is not None, "core plugin library not found"
dot_layout = _find_plugin_so("dot_layout")
assert dot_layout is not None, "dot layout plugin library not found"
# compile the test code
exe = tmp_path / "a.exe"
compile_c(c_src, link=["cgraph", "gvc", core, dot_layout], dst=exe)
# teach the runtime linker how to find the plugins
env = os.environ.copy()
ld_library_path = f"{core.parent}:{dot_layout.parent}"
prefix = ""
if is_macos():
if "DYLD_LIBRARY_PATH" in env:
env["DYLD_LIBRARY_PATH"] = f"{ld_library_path}:{env['DYLD_LIBRARY_PATH']}"
else:
env["DYLD_LIBRARY_PATH"] = ld_library_path
prefix = f"env DYLD_LIBRARY_PATH={env['DYLD_LIBRARY_PATH']} "
else:
if "LD_LIBRARY_PATH" in env:
env["LD_LIBRARY_PATH"] = f"{ld_library_path}:{env['LD_LIBRARY_PATH']}"
else:
env["LD_LIBRARY_PATH"] = ld_library_path
prefix = f"env LD_LIBRARY_PATH={env['LD_LIBRARY_PATH']} "
# run the test code
print(f"+ {prefix}{shlex.quote(str(exe))}")
subprocess.run([exe], env=env, check=True)
def test_2342():
"""
using an arrow with size 0 should not trigger an assertion failure
https://gitlab.com/graphviz/graphviz/-/issues/2342
"""
# find our collocated test case
input = Path(__file__).parent / "2342.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("svg", input)
@pytest.mark.skipif(
is_static_build(),
reason="dynamic libraries are unavailable to link against in static builds",
)
def test_2356():
"""
Using `mindist` programmatically in a loop should not cause Windows crashes
https://gitlab.com/graphviz/graphviz/-/issues/2356
"""
# find co-located test source
c_src = (Path(__file__).parent / "2356.c").resolve()
assert c_src.exists(), "missing test case"
# run the test
run_c(c_src, link=["cgraph", "gvc"])
def test_2361():
"""
using `ortho` and `concentrate` in combination should not cause a crash
https://gitlab.com/graphviz/graphviz/-/issues/2361
"""
# find our collocated test case
input = Path(__file__).parent / "2361.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("png", input)
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/2295"
)
def test_2295():
"""
tooltips should work in PDFs
https://gitlab.com/graphviz/graphviz/-/issues/2295
"""
# find our collocated test case
input = Path(__file__).parent / "2295.dot"
assert input.exists(), "unexpectedly missing test case"
# translate it to PDF
pdf = dot("pdf", input)
assert re.search(rb"\bhi mom\b", pdf) is not None, "tooltip not propagated to PDF"
@pytest.mark.parametrize("arg", ("--filepath", "-Gimagepath"))
def test_2396(arg: str):
"""
`--filepath` should work as a replacement for `$GV_FILE_PATH`
https://gitlab.com/graphviz/graphviz/-/issues/2396
"""
# use an arbitrary image we have in the tree
image = Path(__file__).parent / "../cmd/gvedit/images/save.png"
assert image.exists(), "missing test data"
# a graph that tries to use the image by relative path
slash = "/" if arg == "--filepath" else ""
source = f'graph {{ N[image="{slash}save.png"]; }}'
# run this through Graphviz
proc = subprocess.run(
["dot", "-Tsvg", f"{arg}={image.parent}"],
capture_output=True,
input=source,
cwd=Path(__file__).parent,
text=True,
check=True,
)
# work around macOS warnings
stderr = remove_xtype_warnings(proc.stderr).strip()
# work around ASan informational printing
stderr = remove_asan_summary(stderr)
assert stderr == "", "loading an image by relative path produced warnings"
# whether we used `imagepath` or `filepath` should affect whether we get a leading
# slash
if arg == "-Gimagepath":
assert '"save.png"' in proc.stdout, "incorrect relative path in output"
else:
assert '"/save.png"' in proc.stdout, "incorrect relative path in output"
def test_2481():
"""
`dot` should not exit with a syntax error if keywords are mixed-case
https://gitlab.com/graphviz/graphviz/-/issues/2481
"""
# try a simple graph with uppercase characters in 'digraph'
input = "diGraph { }"
# ensure this does not trigger warnings
with subprocess.Popen(
["dot"],
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
) as p:
_, stderr = p.communicate(input)
assert p.returncode == 0, "mixed-case keyword was rejected"
assert "syntax error" not in stderr, "dot displayed a syntax error message"
@pytest.mark.skipif(
is_static_build(),
reason="dynamic libraries are unavailable to link against in static builds",
)
def test_2484():
"""
Graphviz context should not preserve state across calls
https://gitlab.com/graphviz/graphviz/-/issues/2484
"""
# find our co-located driver
c_src = (Path(__file__).parent / "2484.c").resolve()
assert c_src.exists(), "missing test case"
# find co-located input to the driver
dot_src = (Path(__file__).parent / "2484.dot").resolve()
assert dot_src.exists(), "missing test case"
# compile and run it
run_c(
c_src,
["-Kdot", "-Tpng", str(dot_src), "-o", os.devnull],
link=["cgraph", "gvc"],
)
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/2592"
)
def test_2592():
"""
pack modes should not remove xlabels
https://gitlab.com/graphviz/graphviz/-/issues/2592
"""
# find our collocated test case
input = Path(__file__).parent / "2592.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
svg = dot("svg", input)
assert "comment not included" in svg, "missing xlabel in packed graph"
def test_package_version():
"""
The graphviz_version.h header should define a non-empty PACKAGE_VERSION
"""
# find co-located test source
c_src = (Path(__file__).parent / "get-package-version.c").resolve()
assert c_src.exists(), "missing test case"
# run the test
package_version, _ = run_c(c_src)
assert (
package_version.strip() != ""
), "invalid PACKAGE_VERSION in graphviz_version.h"
def test_user_shapes():
"""
Graphviz should understand how to embed a custom SVG image as a node’s shape
"""
# find our collocated test case
input = Path(__file__).parent / "usershape.dot"
assert input.exists(), "unexpectedly missing test case"
# ask Graphviz to translate this to SVG
output = run(["dot", "-Tsvg", input], cwd=os.path.dirname(__file__))
# the external SVG should have been parsed and is now referenced
assert '<image xlink:href="usershape.svg" width="62px" height="44px" ' in output
def test_xdot_json():
"""
check the output of xdot’s JSON API
"""
# find our collocated C helper
c_src = Path(__file__).parent / "xdot2json.c"
# some valid xdot commands to process
input = "c 9 -#fffffe00 C 7 -#ffffff P 4 0 0 0 36 54 36 54 0"
# ask our C helper to process this
output, err = run_c(c_src, input=input, link=["xdot"])
assert err == ""
# confirm the output was what we expected
data = json.loads(output)
assert data == [
{"c": "#fffffe00"},
{"C": "#ffffff"},
{"P": [0.0, 0.0, 0.0, 36.0, 54.0, 36.0, 54.0, 0.0]},
]
@pytest.mark.skipif(which("gvmap") is None, reason="gvmap not available")
def test_gvmap_fclose():
"""
gvmap should not attempt to fclose(NULL). This example will trigger a crash if
this bug has been reintroduced and Graphviz is built with ASan support.
"""
# a reasonable input graph
input = (
'graph "Alík: Na vlastní oči" {\n'
' graph [bb="0,0,128.9,36",\n'
" concentrate=true,\n"
" overlap=prism,\n"
" start=3\n"
" ];\n"
' node [label="\\N"];\n'
" {\n"
" bob [height=0.5,\n"
' pos="100.95,18",\n'
" width=0.77632];\n"
" }\n"
" {\n"
" alice [height=0.5,\n"
' pos="32.497,18",\n'
" width=0.9027];\n"
" }\n"
' alice -- bob [pos="65.119,18 67.736,18 70.366,18 72.946,18"];\n'
" bob -- alice;\n"
"}"
)
# pass this through gvmap
gvmap = which("gvmap")
proc = subprocess.run([gvmap], input=input.encode("utf-8"), check=False)
assert proc.returncode in (0, 1), "gvmap crashed"
@pytest.mark.skipif(which("gvpr") is None, reason="gvpr not available")
def test_gvpr_usage(tmp_path: Path):
"""
gvpr usage information should be included when erroring on a malformed command
"""
# ask GVPR to process a non-existent file
gvprbin = which("gvpr")
with subprocess.Popen(
[gvprbin, "-v", "-f", "nofile"],
stderr=subprocess.PIPE,
cwd=tmp_path,
text=True,
) as p:
_, stderr = p.communicate()
assert p.returncode != 0, "GVPR accepted a non-existent file"
# the stderr output should have contained full usage instructions
assert (
"-o <ofile> - write output to <ofile>; stdout by default" in stderr
), "truncated or malformed GVPR usage information"
def test_2225():
"""
sfdp should not segfault with curved splines
https://gitlab.com/graphviz/graphviz/-/issues/2225
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2225.dot"
assert input.exists(), "unexpectedly missing test case"
# run this through sfdp
sfdp = which("sfdp")
p = subprocess.run(
[sfdp, "-Gsplines=curved", "-o", os.devnull, input],
stderr=subprocess.PIPE,
check=False,
text=True,
)
# if sfdp was built without libgts, it will not handle anything non-trivial
no_gts_error = "remove_overlap: Graphviz not built with triangulation library"
if no_gts_error in p.stderr:
assert p.returncode != 0, "sfdp returned success after an error message"
return
p.check_returncode()
def test_2257():
"""
`$GV_FILE_PATH` being set should prevent Graphviz from running
`$GV_FILE_PATH` was an environment variable formerly used to implement a file
system sandboxing policy when Graphviz was exposed to the internet via a web
server. These days, there are safer and more robust techniques to sandbox
Graphviz and so `$GV_FILE_PATH` usage has been removed. But if someone
attempts to use this legacy mechanism, we do not want Graphviz to
“fail-open,” starting anyway and silently ignoring `$GV_FILE_PATH` giving
the user the false impression the sandboxing is in force.
https://gitlab.com/graphviz/graphviz/-/issues/2257
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2257.dot"
assert input.exists(), "unexpectedly missing test case"
env = os.environ.copy()
env["GV_FILE_PATH"] = "/tmp"
# Graphviz should refuse to process an input file
with pytest.raises(subprocess.CalledProcessError):
run_raw(["dot", "-Tsvg", input, "-o", os.devnull], env=env)
def test_2258():
"""
'id' attribute should be propagated to all graph children in output
https://gitlab.com/graphviz/graphviz/-/issues/2258
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2258.dot"
assert input.exists(), "unexpectedly missing test case"
# translate this to SVG
svg = dot("svg", input)
# load this as XML
root = ET.fromstring(svg)
# the output is expected to contain a number of linear gradients, all of which
# are semantic children of graph marked `id = "G2"`
gradients = root.findall(".//{http://www.w3.org/2000/svg}linearGradient")
assert len(gradients) > 0, "no gradients in output"
for gradient in gradients:
assert "G2" in gradient.get("id"), "ID was not applied to linear gradients"
def test_2270(tmp_path: Path):
"""
`-O` should result in the expected output filename
https://gitlab.com/graphviz/graphviz/-/issues/2270
"""
# write a simple graph
input = tmp_path / "hello.gv"
input.write_text("digraph { hello -> world }", encoding="utf-8")
# process it with Graphviz
run_raw(["dot", "-T", "plain:dot:core", "-O", "hello.gv"], cwd=tmp_path)
# it should have produced output in the expected location
output = tmp_path / "hello.gv.core.dot.plain"
assert output.exists(), "-O resulted in an unexpected output filename"
@pytest.mark.skipif(
is_static_build(),
reason="dynamic libraries are unavailable to link against in static builds",
)
def test_2272():
"""
using `agmemread` with an unterminated string should not fail assertions
https://gitlab.com/graphviz/graphviz/-/issues/2272
"""
# find co-located test source
c_src = (Path(__file__).parent / "2272.c").resolve()
assert c_src.exists(), "missing test case"
# run the test
run_c(c_src, link=["cgraph", "gvc"])
def test_2272_2():
"""
An unterminated string in the source should not crash Graphviz. Variant of
`test_2272`.
"""
# a graph with an open string
graph = 'graph { a[label="abc'
# process it with Graphviz, which should not crash
p = subprocess.run(["dot", "-o", os.devnull], input=graph, check=False, text=True)
assert p.returncode != 0, "dot accepted invalid input"
assert p.returncode == 1, "dot crashed"
def test_2278():
"""
the shortcut for setting ubiquitous properties should work as expected
https://gitlab.com/graphviz/graphviz/-/issues/2278
"""
# a simple graph that will involve fonts
graph = 'digraph { a->b[label="hello world"]; }'
# process this, setting the default font
svg = run(
["dot", "-Tsvg", "-Efontname=Arial", "-Gfontname=Arial", "-Nfontname=Arial"],
input=graph,
)
# the output of this should differ from the default output
default = dot("svg", source=graph)
assert svg != default, "-E/-G/-N had no effect"
# the shortcut for setting all of these should behave as expected
svg_a = run(["dot", "-Tsvg", "-Afontname=Arial"], input=graph)
assert svg == svg_a, "-A was not equivalent to -E+-G+-N"
def test_2282():
"""
using the `fdp` layout with JSON output should result in valid JSON
https://gitlab.com/graphviz/graphviz/-/issues/2282
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2282.dot"
assert input.exists(), "unexpectedly missing test case"
# translate this to JSON
output = dot("json", input)
# confirm this is valid JSON
json.loads(output)
def test_2283():
"""
`beautify=true` should correctly space nodes
https://gitlab.com/graphviz/graphviz/-/issues/2283
"""
# find our collocated test case
input = Path(__file__).parent / "2283.dot"
assert input.exists(), "unexpectedly missing test case"
# translate this to SVG
p = subprocess.run(
["dot", "-Tsvg", input], capture_output=True, check=False, text=True
)
# if sfdp was built without libgts, it will not handle anything non-trivial
no_gts_error = "remove_overlap: Graphviz not built with triangulation library"
if no_gts_error in p.stderr:
assert p.returncode != 0, "sfdp returned success after an error message"
return
p.check_returncode()
svg = p.stdout
# parse this into something we can inspect
root = ET.fromstring(svg)
# find node N0
n0s = root.findall(
".//{http://www.w3.org/2000/svg}title[.='N0']/../{http://www.w3.org/2000/svg}ellipse"
)
assert len(n0s) == 1, "failed to locate node N0"
n0 = n0s[0]
# find node N1
n1s = root.findall(
".//{http://www.w3.org/2000/svg}title[.='N1']/../{http://www.w3.org/2000/svg}ellipse"
)
assert len(n1s) == 1, "failed to locate node N1"
n1 = n1s[0]
# find node N6
n6s = root.findall(
".//{http://www.w3.org/2000/svg}title[.='N6']/../{http://www.w3.org/2000/svg}ellipse"
)
assert len(n6s) == 1, "failed to locate node N6"
n6 = n6s[0]
# N1 and N6 should not have been drawn on top of each other
n1_x = float(n1.attrib["cx"])
n1_y = float(n1.attrib["cy"])
n6_x = float(n6.attrib["cx"])
n6_y = float(n6.attrib["cy"])
def sameish(a: float, b: float) -> bool:
EPSILON = 0.2
return -EPSILON < abs(a - b) < EPSILON
assert not (
sameish(n1_x, n6_x) and sameish(n1_y, n6_y)
), "N1 and N6 placed identically"
# use the Law of Cosines to compute the angle between N0→N1 and N0→N6
n0_x = float(n0.attrib["cx"])
n0_y = float(n0.attrib["cy"])
n0_n1_dist = math.dist((n0_x, n0_y), (n1_x, n1_y))
n0_n6_dist = math.dist((n0_x, n0_y), (n6_x, n6_y))
n1_n6_dist = math.dist((n1_x, n1_y), (n6_x, n6_y))
angle = math.acos(
(n0_n1_dist**2 + n0_n6_dist**2 - n1_n6_dist**2) / (2 * n0_n1_dist * n0_n6_dist)
)
number_of_radial_nodes = 6
assert sameish(
angle, 2 * math.pi / number_of_radial_nodes
), "nodes not placed evenly"
def test_2285():
"""
using the `svg_inline` output should result in SVG you can inline to HTML
https://gitlab.com/graphviz/graphviz/-/issues/2285
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2285.dot"
assert input.exists(), "unexpectedly missing test case"
# translate this to JSON
output = dot("svg_inline", input)
assert "<?xml" not in output, "<?xml in output"
assert "<!DOCTYPE" not in output, "<?xml in output"
assert "xmlns" not in output, "xmlns in output"
assert "<svg" in output, "<svg not in output"
@pytest.mark.skipif(which("gxl2gv") is None, reason="gxl2gv not available")
def test_2300_1():
"""
translating GXL with an attribute `name` should not crash
https://gitlab.com/graphviz/graphviz/-/issues/2300
"""
# locate our associated test case containing a node attribute `name`
input = Path(__file__).parent / "2300.gxl"
assert input.exists(), "unexpectedly missing test case"
# ask `gxl2gv` to process this
gxl2gv = which("gxl2gv")
run_raw([gxl2gv, input])
def test_2307():
"""
'id' attribute should be propagated to 'url' links in SVG output
https://gitlab.com/graphviz/graphviz/-/issues/2307
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2258.dot"
assert input.exists(), "unexpectedly missing test case"
# translate this to SVG
svg = dot("svg", input)
# load this as XML
root = ET.fromstring(svg)
# the output is expected to contain a number of polygons, any of which have
# `url` fills should include the ID “G2”
polygons = root.findall(".//{http://www.w3.org/2000/svg}polygon")
assert len(polygons) > 0, "no polygons in output"
for polygon in polygons:
m = re.match(r"url\((?P<url>.*)\)$", polygon.get("fill"))
if m is None:
continue
assert (
re.search(r"\bG2_", m.group("url")) is not None
), "ID G2 was not applied to polygon fill url"
def test_2325():
"""
using more than 63 styles and/or more than 128 style bytes should not trigger
an out-of-bounds memory read
https://gitlab.com/graphviz/graphviz/-/issues/2325
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2325.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("svg", input)
@pytest.mark.skipif(shutil.which("groff") is None, reason="groff not available")
def test_2341():
"""
PIC backend should generate correct comments
https://gitlab.com/graphviz/graphviz/-/issues/2341
"""
# a simple graph
source = "digraph { a -> b; }"
# generate PIC from this
pic = dot("pic", source=source)
# run this through groff
groffed = run(["groff", "-Tascii", "-p"], input=pic)
# it should not contain any comments
assert (
re.search(r"^\s*#", groffed) is None
), "Graphviz comment remains in groff output"
def test_2352():
"""
referencing an all-one-line external SVG file should work
https://gitlab.com/graphviz/graphviz/-/issues/2352
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2352.dot"
assert input.exists(), "unexpectedly missing test case"
# translate it to SVG
svg = run(["dot", "-Tsvg", input], cwd=Path(__file__).parent)
assert '<image xlink:href="EDA.svg" ' in svg, "external file reference missing"
def test_2352_1():
"""
variant of 2352 with a leading space in front of `<svg`
https://gitlab.com/graphviz/graphviz/-/issues/2352
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2352_1.dot"
assert input.exists(), "unexpectedly missing test case"
# translate it to SVG
svg = run(["dot", "-Tsvg", input], cwd=Path(__file__).parent)
assert '<image xlink:href="EDA_1.svg" ' in svg, "external file reference missing"
def test_2352_2():
"""
variant of 2352 that spaces viewBox such that it is on a 200-character line
boundary
https://gitlab.com/graphviz/graphviz/-/issues/2352
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2352_2.dot"
assert input.exists(), "unexpectedly missing test case"
# translate it to SVG
svg = run(["dot", "-Tsvg", input], cwd=Path(__file__).parent)
assert '<image xlink:href="EDA_2.svg" ' in svg, "external file reference missing"
def test_2355():
"""
Using >127 layers should not crash Graphviz
https://gitlab.com/graphviz/graphviz/-/issues/2355
"""
# construct a graph with 128 layers
graph = io.StringIO()
graph.write("digraph {\n")
layers = ":".join(f"l{i}" for i in range(128))
graph.write(f' layers="{layers}";\n')
for i in range(128):
graph.write(f' n{i}[layer="l{i}"];\n')
graph.write("}\n")
# process this with dot
dot("svg", source=graph.getvalue())
@pytest.mark.parametrize("testcase", ("2368.dot", "2368_1.dot"))
@pytest.mark.xfail(strict=True) # FIXME
def test_2368(testcase: str):
"""
routesplines should not corrupt its `prev` and `next` indices
https://gitlab.com/graphviz/graphviz/-/issues/2368
"""
# locate our associated test case in this directory
input = Path(__file__).parent / testcase
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("svg", input)
@pytest.mark.skipif(shutil.which("tclsh") is None, reason="tclsh not available")
def test_2370():
"""
tcldot should have a version number TCL accepts
https://gitlab.com/graphviz/graphviz/-/issues/2370
"""
# if this appears to be an ASan-enabled CI job, teach `tclsh` to load ASan’s
# supporting library because it is otherwise unaware that Tcldot depends on this
# being loaded first
env = os.environ.copy()
dot_exe = which("dot")
if is_asan_instrumented(dot_exe):
cc = os.environ.get("CC", "gcc")
libasan = run([cc, "-print-file-name=libasan.so"]).strip()
print(f"setting LD_PRELOAD={libasan}")
env["LD_PRELOAD"] = libasan
# ask TCL to import the Graphviz package
response = run(
["tclsh"],
stderr=subprocess.STDOUT,
input="package require Tcldot;",
env=env,
)
assert (
"error reading package index file" not in response
), "tcldot cannot be loaded by TCL"
def test_2371():
"""
Large graphs should not cause rectangle area calculation overflows
https://gitlab.com/graphviz/graphviz/-/issues/2371
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2371.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
run_raw(["dot", "-Tsvg", "-Knop2", "-o", os.devnull, input])
@pytest.mark.skipif(
platform.system() == "Windows",
reason="gvplugin_list symbol is not exposed on Windows",
)
def test_2375():
"""
`gvplugin_list` should return full plugin names
https://gitlab.com/graphviz/graphviz/-/issues/2375
"""
# find co-located test source
c_src = (Path(__file__).parent / "2375.c").resolve()
assert c_src.exists(), "missing test case"
# run the test
run_c(c_src, link=["gvc"])
def test_2377():
"""
3 letter hex color codes should be accepted
https://gitlab.com/graphviz/graphviz/-/issues/2377
"""
# run some 6 letter color input through Graphviz
input = 'digraph { n [color="#cc0000" fillcolor="#ffcc00" style=filled] }'
svg1 = dot("svg", source=input)
# try the equivalent with 3 letter colors
input = 'digraph { n [color="#c00" fillcolor="#fc0" style=filled] }'
svg2 = dot("svg", source=input)
assert svg1 == svg2, "3 letter hex colors were not translated correctly"
def test_2390():
"""
using an out of range `xdotversion` should not crash Graphviz
https://gitlab.com/graphviz/graphviz/-/issues/2390
"""
# some input with an invalid large `xdotversion`
input = 'graph { xdotversion=99; n[label="hello world"]; }'
# run this through Graphviz
dot("xdot", source=input)
def test_2391():
"""
`nslimit1=0` should not cause Graphviz to crash
https://gitlab.com/graphviz/graphviz/-/issues/2391
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2391.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("svg", input)
def test_2391_1():
"""
`nslimit1=0` with a label should not cause Graphviz to crash
https://gitlab.com/graphviz/graphviz/-/issues/2391
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2391_1.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("svg", input)
def test_2397():
"""
escapes in strings should be handled correctly
https://gitlab.com/graphviz/graphviz/-/issues/2397
"""
# find co-located test source
c_src = (Path(__file__).parent / "2397.c").resolve()
assert c_src.exists(), "missing test case"
# run this to generate a graph
link = ["cgraph", "gvc"]
if is_static_build():
# in static builds, we also need transitive dependencies
link += ["cdt"]
source, _ = run_c(c_src, link=link)
# this should have produced a valid graph
dot("svg", source=source)
def test_2397_1():
"""
a variant of test_2397 that confirms the same works via the command line
https://gitlab.com/graphviz/graphviz/-/issues/2397
"""
source = 'digraph { a[label="foo\\\\\\"bar"]; }'
# run this through dot
output = dot("dot", source=source)
# the output should be valid dot
dot("svg", source=output)
@pytest.mark.skipif(shutil.which("shellcheck") is None, reason="shellcheck unavailable")
def test_2404():
"""
shell syntax used by gvmap should be correct
https://gitlab.com/graphviz/graphviz/-/issues/2404
"""
gvmap_sh = Path(__file__).parent / "../cmd/gvmap/gvmap.sh"
run_raw(["shellcheck", "-S", "error", gvmap_sh])
def test_2406():
"""
arrow types like `invdot` and `onormalonormal` should be displayed correctly
https://gitlab.com/graphviz/graphviz/-/issues/2406
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2406.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
output = dot("svg", input)
# the rounded hollows should be present
assert re.search(r"\bellipse\b", output), "missing element of invdot arrow"
@pytest.mark.parametrize("source", ("2413_1.dot", "2413_2.dot"))
def test_2413(source: str):
"""
graphs that induce an edge length > 65535 should be supported
https://gitlab.com/graphviz/graphviz/-/issues/2413
"""
# locate our associated test case in this directory
input = Path(__file__).parent / source
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
proc = subprocess.run(
["dot", "-Tsvg", "-o", os.devnull, input],
stderr=subprocess.PIPE,
check=True,
text=True,
)
# work around macOS warnings
stderr = remove_xtype_warnings(proc.stderr).strip()
# work around ASan informational printing
stderr = remove_asan_summary(stderr)
# no warnings should have been generated
assert stderr == "", "long edges resulted in a warning"
def test_2429():
"""
the vt target should be usable
https://gitlab.com/graphviz/graphviz/-/issues/2429
"""
# a basic graph
source = "digraph { a -> b; }"
# run it through Graphviz
dot("vt", source=source)
@pytest.mark.skipif(which("nop") is None, reason="nop not available")
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/2436"
)
def test_2436():
"""
nop should preserve empty labels
https://gitlab.com/graphviz/graphviz/-/issues/2436
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2436.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through nop
nop = which("nop")
output = run([nop, input])
# the empty label should be present
assert re.search(r'\blabel\s*=\s*""', output), "empty label was not preserved"
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/2434"
)
def test_2434():
"""
the order in which `agmemread` and `gvContext` calls are made should have no impact
https://gitlab.com/graphviz/graphviz/-/issues/2434
"""
# find co-located test source
c_src = (Path(__file__).parent / "2434.c").resolve()
assert c_src.exists(), "missing test case"
# generate an SVG by calling `gvContext` first
before, _ = run_c(c_src, ["before"], link=["cgraph", "gvc"])
# generate an SVG by calling `gvContext` second
after, _ = run_c(c_src, ["after"], link=["cgraph", "gvc"])
# resulting images should be identical
assert before == after, "agmemread/gvContext ordering affected image output"
def test_2437():
"""
both an arrowhead and an arrowtail shall be created when using dir=both,
compass ports, an edge default attribute and rank=same
https://gitlab.com/graphviz/graphviz/-/issues/2437
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2437.dot"
assert input.exists(), "unexpectedly missing test case"
# translate this to SVG
svg = dot("svg", input)
# load this as XML
root = ET.fromstring(svg)
# The output is expected to contain tree polygons. The graph "background"
# polygon, the arrowhead polygon and the arrowtail polygon.
polygons = root.findall(".//{http://www.w3.org/2000/svg}polygon")
assert len(polygons) == 3, "wrong number of polygons in output"
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/2416"
)
def test_2416():
"""
`splines=curved` should not affect arrow directions
https://gitlab.com/graphviz/graphviz/-/issues/2416
"""
# an input graph that provokes the problem
input = "digraph G { splines=curved; b -> a; a -> b; }"
# run it through Graphviz
output = dot("json", source=input)
data = json.loads(output)
edges = data["edges"]
assert len(edges) == 2, "unexpected number of output edges"
# extract the height each edge’s arrow starts at
y_1 = edges[0]["_hdraw_"][3]["points"][0][1]
y_2 = edges[1]["_hdraw_"][3]["points"][0][1]
# assuming the graph is vertical, these should not be too close
assert abs(y_1 - y_2) > 1, "edge arrows appear to be drawn next to the same node"
@pytest.mark.skipif(which("gvpr") is None, reason="GVPR not available")
def test_2454():
"""
gvpr should support sscanf
https://gitlab.com/graphviz/graphviz/-/issues/2454
"""
# an input graph that provokes the problem
input = "graph x{a -- {b c}}"
# run it through Graphviz
output = dot("dot", source=input)
# run it through gvpr
program = Path(__file__).parent / "2454.gvpr"
gvprbin = which("gvpr")
with subprocess.Popen(
[gvprbin, "-cf", program], stdin=subprocess.PIPE, text=True
) as p:
p.communicate(output)
assert p.returncode == 0, "gvpr failed"
@pytest.mark.skipif(which("twopi") is None, reason="twopi not available")
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/2457"
)
def test_2457():
"""
node definition order should not affect twopi’s layout
https://gitlab.com/graphviz/graphviz/-/issues/2457
"""
# locate our associated test cases in this directory
case1 = Path(__file__).parent / "2457_1.dot"
assert case1.exists(), "unexpectedly missing test case"
case2 = Path(__file__).parent / "2457_2.dot"
assert case2.exists(), "unexpectedly missing test case"
# tweak the environment to force deterministic PDF generation
env = os.environ.copy()
env["SOURCE_DATE_EPOCH"] = "0"
# generate PDFs
twopi = which("twopi")
pdf1 = run_raw([twopi, "-Tpdf", case1], env=env)
pdf2 = run_raw([twopi, "-Tpdf", case2], env=env)
assert pdf1 == pdf2, "node definition order affected PDF generation"
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/2458"
)
def test_2458():
"""
`pack=true` should not result in edge labels disappearing
https://gitlab.com/graphviz/graphviz/-/issues/2458
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2458.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
output = dot("svg", input)
# the edge label should be present
assert re.search(r"\bconnected\b", output), "missing edge label"
def test_2460():
"""
labels involving back slashes should come out correctly in JSON
https://gitlab.com/graphviz/graphviz/-/issues/2460
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2460.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
output = dot("json", input)
data = json.loads(output)
assert (
data["objects"][0]["_ldraw_"][2]["text"]
== r"double back slash in label \\. End should be the last word - End"
), "back slashes in labels handled incorrectly"
@pytest.mark.xfail(
strict=platform.system() != "Windows",
reason="https://gitlab.com/graphviz/graphviz/-/issues/2470",
)
def test_2470():
"""
another “trouble in init_rank variant”
https://gitlab.com/graphviz/graphviz/-/issues/2470
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2470.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("ps", input)
@pytest.mark.xfail(
reason="https://gitlab.com/graphviz/graphviz/-/issues/2471",
strict=True,
)
def test_2471():
"""
another “trouble in init_rank variant”
https://gitlab.com/graphviz/graphviz/-/issues/2471
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2471.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("png", input)
@pytest.mark.xfail(
is_rocky_8(),
reason="Cairo is <v1.16 or malfunctions",
strict=True,
)
def test_2473_1():
"""
`SOURCE_DATE_EPOCH` should be usable to suppress timestamps
https://gitlab.com/graphviz/graphviz/-/issues/2473
"""
# a trivial graph
graph = "graph { a -- b }".encode("utf-8")
# set an epoch
env = os.environ.copy()
env["SOURCE_DATE_EPOCH"] = "60"
# generate a PDF
first_run = run_raw(["dot", "-Tpdf"], input=graph, env=env)
# wait long enough for the current time to change
time.sleep(2)
# generate another PDF
second_run = run_raw(["dot", "-Tpdf"], input=graph, env=env)
assert (
first_run == second_run
), "PDF output is dependent on current time even when $SOURCE_DATE_EPOCH is set"
def test_2473_2():
"""
When handling `SOURCE_DATE_EPOCH`, from
https://reproducible-builds.org/specs/source-date-epoch/:
If the value is malformed, the build process SHOULD exit with a non-zero
error code.
https://gitlab.com/graphviz/graphviz/-/issues/2473
"""
# set up an invalid epoch
env = os.environ.copy()
env["SOURCE_DATE_EPOCH"] = "foo"
# confirm Graphviz rejects this
with pytest.raises(subprocess.CalledProcessError):
run(
["dot", "-Tpdf", "-o", os.devnull],
input="graph { a -- b }",
env=env,
encoding="utf-8",
)
def test_2476():
"""
tweaking `mclimit` should not lead to a “trouble in init_rank” failure
https://gitlab.com/graphviz/graphviz/-/issues/2476
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2476.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
run_raw(["dot", "-Tsvg", "-Gmclimit=0.5", "-o", os.devnull, input])
def test_2490():
"""
the `crow` arrow shall be correctly placed and orientated when ports are used
https://gitlab.com/graphviz/graphviz/-/issues/2490
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2490.dot"
assert input.exists(), "unexpectedly missing test case"
# translate this to SVG
svg = dot("svg", input)
# load this as XML
root = ET.fromstring(svg)
# The output is expected to contain three polygons, of which the two last
# are the `crow` arrow shapes of the edge head and tail. Except for the
# crow's "toes", the corners of these are expected to have the same x
# position as the nodes' centers. The "toes" are expected to have x
# positions half the width more or less than the nodes' centers.
ellipses = root.findall(".//{http://www.w3.org/2000/svg}ellipse")
assert len(ellipses) == 2, "wrong number of ellipses in output"
cx = float(ellipses[0].get("cx"))
assert float(ellipses[1].get("cx")) == cx
polygons = root.findall(".//{http://www.w3.org/2000/svg}polygon")
assert len(polygons) == 3, "wrong number of polygons in output"
for polygon_index, polygon in enumerate(polygons):
points_attr = polygon.get("points")
point_pair_strs = points_attr.split(" ")
points = [point_pair_str.split(",") for point_pair_str in point_pair_strs]
if polygon_index == 0:
assert len(points) == 5
# ignore the graph polygon
continue
assert len(points) == 9
for point_index, point in enumerate(points):
x = float(point[0])
crow_width = 9
expected_crow_tip_and_shaft_x = cx
expected_crow_toe_left_x = cx - crow_width / 2
expected_crow_toe_right_x = cx + crow_width / 2
expected_first_crow_toe_x = (
expected_crow_toe_left_x
if polygon_index == 1
else expected_crow_toe_right_x
)
expected_second_crow_toe_x = (
expected_crow_toe_right_x
if polygon_index == 1
else expected_crow_toe_left_x
)
if point_index in [0, 2, 3, 4, 5, 6, 8]:
assert x == expected_crow_tip_and_shaft_x
elif point_index == 1:
assert x == expected_first_crow_toe_x
elif point_index == 7:
assert x == expected_second_crow_toe_x
@pytest.mark.skipif(which("gv2gml") is None, reason="gv2gml not available")
def test_2493():
"""
`gv2gml` should support the yWorks.com variant of GML
https://gitlab.com/graphviz/graphviz/-/issues/2493
"""
# a trivial graph with a colored label
src = 'graph { a -- b[label="foo", fontcolor="red"]; }'
# pass this through `gv2gml`
gv2gml = which("gv2gml")
gml = run([gv2gml, "-y"], input=src)
assert (
re.search(r"\bfontcolor\b", gml) is None
), "gv2gml emitted 'fontcolor' when in yWorks.com mode"
assert (
re.search(r"\bcolor\b", gml) is not None
), "gv2gml did not emit LabelGraphics 'color' attribute"
def test_2497():
"""
graph rendering should be deterministic
https://gitlab.com/graphviz/graphviz/-/issues/2497
"""
# get our baseline reference
input = Path(__file__).parent / "2497.dot"
assert input.exists(), "unexpectedly missing test case"
ref = dot("svg", input)
# now repeat this, expecting it not to change
for _ in range(20):
out = dot("svg", input)
assert ref == out, "repeated rendering changed output"
def test_2502():
"""
unicode labels should be usable
https://gitlab.com/graphviz/graphviz/-/issues/2502
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2502.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("dot", input)
@pytest.mark.xfail(
strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/2516"
)
def test_2516():
"""
errors in HTML labels should result in a message with correct line number
https://gitlab.com/graphviz/graphviz/-/issues/2516
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2516.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
proc = subprocess.run(
["dot", "-Tsvg", "-o", os.devnull, input],
stderr=subprocess.PIPE,
check=False,
text=True,
)
assert proc.returncode != 0, "malformed HTML label was accepted"
assert (
re.search(r"\bline 1\b", proc.stderr) is None
), "incorrect line number in error message"
assert (
re.search(r"\bline 2\b", proc.stderr) is not None
), "correct line number missing from error message"
@pytest.mark.parametrize(
"testcase",
(
"705.dot",
pytest.param(
"2521.dot",
marks=pytest.mark.xfail(
strict=False,
reason="https://gitlab.com/graphviz/graphviz/-/issues/2521",
),
),
"2521_1.dot",
),
)
def test_2521(testcase: str):
"""
`newrank=false` should reset to the default behavior
https://gitlab.com/graphviz/graphviz/-/issues/2521
"""
# locate our associated test case in this directory
input = Path(__file__).parent / testcase
assert input.exists(), "unexpectedly missing test case"
def sh(args: list[Union[Path, str]]) -> bytes:
"""run a command, as if via the shell"""
# dump the command being run for the user to observe if the test fails
print(f"+ {shlex.join(str(x) for x in args)}")
proc = subprocess.run(args, stdout=subprocess.PIPE, check=True)
return proc.stdout
# process this with and without `newrank=true`
off = sh(["dot", "-Tpng", input])
on = sh(["dot", "-Gnewrank=true", "-Tpng", input])
assert off != on, "-Gnewrank=true had no effect"
# we should be able to reset `newrank` with an explicit setting
force_off = sh(["dot", "-Gnewrank=false", "-Tpng", input])
assert force_off == off, "-Gnewrank=false did not reset the default"
@pytest.mark.xfail(
is_macos(), strict=True, reason="https://gitlab.com/graphviz/graphviz/-/issues/2538"
)
def test_2538():
"""
`chanSearch` assertion on `cp` should not fail
https://gitlab.com/graphviz/graphviz/-/issues/2538
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2538.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("dot", input)
@pytest.mark.skipif(which("sfdp") is None, reason="sfdp not available")
def test_2556():
"""
sfdp should not fail a GTS assertion
https://gitlab.com/graphviz/graphviz/-/issues/2556
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2556.dot"
assert input.exists(), "unexpectedly missing test case"
# run this through sfdp
sfdp = which("sfdp")
p = subprocess.run(
[sfdp, "-Tpng", "-o", os.devnull, input],
stderr=subprocess.PIPE,
check=False,
text=True,
)
# if sfdp was built without libgts, it will not handle anything non-trivial
no_gts_error = "remove_overlap: Graphviz not built with triangulation library"
if no_gts_error in p.stderr:
assert p.returncode != 0, "sfdp returned success after an error message"
return
p.check_returncode()
def test_2559():
"""
`concentrate=true` should actually concentrate edges
https://gitlab.com/graphviz/graphviz/-/issues/2559
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2559.dot"
assert input.exists(), "unexpectedly missing test case"
# convert this to JSON
layout = dot("json", input)
parsed = json.loads(layout)
# the last edge, d→b, should be drawn as a curve rather than a straight edge
assert not parsed["edges"][-1]["pos"].startswith(
"e"
), "concentrated edge drawn as a regular straight edge"
@pytest.mark.skipif(which("fdp") is None, reason="fdp not available")
def test_2563():
"""
`overlap` parameters should generate different results
https://gitlab.com/graphviz/graphviz/-/issues/2563
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2563.dot"
assert input.exists(), "unexpectedly missing test case"
# try various `overlap=…` values
results: set[str] = set()
for overlap in ("scale", "scalexy"):
# run this through fdp
fdp = which("fdp")
p = subprocess.run(
[fdp, f"-Goverlap={overlap}", input],
capture_output=True,
check=False,
text=True,
)
# if fdp was built without libgts, it will not handle anything non-trivial
no_gts_error = "remove_overlap: Graphviz not built with triangulation library"
if no_gts_error in p.stderr:
assert p.returncode != 0, "fdp returned success after an error message"
return
p.check_returncode()
# remove the overlap parameter itself, that would otherwise cause each
# output to be unique
output = re.sub(r"\boverlap\s*=\s*scale(xy)?\b", "", p.stdout)
assert (
output not in results
), "altering `overlap` attribute did not affect output"
results.add(output)
def test_2564():
"""
`overlap="scale"` should not result in all nodes overlapping
https://gitlab.com/graphviz/graphviz/-/issues/2564
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2564.dot"
assert input.exists(), "unexpectedly missing test case"
# convert this to JSON
layout = run(["dot", "-Kneato", "-Tjson", input])
parsed = json.loads(layout)
# nodes should not be on top of one another
starts = []
for node in parsed["objects"]:
start = re.match(r"(?P<start>\d+(\.\d+)?,\d+(\.\d+)?)\b", node["pos"]).group(
"start"
)
assert start not in starts, "nodes overlap"
starts += [start]
@pytest.mark.skipif(shutil.which("tclsh") is None, reason="tclsh not available")
@pytest.mark.skipif(
platform.system() == "Windows",
reason="pexpect.spawn is not available on Windows "
"(https://pexpect.readthedocs.io/en/stable/overview.html#pexpect-on-windows)",
)
def test_2568():
"""
tags used in TCL output should be usable for later lookup
https://gitlab.com/graphviz/graphviz/-/issues/2568
"""
# locate the TCL input for this test
prelude = Path(__file__).parent / "2568.tcl"
assert prelude.exists(), "unexpectedly missing test collateral"
# if this appears to be an ASan-enabled CI job, teach `tclsh` to load ASan’s
# supporting library because it is otherwise unaware that Tcldot depends on this
# being loaded first
env = os.environ.copy()
dot_exe = which("dot")
if is_asan_instrumented(dot_exe):
cc = os.environ.get("CC", "gcc")
libasan = run([cc, "-print-file-name=libasan.so"]).strip()
print(f"setting LD_PRELOAD={libasan}")
env["LD_PRELOAD"] = libasan
# startup TCL and load our graph setup code
proc = pexpect.spawn("tclsh", timeout=1, env=env)
proc.expect("% ")
proc.sendline(f'source "{shlex.quote(str(prelude))}"')
# look for tags to query
while True:
index = proc.expect(
[
"invalid command name",
re.compile(rb"-tags {\d(?P<tag>(edge|node)0x[\da-fA-F]+)}"),
pexpect.TIMEOUT,
]
)
# stdout and stderr are multiplexed onto the same stream by `pexpect`, so if one
# of the commands we previously entered was not recognized, we will see an error
# at the end of the output stream
assert index != 0, "at least one tag was not recognized"
# if we got no output within 1s, assume we are done
if index == 2:
break
tag = proc.match.group("tag").decode("utf-8")
# try to look up its corresponding entities
if tag.startswith("edge"):
cmd = "listnodes"
else:
cmd = "listedges"
proc.sendline(f"{tag} {cmd}")
@pytest.mark.skipif(which("sfdp") is None, reason="sfdp not available")
def test_2572():
"""
sfdp should be able to find non-overlapping layouts
https://gitlab.com/graphviz/graphviz/-/issues/2572
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2572.dot"
assert input.exists(), "unexpectedly missing test case"
# run this through SFDP and convert this to JSON
sfdp = which("sfdp")
layout = run([sfdp, "-Kneato", "-Tjson", input])
parsed = json.loads(layout)
@dataclasses.dataclass
class Box:
"""
a geometric rectangle, defined by two of its corners
"""
llx: float # lower left X coordinate
lly: float # lower left Y coordinate
urx: float # upper right X coordinate
ury: float # upper right Y coordinate
def overlaps(self, other: "Box") -> bool:
"""
do we intersect the given box?
"""
if self.llx > other.urx:
return False
if self.lly > other.ury:
return False
if self.urx < other.llx:
return False
if self.ury < other.lly:
return False
return True
nodes: list[Box] = []
for obj in parsed["objects"]:
# extract the ellipse drawn for this node
ellipses = [e for e in obj["_draw_"] if e["op"] == "e"]
assert len(ellipses) == 1, "could not find ellipse for node"
center_x, center_y, width, height = ellipses[0]["rect"]
assert center_x >= width, "ellipse extends into negative X space"
assert center_y >= height, "ellipse extends into negative Y space"
node = Box(
center_x - width, center_y - height, center_x + width, center_y + height
)
assert not any(n.overlaps(node) for n in nodes), "nodes overlap"
nodes.append(node)
@pytest.mark.skipif(which("gvpr") is None, reason="GVPR not available")
def test_2577():
"""
accessing an uninitialized string should not corrupt GVPR’s state
https://gitlab.com/graphviz/graphviz/-/issues/2577
"""
# find our collocated test case
program = Path(__file__).parent / "2577.gvpr"
assert program.exists(), "unexpectedly missing test case"
# run it through GVPR
output = gvpr(program)
# it should have printed an empty string for the uninitialized attribute
assert (
"Before...\n<>\nAfter." in output
), "incorrect handling of uninitialized attribute in GVPR"
@pytest.mark.skipif(which("gvpr") is None, reason="GVPR not available")
def test_2577_1():
"""
a variant of `test_2577` that does not involve attribute access
https://gitlab.com/graphviz/graphviz/-/issues/2577
"""
# run GVPR on a simple program
gvprbin = which("gvpr")
output = run(
[gvprbin, 'BEGIN { printf("hello%s world\\n", ""); }'],
stdin=subprocess.DEVNULL,
)
# it should have printed the expected text
assert output == "hello world\n", "gvpr cannot handle empty strings to printf"
@pytest.mark.parametrize(
"program,a_arg,expected",
(
("BEGIN { print(#ARGV); }", "abc", "1"),
("BEGIN { print(0 in ARGV); }", "abc", "1"),
(
'BEGIN {string argv[int]; argv[0] = "abc"; print(#argv); print(0 in argv);}',
None,
"1\n1",
),
),
)
@pytest.mark.skipif(which("gvpr") is None, reason="GVPR not available")
def test_2582(program: str, a_arg: Optional[str], expected: str):
"""
gvpr should treat `ARGV` as an array
https://gitlab.com/graphviz/graphviz/-/issues/2582
Args:
program: Program text to run in gvpr
a_arg: An optional parameter to pass via `-a …` to gvpr
expected: Expected output
"""
gvprbin = which("gvpr")
args = [gvprbin]
if a_arg is not None:
args += ["-a", a_arg]
args += [program]
actual = run(args)
assert actual.strip() == expected, "unexpected GVPR program output"
@pytest.mark.parametrize(
"testcase",
(
"2585",
"2585_1",
"2585_2",
"2585_3",
"2585_4",
"2585_5",
"2585_6",
"2585_7",
),
)
@pytest.mark.skipif(which("gvpr") is None, reason="GVPR not available")
def test_2585(testcase: str):
"""
GVPR should reject various invalid uses of `void` types
https://gitlab.com/graphviz/graphviz/-/issues/2585
"""
# locate our associated test case in this directory
input = Path(__file__).parent / f"{testcase}.gvpr"
assert input.exists(), "unexpectedly missing test case"
# run the program
gvprbin = which("gvpr")
ret = subprocess.call(
[gvprbin, "-o", os.devnull, "-f", input], stdin=subprocess.DEVNULL
)
assert ret == 1, "GVPR did not reject invalid use of `void`"
@pytest.mark.skipif(which("gml2gv") is None, reason="gml2gv not available")
def test_2586():
"""
labels should be preserved in GML→GV translation
https://gitlab.com/graphviz/graphviz/-/issues/2586
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2586.gml"
assert input.exists(), "unexpectedly missing test case"
# translate it
gml2gv = which("gml2gv")
gv = run([gml2gv, input])
assert (
re.search(r'\blabel\s*=\s*"?0"?\b', gv) is not None
), "labels not preserved in GML→GV translation"
@pytest.mark.skipif(which("gvpr") is None, reason="gvpr not available")
def test_2587():
"""
gvpr should have a usable `unsigned` type
https://gitlab.com/graphviz/graphviz/-/issues/2587
"""
gvpr_bin = which("gvpr")
output = run(
[gvpr_bin, "BEGIN { unsigned x = 281; print(x); }"],
stdin=subprocess.DEVNULL,
)
assert output == "281\n", "gvpr did not correctly interpret an `unsigned`"
@pytest.mark.skipif(which("gvpr") is None, reason="gvpr not available")
def test_2587_1():
"""
gvpr should have a usable `unsigned` type
https://gitlab.com/graphviz/graphviz/-/issues/2587
"""
gvpr_bin = which("gvpr")
output = run(
[gvpr_bin, 'BEGIN { unsigned x; sscanf("139", "%u", &x); print(x); }'],
stdin=subprocess.DEVNULL,
)
assert output == "139\n", "gvpr did not correctly interpret an `unsigned`"
@pytest.mark.skipif(which("gvgen") is None, reason="gvgen not available")
def test_2588():
"""
`gvgen` should not crash when producing random graphs
https://gitlab.com/graphviz/graphviz/-/issues/2588
"""
gvgen = which("gvgen")
# this execution depends on random numbers, so we need to run many times to
# have a chance of provoking the bug
for _ in range(200):
run_raw([gvgen, "-R", "20"], stdout=subprocess.DEVNULL)
@pytest.mark.skipif(which("edgepaint") is None, reason="edgepaint not available")
@pytest.mark.skipif(which("gvgen") is None, reason="gvgen not available")
def test_2591():
"""
edgepaint color schemes should do something
https://gitlab.com/graphviz/graphviz/-/issues/2591
"""
# make an input graph
gvgen = which("gvgen")
graph = run([gvgen, "-k", "5"])
# run it through neato
laidout = run(["dot", "-Kneato", "-Goverlap=false"], input=graph)
# try two different edgepaint invocations
edgepaint = which("edgepaint")
gray = run([edgepaint, "--angle=89.999", "--color_scheme=gray"], input=laidout)
rgb = run(
[edgepaint, "--angle=89.999", "--color_scheme=#00ff00,#0000ff"],
input=laidout,
)
# process these into an image
gray_svg = run(["dot", "-Kneato", "-n2", "-Tsvg"], input=gray)
rgb_svg = run(["dot", "-Kneato", "-n2", "-Tsvg"], input=rgb)
assert gray_svg != rgb_svg, "edgepaint --color_scheme had no effect"
@pytest.mark.skipif(which("ccomps") is None, reason="ccomps not available")
def test_2593():
"""
ccomps should be able to handle this graph in reasonable time
https://gitlab.com/graphviz/graphviz/-/issues/2593
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2593.dot"
assert input.exists(), "unexpectedly missing test case"
# this typically takes 30-45s to run, so give a wide margin of error and require
# that ccomps finishes within that
ccomps = which("ccomps")
proc = subprocess.run(
[ccomps, "-o", os.devnull, input], timeout=60 * 5, check=False
)
assert proc.returncode == 1, "ccomps did not detect graphs have multiple components"
@pytest.mark.skipif(shutil.which("tclsh") is None, reason="tclsh not available")
@pytest.mark.skipif(
platform.system() == "Windows",
reason="pexpect.spawn is not available on Windows "
"(https://pexpect.readthedocs.io/en/stable/overview.html#pexpect-on-windows)",
)
@pytest.mark.xfail(
is_cmake() and is_macos(),
reason="FIXME: 'vgpane' command is unrecognized for unknown reasons",
strict=True,
)
@pytest.mark.xfail(
is_autotools() and is_macos(),
reason="Autotools on macOS does not detect TCL",
strict=True,
)
def test_2596():
"""
running Tclpathplan `triangulate` with a malformed callback script should not read
out-of-bounds
https://gitlab.com/graphviz/graphviz/-/issues/2596
"""
# if this appears to be an ASan-enabled CI job, teach `tclsh` to load ASan’s
# supporting library because it is otherwise unaware that Tcldot depends on this
# being loaded first
env = os.environ.copy()
dot_exe = which("dot")
if is_asan_instrumented(dot_exe):
cc = os.environ.get("CC", "gcc")
libasan = run([cc, "-print-file-name=libasan.so"]).strip()
print(f"setting LD_PRELOAD={libasan}")
env["LD_PRELOAD"] = libasan
# startup TCL and load the pathplan module
proc = pexpect.spawn("tclsh", timeout=1, env=env)
proc.expect("% ")
proc.sendline("package require Tclpathplan")
proc.expect("% ")
# Create a pane. We assume the first created pane will be index 0, though
# this is not technically required.
proc.sendline("vgpane")
proc.expect("vgpane0")
proc.expect("% ")
# bind the triangulation callback to something ending in a trailing '%'
proc.sendline("vgpane0 bind triangle %")
proc.expect("% ")
# add a triangular polygon
proc.sendline("vgpane0 insert 1 1 2 2 1 2")
proc.expect("1")
proc.expect("% ")
# attempt triangulation on this polygon
proc.sendline("vgpane0 triangulate 1")
proc.expect("% ")
# delete the pane to clean up, to exit ASan-clean
proc.sendline("vgpane0 delete")
proc.expect("% ")
@pytest.mark.skipif(not is_cmake(), reason="only relevant in CMake builds")
@pytest.mark.skipif(shutil.which("cmake") is None, reason="cmake not available")
@pytest.mark.skipif(
re.search(r"\bstatic\b", os.environ.get("CI_JOB_NAME", "")) is not None,
reason="CMake support files are not installed in static builds",
)
def test_2598(tmp_path: Path):
"""
Graphviz, as installed by the CMake build system, should be usable with standard
CMake idioms
https://gitlab.com/graphviz/graphviz/-/issues/2598
"""
# configure a build directory for our sample applications
src = Path(__file__).parent / "2598"
args = ["cmake", "--debug-find", "-B", tmp_path, "-S", src]
if os.environ.get("CI_JOB_NAME", "").startswith("windows-cmake-Win32"):
args += ["-A", "Win32"]
run_raw(args)
# run compilation
run_raw(["cmake", "--build", tmp_path])
@pytest.mark.skipif(not is_cmake(), reason="only relevant in CMake builds")
@pytest.mark.skipif(shutil.which("cmake") is None, reason="cmake not available")
@pytest.mark.skipif(
re.search(r"\bstatic\b", os.environ.get("CI_JOB_NAME", "")) is not None,
reason="CMake support files are not installed in static builds",
)
def test_2598_1(tmp_path: Path):
"""
A variant of test_2598, that does not directly use cdt
https://gitlab.com/graphviz/graphviz/-/issues/2598
"""
# configure a build directory for our sample applications
src = Path(__file__).parent / "2598_1"
args = ["cmake", "--debug-find", "-B", tmp_path, "-S", src]
if os.environ.get("CI_JOB_NAME", "").startswith("windows-cmake-Win32"):
args += ["-A", "Win32"]
run_raw(args)
# run compilation
run_raw(["cmake", "--build", tmp_path])
@pytest.mark.skipif(which("gvgen") is None, reason="gvgen not available")
@pytest.mark.skipif(which("mingle") is None, reason="mingle not available")
def test_2599():
"""
mingle should not segfault when processing simple graphs
https://gitlab.com/graphviz/graphviz/-/issues/2599
"""
# generate a graph
gvgen = which("gvgen")
graph = run([gvgen, "-d", "-k", "5"])
# process it into canonical form
processed = run(["dot"], input=graph)
# pass it through mingle
mingle = which("mingle")
proc = subprocess.run(
[mingle, "-v", "999"], check=False, text=True, input=processed
)
assert proc.returncode in (0, 1), "mingle crashed"
@pytest.mark.skipif(which("acyclic") is None, reason="acyclic not available")
def test_2600():
"""
acyclic should produce output
https://gitlab.com/graphviz/graphviz/-/issues/2600
"""
# run acyclic on a simple cyclic graph
acyclic = which("acyclic")
ret = subprocess.run(
[acyclic],
input="digraph { A -> B -> C -> D -> E; E -> A }",
stdout=subprocess.PIPE,
check=False,
text=True,
)
assert ret.returncode == 1, "acyclic did not detect a cyclic graph"
assert ret.stdout.strip() != "", "acyclic produced no output"
@pytest.mark.skipif(which("dot_builtins") is None, reason="dot_builtins not available")
def test_2604():
"""
dot_builtins should not repeat formats in guidance
https://gitlab.com/graphviz/graphviz/-/issues/2604
"""
# a simple graph
input = "digraph { a -> b; }"
# run dot_builtins with an incorrect format
dot_builtins = which("dot_builtins")
proc = subprocess.run(
[dot_builtins, "-o", os.devnull, "-Tpng:"],
stderr=subprocess.PIPE,
input=input,
text=True,
check=False,
)
assert proc.returncode != 0, "dot_builtins accepted malformed format 'png:'"
assert (
len(re.findall(r"\bpng:cairo:cairo\b", proc.stderr)) <= 1
), "duplicate formats listed in guidance"
@pytest.mark.skipif(which("neato") is None, reason="neato not available")
def test_2609(tmp_path: Path):
"""
GIFs should not be blank
https://gitlab.com/graphviz/graphviz/-/issues/2609
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2609.dot"
assert input.exists(), "unexpectedly missing test case"
# run this through Neato and convert to GIF
neato = which("neato")
gif = tmp_path / "2609.gif"
run_raw([neato, "-Tgif", input, "-o", gif])
# load the image and scan its pixels
img = Image.open(gif)
reference = None
for x in range(img.width):
for y in range(img.height):
pixel = img.getpixel((x, y))
if reference is None:
reference = pixel
elif reference != pixel:
# found a different pixel
return
pytest.fail("generated GIF was a solid color")
def test_2613():
"""
Graphviz should not fail an assertion when processing this graph
https://gitlab.com/graphviz/graphviz/-/issues/2613
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2613.dot"
assert input.exists(), "unexpectedly missing test case"
# generate it as a PDF
dot("pdf", input)
def test_2614():
"""
quotes in strings should be correctly escaped
https://gitlab.com/graphviz/graphviz/-/issues/2614
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2614.dot"
assert input.exists(), "unexpectedly missing test case"
# generate the canonical form of this
canonical = dot("canon", input)
# it should be re-parseable
dot("svg", source=canonical)
# quotes should have been escaped
assert canonical.count('\\"') == 2, "quotes in string were not properly escaped"
def test_2615():
"""
cluster→cluster edges should not be duplicated
https://gitlab.com/graphviz/graphviz/-/issues/2615
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2615.dot"
assert input.exists(), "unexpectedly missing test case"
# lay this out
layout = dot("dot", input)
# find an inter-cluster edge
m = re.search(r'\bD\s*->\s*F\s*\[\s*pos\s*=\s*"(?P<position>[^"]*)"', layout)
assert m is not None, "could not locate D->F edge"
edge_count = len(re.findall(r"\be\b", m.group("position")))
assert edge_count == 1, "incorrect number of inter-cluster edges"
@pytest.mark.xfail(
platform.system() == "Windows" and not is_mingw() and not is_ndebug_defined(),
strict=True,
reason="https://gitlab.com/graphviz/graphviz/-/issues/2619",
)
def test_2619():
"""
loading a JPEG with initial EXIF stream should be possible
https://gitlab.com/graphviz/graphviz/-/issues/2619
"""
# we need to run in our own directory so relative path references work
cwd = Path(__file__).parent
# our test case should be translatable to PDF
run_raw(["dot", "-Tpdf", "-o", os.devnull, "2619.dot"], cwd=cwd)
@pytest.mark.xfail(
platform.system() == "Windows" and not is_mingw() and not is_ndebug_defined(),
strict=True,
reason="https://gitlab.com/graphviz/graphviz/-/issues/2619",
)
@pytest.mark.parametrize("images", ("2619_1", "2619_2"))
@pytest.mark.parametrize("output", ("pdf", "png"))
@pytest.mark.parametrize("source", ("2619_1.dot", "2619_2.dot"))
def test_2619_1(images: str, output: str, source: str, tmp_path: Path):
"""
output files for this graph should be non-empty
https://gitlab.com/graphviz/graphviz/-/issues/2619
"""
# locate our associated test case in this directory
input = Path(__file__).parent / source
assert input.exists(), "unexpectedly missing test case"
# copy it to a temporary path, replacing image references for our variant
content = input.read_bytes()
specialized = re.sub(
rb"\b2619_(\d)1\.jpg\b", images.encode("utf-8") + rb"_\1.jpg", content
)
destination = tmp_path / "2619.dot"
destination.write_bytes(specialized)
# copy images to the expected directory structure
media = tmp_path / "data/media/media/schoenfeld-liberman.ged"
media.mkdir(parents=True)
for i in (1, 2, 3):
src = Path(__file__).parent / f"{images}_{i}.jpg"
shutil.copy(src, media / f"2619_{i}.jpg")
def sh(args: list[Union[Path, str]], stdin: Optional[bytes] = None) -> bytes:
"""run a command, as if via the shell"""
nonlocal tmp_path
# dump the command being run for the user to observe if the test fails
print(
f"+ cd {shlex.quote(str(tmp_path))} && {shlex.join(str(x) for x in args)}"
)
proc = subprocess.run(
args, input=stdin, stdout=subprocess.PIPE, cwd=tmp_path, check=True
)
return proc.stdout
# render this
dot_result = sh(["dot", f"-T{output}", destination])
assert dot_result.strip() != b"", "an empty file was rendered"
# render it with exact position information
positioned = sh(["dot", "-Tdot", destination])
# use this to render with neato
neato = which("neato")
neato_result = sh([neato, "-n2", f"-T{output}"], stdin=positioned)
assert neato_result.strip() != b"", "an empty file was rendered"
@pytest.mark.xfail(
platform.system() == "Windows" and not is_mingw() and not is_ndebug_defined(),
strict=True,
reason="https://gitlab.com/graphviz/graphviz/-/issues/2619",
)
def test_2619_3():
"""
loading a JPEG image shall not cause a crash in the GD plugin when the output format is PDF
https://gitlab.com/graphviz/graphviz/-/issues/2619
"""
# we need to run in our own directory so relative path references work
cwd = Path(__file__).parent
src = 'digraph {a [image="2619_1_2.jpg"]}'.encode("utf-8")
# our test case shall not cause a crash
run_raw(["dot", "-Tpdf", "-o", os.devnull], cwd=cwd, input=src)
def test_2619_4():
"""
processing a node with the 'image' attribute set to a JPEG file shall not yield warnings
https://gitlab.com/graphviz/graphviz/-/issues/2619
"""
# we need to run in our own directory so relative path references work
cwd = Path(__file__).parent
src = 'digraph {a [image="2619.jpg"]}'
output = run(
["dot", "-Tsvg", "-o", os.devnull],
cwd=cwd,
input=src,
stderr=subprocess.STDOUT,
)
assert "Warning:" not in output, f"Warnings issued: {output}"
@pytest.mark.parametrize(
"image",
(
"2619.jpg",
"2619_1_1.jpg",
"2619_1_2.jpg",
"2619_1_3.jpg",
"2619_2_1.jpg",
"2619_2_2.jpg",
"2619_2_3.jpg",
),
)
def test_2619_5(image: str):
"""
a node with the 'image' attribute set to a JPEG file shall render an SVG
containing an 'image' element with the correct width and height
https://gitlab.com/graphviz/graphviz/-/issues/2619
"""
# we need to run in our own directory so relative path references work
cwd = Path(__file__).parent
file = cwd / image
width, height = Image.open(file).size
src = f'digraph {{a [image="{image}"]}}'
svg = run(["dot", "-Tsvg"], cwd=cwd, input=src)
# load it as XML
root = ET.fromstring(svg)
# find the `image` element
image_element = root.findall(".//{http://www.w3.org/2000/svg}image")
assert len(image_element) == 1, "could not find an 'image' element in the SVG"
assert image_element[0].get("width") == f"{width}px"
assert image_element[0].get("height") == f"{height}px"
def test_2620():
"""
arrows in this graph should not be truncated
https://gitlab.com/graphviz/graphviz/-/issues/2620
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2620.dot"
assert input.exists(), "unexpectedly missing test case"
# render to SVG
svg = dot("svg", input)
# parse the SVG
root = ET.fromstring(svg)
# most of the differences between the “good” and “bad” rendering are small
# (~1pt diff), so discriminate using one that has been observed to be much larger
edge = root.findall(
".//{http://www.w3.org/2000/svg}g[@id='edge101']/{http://www.w3.org/2000/svg}path"
)
assert len(edge) == 1, "could not find expected edge"
# parse the expected drawing instructions out of this
m = re.match("M(?P<move>.*)C(?P<curve>.*)", edge[0].attrib["d"])
assert m is not None, "drawing command in unexpected format"
# the curve is expected to be composed of two Béziers
points = m.group("curve").split()
assert len(points) == 6, "unexpected number of Bézier curve components"
bezier2 = [pt.split(",") for pt in points[3:]]
assert all(len(pt) == 2 for pt in bezier2), "unexpected Bézier composition"
# compare the end point of the last command against what we expect with a large
# margin of error
expected = -7286.11
assert abs(float(bezier2[2][1]) - expected) < 1000, "incorrect edge construction"
def test_2621():
"""
this graph should not trigger an integer overflow in crossing calculation
https://gitlab.com/graphviz/graphviz/-/issues/2621
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2621.dot"
assert input.exists(), "unexpectedly missing test case"
run_raw(["dot", "-Gmclimit=.05", "-Gphase=2", "-Tsvg", "-o", os.devnull, input])
def test_2636_1():
"""
`viewBox` in an SVG image should not override `width` and `height`
https://gitlab.com/graphviz/graphviz/-/issues/2636
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2636_1.dot"
assert input.exists(), "unexpectedly missing test case"
# we need to run in our current directory in order to reference the co-located
# 2636_1.svg
cwd = Path(__file__).parent
svg = run(["dot", "-Tsvg", input], cwd=cwd)
# parse the generated SVG
root = ET.fromstring(svg)
# find the included image
imgs = root.findall(".//{http://www.w3.org/2000/svg}image")
assert len(imgs) == 1, "could not find included SVG"
img = imgs[0]
assert img.attrib["height"] == "100px", "image height set incorrectly"
assert img.attrib["width"] == "100px", "image width set incorrectly"
def test_2636_2():
"""
`viewBox` parameters in an SVG image should be interpreted correctly
https://gitlab.com/graphviz/graphviz/-/issues/2636
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2636_2.dot"
assert input.exists(), "unexpectedly missing test case"
# we need to run in our current directory in order to reference the co-located
# 2636_2.svg
cwd = Path(__file__).parent
svg = run(["dot", "-Tsvg", input], cwd=cwd)
# parse the generated SVG
root = ET.fromstring(svg)
# find the included image
imgs = root.findall(".//{http://www.w3.org/2000/svg}image")
assert len(imgs) == 1, "could not find included SVG"
img = imgs[0]
assert img.attrib["height"] == "10px", "image height set incorrectly"
assert img.attrib["width"] == "10px", "image width set incorrectly"
@pytest.mark.skipif(which("gvpr") is None, reason="gvpr not available")
def test_2639():
"""
in GVPR, setting an attribute on a subgraph should not set it on the root graph
https://gitlab.com/graphviz/graphviz/-/issues/2639
"""
# locate our associated supporting files in this directory
input = Path(__file__).parent / "2639.dot"
assert input.exists(), "unexpectedly missing test case"
program = Path(__file__).parent / "2639.gvpr"
assert program.exists(), "unexpectedly missing test case"
checker = Path(__file__).parent / "2639_2.gvpr"
assert checker.exists(), "unexpectedly missing test case"
# process the graph with GVPR
gvpr_bin = which("gvpr")
output = run(
[gvpr_bin, "-c", program.read_text(encoding="utf-8")],
input=input.read_text(encoding="utf-8"),
)
# run this resulting graph through the checker to retrieve one of its root graph’s
# defaults
color = run(
[gvpr_bin, "-c", checker.read_text(encoding="utf-8"), "-o", os.devnull],
input=output,
)
assert (
re.search(r"\bred\b", color) is None
), "subgraph default was set on root graph"
@pytest.mark.skipif(which("twopi") is None, reason="twopi not available")
def test_2643():
"""
twopi should not read/write out of bounds when processing this case’s graph
https://gitlab.com/graphviz/graphviz/-/issues/2643
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2643.dot"
assert input.exists(), "unexpectedly missing test case"
# run this through twopi
twopi = which("twopi")
run_raw([twopi, "-o", os.devnull, input])
@pytest.mark.slow # ~13min
def test_2646():
"""
Graphviz should not crash when processing this large graph
https://gitlab.com/graphviz/graphviz/-/issues/2646
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2646.dot"
assert input.exists(), "unexpectedly missing test case"
# run this through Graphviz
dot("pdf", input)
def test_2646_1():
"""
It was observed that `test_2646` could crash early on when minor changes subtly
affected the stack depth of functions in lib/common/ns.c. Because `test_2646` is
expensive, this tries to validate the lack of such crashes with something quicker.
https://gitlab.com/graphviz/graphviz/-/issues/2646
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2646.dot"
assert input.exists(), "unexpectedly missing test case"
# Run this through Graphviz. We expect this long running process to timeout, not
# crash.
try:
run(["dot", "-Tpdf", "-o", os.devnull, input], timeout=10)
except subprocess.TimeoutExpired:
pass
def test_2647():
"""
`-Tsvg_inline` should allow references to external files in its output
https://gitlab.com/graphviz/graphviz/-/issues/2636#note_2326527219
https://gitlab.com/graphviz/graphviz/-/merge_requests/4208
https://gitlab.com/graphviz/graphviz/-/issues/2647
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2636.dot"
assert input.exists(), "unexpectedly missing test case"
# we need to run in our current directory in order to reference the co-located
# 2636.svg
cwd = Path(__file__).parent
svg = run(["dot", "-Tsvg_inline", input], cwd=cwd)
assert (
re.search(r"\b2636\.svg\b", svg) is not None
), "`-Tsvg_inline` output did not reference external image"
@pytest.mark.slow # ~10min
def test_MR_2854():
"""
this graph should be handled in a reasonable amount of time
The graph used by this test was accelerated by commit
4b736d297bb1599451e89c2fde911d966a1db3cf landing in Merge Request !2857. This test
case checks if performance on this workload has regressed since then.
https://gitlab.com/graphviz/graphviz/-/merge_requests/2854
https://gitlab.com/graphviz/graphviz/-/merge_requests/2857
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2854.dot"
assert input.exists(), "unexpectedly missing test case"
# this typically takes ~10m to run, so give a wide margin of error and require that
# Graphviz finishes within that
run_raw(["dot", "-Tsvg", "-o", os.devnull, input], timeout=60 * 20)
@pytest.mark.skipif(which("gvgen") is None, reason="gvgen not available")
@pytest.mark.parametrize("seed", range(1, 2000))
def test_2640(seed: int):
"""
gvgen should not access values out of bounds
https://gitlab.com/graphviz/graphviz/-/issues/2640
"""
# the seed 1967 was observed previously to cause crashes on Windows
gvgen = which("gvgen")
run_raw([gvgen, "-R", "20", f"-u{seed}"], stdout=subprocess.DEVNULL)
@pytest.mark.parametrize(
"testcase", ("agattr", "agsafeset", "agset", "agstrbind", "agxset")
)
@pytest.mark.skipif(
is_static_build(),
reason="dynamic libraries are unavailable to link against in static builds",
)
def test_2641(testcase: str):
"""
`agattr*` and friends should preserve some measure of backwards compatibility
https://gitlab.com/graphviz/graphviz/-/issues/2641
"""
# find co-located test source
c_src = (Path(__file__).parent / f"2641_{testcase}.c").resolve()
assert c_src.exists(), "missing test case"
# run it
run_c(c_src, link=["cgraph"])
def _find_plugin_so(plugin: str) -> Optional[Path]:
"""
find the absolute path to the dynamic library for a given Graphviz plugin
Args:
plugin: Name of the plugin being sought
Return:
An absolute path to the corresponding installed dynamic library or `None` if it
could not be found.
"""
# figure out the path to installed root based on binaries
dot_bin = which("dot")
root = dot_bin.parents[1]
# extract plugin version
current, revision, age = plugin_version()
for subdir in ("lib", "lib64"):
if is_macos():
candidate = root / subdir / f"graphviz/libgvplugin_{plugin}.dylib"
elif is_mingw():
candidate = root / f"bin/libgvplugin_{plugin}-{current - age}.dll"
elif platform.system() == "Windows":
candidate = root / subdir / f"gvplugin_{plugin}.lib"
else:
candidate = root / subdir / f"graphviz/libgvplugin_{plugin}.so"
print(f"checking {candidate}") # log some useful information
if candidate.exists():
return candidate
if platform.system() == "Linux":
# try it with the version info suffix, which is what some RHEL platforms use
suffix = f".{current - age}.{age}.{revision}"
candidate = root / subdir / f"graphviz/libgvplugin_{plugin}.so{suffix}"
print(f"checking {candidate}") # log some useful information
if candidate.exists():
return candidate
# not found
return None
@pytest.mark.skipif(
is_static_build(),
reason="dynamic libraries are unavailable to link against in static builds",
)
def test_2648(tmp_path: Path):
"""
rendering multiple times programmatically should not crash
https://gitlab.com/graphviz/graphviz/-/issues/2648
"""
# find co-located test source
c_src = (Path(__file__).parent / "2648.c").resolve()
assert c_src.exists(), "missing test case"
# From here, we essentially want to `run_c(c_src, …)`. However we cannot easily do
# this because we want to directly link against plugins (instead of `dlopen` them),
# libraries that are not in the linker’s search path. So instead we have to take a
# more manual approach.
# find the plugins we need to link against
core = _find_plugin_so("core")
assert core is not None, "core plugin library not found"
dot_layout = _find_plugin_so("dot_layout")
assert dot_layout is not None, "dot layout plugin library not found"
# compile the test code
exe = tmp_path / "a.exe"
compile_c(c_src, link=["cgraph", "gvc", core, dot_layout], dst=exe)
# teach the runtime linker how to find the plugins
env = os.environ.copy()
ld_library_path = f"{core.parent}:{dot_layout.parent}"
prefix = ""
if is_macos():
if "DYLD_LIBRARY_PATH" in env:
env["DYLD_LIBRARY_PATH"] = f"{ld_library_path}:{env['DYLD_LIBRARY_PATH']}"
else:
env["DYLD_LIBRARY_PATH"] = ld_library_path
prefix = f"env DYLD_LIBRARY_PATH={env['DYLD_LIBRARY_PATH']} "
else:
if "LD_LIBRARY_PATH" in env:
env["LD_LIBRARY_PATH"] = f"{ld_library_path}:{env['LD_LIBRARY_PATH']}"
else:
env["LD_LIBRARY_PATH"] = ld_library_path
prefix = f"env LD_LIBRARY_PATH={env['LD_LIBRARY_PATH']} "
# run the test code
print(f"+ {prefix}{shlex.quote(str(exe))}")
subprocess.run([exe], env=env, check=True)
def test_2669():
"""
`dpi=…` should scale the SVG `viewBox` as well as the overall size
https://gitlab.com/graphviz/graphviz/-/issues/2669
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2669.dot"
assert input.exists(), "unexpectedly missing test case"
def parse(xml: str) -> tuple[int, int, tuple[float, float]]:
"""
parse an SVG
Args:
xml: The text content of an SVG image
Returns:
(width, height, (viewBox width, viewBox height))
"""
root = ET.fromstring(xml)
assert root.attrib["width"].endswith("pt")
width = int(root.attrib["width"][:-2])
assert root.attrib["height"].endswith("pt")
height = int(root.attrib["height"][:-2])
viewbox = re.match(
r"\d+(\.\d+)?\s+\d+(\.\d+)?\s+(?P<width>\d+(\.\d+)?)\s+(?P<height>\d+(\.\d+)?)$",
root.attrib["viewBox"],
)
assert viewbox is not None, "unexpected SVG viewBox format"
vb_width = float(viewbox.group("width"))
vb_height = float(viewbox.group("height"))
return width, height, (vb_width, vb_height)
# run this through Graphviz as normal
svg1 = dot("svg", input)
# confirm the width and height roughly match the `viewBox`
width, height, viewbox = parse(svg1)
assert math.isclose(width, viewbox[0], abs_tol=1.0), "mismatched SVG widths"
assert math.isclose(height, viewbox[1], abs_tol=1.0), "mismatched SVG heights"
# run this with a modified DPI
svg2 = run(["dot", "-Tsvg", "-Gdpi=60", input])
# confirm the width and height roughly match the `viewBox`
width, height, viewbox = parse(svg2)
assert math.isclose(width, viewbox[0], abs_tol=1.0), "mismatched SVG widths"
assert math.isclose(height, viewbox[1], abs_tol=1.0), "mismatched SVG heights"
def test_2682():
"""
processing a graph with `pack` attributes should not cause a crash
https://gitlab.com/graphviz/graphviz/-/issues/2682
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2682.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("dot", input)
def test_2683():
"""
processing a graph with `packmode` attributes should not cause a crash
https://gitlab.com/graphviz/graphviz/-/issues/2683
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2683.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
dot("dot", input)
@pytest.mark.skipif(shutil.which("ps2pdf") is None, reason="ps2pdf not available")
def test_2699():
"""
`showboxes` should generate a valid PS file
https://gitlab.com/graphviz/graphviz/-/issues/2699
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2699.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through Graphviz
ps = dot("ps", input)
# run this through `ps2pdf`, an arbitrary PS-consuming program to validate what
# Graphviz gave us
run_raw(["ps2pdf", "-", os.devnull], input=ps)
def test_2705(tmp_path: Path):
"""
round tripping a graph through a file should not alter its node defaults
https://gitlab.com/graphviz/graphviz/-/issues/2705
"""
# find co-located test source
c_src = (Path(__file__).parent / "2705.c").resolve()
assert c_src.exists(), "missing test case"
from_memory = tmp_path / "memory.dot"
from_file = tmp_path / "file.dot"
# run it
link = ["cgraph"]
if is_static_build():
# in static builds, we also need transitive dependencies
link += ["cdt"]
run_c(c_src, [from_memory, from_file], link=link)
original = from_memory.read_text(encoding="utf-8")
round_tripped = from_file.read_text(encoding="utf-8")
assert (
original == round_tripped
), "round tripping graph through file was not idempotent"
@pytest.mark.skipif(which("gvpr") is None, reason="gvpr is not available")
def test_2707():
"""
gvpr should not perform a double-free while processing this example
https://gitlab.com/graphviz/graphviz/-/issues/2707
"""
# find our test sources
program = (Path(__file__).parent / "2707.gvpr").resolve()
assert program.exists(), "missing test case"
graph = (Path(__file__).parent / "share/unix.gv").resolve()
assert graph.exists(), "missing test case"
gvpr_bin = which("gvpr")
run([gvpr_bin, "-f", program, graph])
def test_2712():
"""
Graphviz on macOS should not crash while processing this graph
https://gitlab.com/graphviz/graphviz/-/issues/2712
"""
source = 'digraph G { abc [URL=" "]; }'
# process this to a JPEG
dot("jpe", source=source)
def test_2716():
"""
version components should be exposed that work at compile-time
https://gitlab.com/graphviz/graphviz/-/issues/2716
"""
# find co-located test source
c_src = (Path(__file__).parent / "2716.c").resolve()
assert c_src.exists(), "missing test case"
# generate a graph and pass it through dot
compile_c(c_src)
@pytest.mark.skipif(which("fdp") is None, reason="fdp is not available")
@pytest.mark.xfail(
strict=not is_ndebug_defined(),
reason="https://gitlab.com/graphviz/graphviz/-/issues/2717",
)
def test_2717():
"""
processing the given graph with fdp should not crash
https://gitlab.com/graphviz/graphviz/-/issues/2717
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2717.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through fdp
fdp = which("fdp")
run([fdp, "-o", os.devnull, input])
@pytest.mark.skipif(which("osage") is None, reason="osage is not available")
def test_2721():
"""
osage should not crash when processing this graph
https://gitlab.com/graphviz/graphviz/-/issues/2721
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2721.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through osage
osage = which("osage")
run([osage, "-Tpng", "-o", os.devnull, input])
def test_2722():
"""
the `CDT_VERSION` macro should be updated whenever its API changes
https://gitlab.com/graphviz/graphviz/-/issues/2722
"""
# The SHA1 digest of ../lib/cdt/cdt.h. This should be updated whenever you update
# ../lib/cdt/cdt.h.
reference = "43c41531381ed1cec4259a08a80dd69b53189100"
# read in the current cdt.h, accounting for Windows vs Unix line ending differences
cdt_h = Path(__file__).absolute().parents[1] / "lib/cdt/cdt.h"
content = cdt_h.read_text(encoding="utf-8")
# hash the content
m = hashlib.sha1()
m.update(content.encode("utf-8"))
# Check they match. The intent here is that this assertion will fail whenever cdt.h
# is updated without taking this test case into account. The failure should prompt
# the developer to update `CDT_VERSION`.
assert (
reference == m.hexdigest()
), "cdt.h has changed; update test_2722 and remember to update `CDT_VERSION`"
@pytest.mark.xfail(
strict=which("dot") is not None and is_asan_instrumented(which("dot")),
reason="https://gitlab.com/graphviz/graphviz/-/issues/2723",
)
def test_2723():
"""
Graphviz should not crash while processing this graph
https://gitlab.com/graphviz/graphviz/-/issues/2723
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2723.dot"
assert input.exists(), "unexpectedly missing test case"
# process this
dot("png", input)
def test_2727():
"""
the label “<>” should be accepted
https://gitlab.com/graphviz/graphviz/-/issues/2727
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2727.dot"
assert input.exists(), "unexpectedly missing test case"
# process this
dot("svg", input)
@pytest.mark.skipif(which("gvpr") is None, reason="gvpr is not available")
def test_2731():
"""
gvpr should produce output for this example
https://gitlab.com/graphviz/graphviz/-/issues/2731
"""
# find our test source
graph = (Path(__file__).parent / "graphs/unix.gv").resolve()
gvpr_bin = which("gvpr")
result = run([gvpr_bin, "-c", 'N{label="\\N";}', graph])
assert result.strip() != "", "gvpr output missing"
@pytest.mark.parametrize(
"fmt",
(
"png",
pytest.param(
"png:cairo:gdk",
marks=pytest.mark.skipif(
is_macos() or platform.system() == "Windows",
reason="GDK plugin not supported",
),
),
"jpg",
"jpg:cairo:gd",
),
)
def test_2732(fmt: str):
"""
back ends should not produce empty files
https://gitlab.com/graphviz/graphviz/-/issues/2732
Args:
fmt: Format to pass to dot’s `-T…`.
"""
# an arbitrary, trivial graph
source = "graph G { a -- b; }"
# confirm this produces non-empty output
output = dot(fmt, source=source)
assert output != b"", "empty output produced for valid graph"
def test_2734():
"""
this graph should not be drawn with sharply angled curves
https://gitlab.com/graphviz/graphviz/-/issues/2734
"""
# locate our associated test case in this directory
input = Path(__file__).parent / "2734.dot"
assert input.exists(), "unexpectedly missing test case"
# process this
svg = dot("svg", input)
# parse the SVG
root = ET.fromstring(svg)
# look at each path
for path in root.findall(".//{http://www.w3.org/2000/svg}path"):
# get the definition and make it slightly easier to parse
d = path.get("d")
points_str = d.replace("C", " ").replace("M", " ")
# parse it into a list of points
points = [
(float(x), float(y))
for x, y in [p.split(",") for p in points_str.split(" ") if p]
]
# examine the angles along the path, looking for an abnormally large one
gradient: Optional[float] = None
last_point: Optional[tuple[float, float]] = None
for p in points:
if last_point is None:
last_point = p
continue
# for simplicity, skip paths with vertical lines because we know the
# problematic one we are scanning for does not have any
if p[0] == last_point[0]:
break
this_gradient = (p[1] - last_point[1]) / (p[0] - last_point[0])
if gradient is not None:
angle = math.atan(
(gradient - this_gradient) / (1 + gradient * this_gradient)
)
assert math.degrees(angle) < 10, "unnecessarily sharp edge generated"
gradient = this_gradient
@pytest.mark.parametrize("package", ("Tcldot", "Tclpathplan"))
@pytest.mark.skipif(shutil.which("tclsh") is None, reason="tclsh not available")
@pytest.mark.xfail(
is_autotools() and is_macos(),
reason="Autotools on macOS does not detect TCL",
strict=True,
)
def test_import_tcl_package(package: str):
"""
The given TCL package should be loadable
"""
# if this appears to be an ASan-enabled CI job, teach `tclsh` to load ASan’s
# supporting library because it is otherwise unaware that Tcldot depends on this
# being loaded first
env = os.environ.copy()
dot_exe = which("dot")
if is_asan_instrumented(dot_exe):
cc = os.environ.get("CC", "gcc")
libasan = run([cc, "-print-file-name=libasan.so"]).strip()
print(f"setting LD_PRELOAD={libasan}")
env["LD_PRELOAD"] = libasan
# ask TCL to import the given package
response = run(
["tclsh"],
stderr=subprocess.STDOUT,
input=f"package require {package};",
env=env,
)
assert "can't find package" not in response, f"{package} cannot be loaded by TCL"
@pytest.mark.skipif(shutil.which("tclsh") is None, reason="tclsh not available")
@pytest.mark.skipif(
platform.system() == "Windows",
reason="pexpect.spawn is not available on Windows "
"(https://pexpect.readthedocs.io/en/stable/overview.html#pexpect-on-windows)",
)
@pytest.mark.xfail(
is_cmake() and is_macos(),
reason="FIXME: 'vgpane' command is unrecognized for unknown reasons",
strict=True,
)
@pytest.mark.xfail(
is_autotools() and is_macos(),
reason="Autotools on macOS does not detect TCL",
strict=True,
)
def test_triangulation_overflow():
"""
running Tclpathplan `triangulate` with a malformed polygon should be rejected
"""
# if this appears to be an ASan-enabled CI job, teach `tclsh` to load ASan’s
# supporting library because it is otherwise unaware that Tcldot depends on this
# being loaded first
env = os.environ.copy()
dot_exe = which("dot")
if is_asan_instrumented(dot_exe):
cc = os.environ.get("CC", "gcc")
libasan = run([cc, "-print-file-name=libasan.so"]).strip()
print(f"setting LD_PRELOAD={libasan}")
env["LD_PRELOAD"] = libasan
# startup TCL and load the pathplan module
proc = pexpect.spawn("tclsh", timeout=1, env=env)
proc.expect("% ")
proc.sendline("package require Tclpathplan")
proc.expect("% ")
# Create a pane. We assume the first created pane will be index 0, though
# this is not technically required.
proc.sendline("vgpane")
proc.expect("vgpane0")
proc.expect("% ")
# add a “polygon” with only a single point
proc.sendline("vgpane0 insert 4 5")
proc.expect("1")
proc.expect("% ")
# attempt triangulation on this polygon
proc.sendline("vgpane0 triangulate 1")
proc.expect("cannot be triangulated")
proc.expect("% ")
# delete the pane to clean up, to exit ASan-clean
proc.sendline("vgpane0 delete")
proc.expect("% ")
@pytest.mark.skipif(shutil.which("tclsh") is None, reason="tclsh not available")
@pytest.mark.skipif(
platform.system() == "Windows",
reason="pexpect.spawn is not available on Windows "
"(https://pexpect.readthedocs.io/en/stable/overview.html#pexpect-on-windows)",
)
@pytest.mark.xfail(
is_cmake() and is_macos(),
reason="FIXME: 'vgpane' command is unrecognized for unknown reasons",
strict=True,
)
@pytest.mark.xfail(
is_autotools() and is_macos(),
reason="Autotools on macOS does not detect TCL",
strict=True,
)
def test_vgpane_bad_triangulation():
"""
running Tclpathplan `triangulate` with incorrect arguments should be rejected
"""
# if this appears to be an ASan-enabled CI job, teach `tclsh` to load ASan’s
# supporting library because it is otherwise unaware that Tcldot depends on this
# being loaded first
env = os.environ.copy()
dot_exe = which("dot")
if is_asan_instrumented(dot_exe):
cc = os.environ.get("CC", "gcc")
libasan = run([cc, "-print-file-name=libasan.so"]).strip()
print(f"setting LD_PRELOAD={libasan}")
env["LD_PRELOAD"] = libasan
# startup TCL and load the pathplan module
proc = pexpect.spawn("tclsh", timeout=1, env=env)
proc.expect("% ")
proc.sendline("package require Tclpathplan")
proc.expect("% ")
# Create a pane. We assume the first created pane will be index 0, though
# this is not technically required.
proc.sendline("vgpane")
proc.expect("vgpane0")
proc.expect("% ")
# bind the triangulation callback to something ending in a trailing '%'
proc.sendline("vgpane0 bind triangle %")
proc.expect("% ")
# run triangulation with no polygon ID, which should be rejected
proc.sendline("vgpane0 triangulate")
proc.expect("wrong # args")
# delete the pane to clean up, to exit ASan-clean
proc.sendline("vgpane0 delete")
proc.expect("% ")
@pytest.mark.skipif(shutil.which("tclsh") is None, reason="tclsh not available")
@pytest.mark.skipif(
platform.system() == "Windows",
reason="pexpect.spawn is not available on Windows "
"(https://pexpect.readthedocs.io/en/stable/overview.html#pexpect-on-windows)",
)
@pytest.mark.xfail(
is_cmake() and is_macos(),
reason="FIXME: 'vgpane' command is unrecognized for unknown reasons",
strict=True,
)
@pytest.mark.xfail(
is_autotools() and is_macos(),
reason="Autotools on macOS does not detect TCL",
strict=True,
)
def test_vgpane_delete():
"""
it should be possible to delete an existing `vgpane`
"""
# if this appears to be an ASan-enabled CI job, teach `tclsh` to load ASan’s
# supporting library because it is otherwise unaware that Tcldot depends on this
# being loaded first
env = os.environ.copy()
dot_exe = which("dot")
if is_asan_instrumented(dot_exe):
cc = os.environ.get("CC", "gcc")
libasan = run([cc, "-print-file-name=libasan.so"]).strip()
print(f"setting LD_PRELOAD={libasan}")
env["LD_PRELOAD"] = libasan
# startup TCL and load the pathplan module
proc = pexpect.spawn("tclsh", timeout=1, env=env)
proc.expect("% ")
proc.sendline("package require Tclpathplan")
proc.expect("% ")
# Create a pane. We assume the first created pane will be index 0, though
# this is not technically required.
proc.sendline("vgpane")
proc.expect("vgpane0")
proc.expect("% ")
# delete the pane to clean up
proc.sendline("vgpane0 delete")
# `pexpect.expect` returns an index of which given expectation was matched. We
# expect this to return no output (not the invalid handle message) and therefore
# timeout.
is_valid = proc.expect(['Invalid handle: "vgpane0"', pexpect.TIMEOUT]) == 1
assert is_valid, "created vgpane was considered an invalid handle"
def test_changelog_dates():
"""
Check the dates of releases in the changelog are correctly formatted
"""
changelog = Path(__file__).parent / "../CHANGELOG.md"
with open(changelog, "rt", encoding="utf-8") as f:
for lineno, line in enumerate(f, 1):
m = re.match(r"## \[\d+\.\d+\.\d+\] [-–] (?P<date>.*)$", line)
if m is None:
continue
d = re.match(r"\d{4}-\d{2}-\d{2}", m.group("date"))
assert (
d is not None
), f"CHANGELOG.md:{lineno}: date in incorrect format: {line}"
@pytest.mark.skipif(which("gvpack") is None, reason="gvpack not available")
def test_duplicate_hard_coded_metrics_warnings():
"""
Check “no hard-coded metrics” warnings are not repeated
"""
# use the #2239 test case that happens to provoke this
input = Path(__file__).parent / "2239.dot"
assert input.exists(), "unexpectedly missing test case"
# run it through gvpack
gvpack = which("gvpack")
p = subprocess.run(
[gvpack, "-u", "-o", os.devnull, input],
stderr=subprocess.PIPE,
check=False,
text=True,
)
assert (
p.stderr.count("no hard-coded metrics for 'sans'") <= 1
), "multiple identical “no hard-coded metrics” warnings printed"
@pytest.mark.parametrize("branch", (0, 1, 2, 3))
@pytest.mark.skipif(which("gvpr") is None, reason="gvpr not available")
def test_gvpr_switches(branch: int):
"""
confirm the behavior of GVPR switch statements
"""
# an input GVPR program with multiple blocks and switches
program = textwrap.dedent(
f"""\
BEGIN {{
switch ({branch}) {{
case 0:
printf("begin 0\\n");
break;
case 1:
printf("begin 1\\n");
break;
case 2:
printf("begin 2\\n");
break;
default:
printf("begin 3\\n");
break;
}}
}}
END {{
switch ({branch}) {{
case 0:
printf("end 0\\n");
break;
case 1:
printf("end 1\\n");
break;
case 2:
printf("end 2\\n");
break;
default:
printf("end 3\\n");
break;
}}
}}
"""
)
# run this through GVPR with no input graph
gvpr_bin = which("gvpr")
result = run([gvpr_bin, program], stdin=subprocess.DEVNULL)
# confirm we got the expected output
assert result == f"begin {branch}\nend {branch}\n", "incorrect GVPR switch behavior"
@pytest.mark.parametrize(
"statement,expected",
(
('printf("%d", 5)', "5"),
('printf("%d", 0)', "0"),
('printf("%.0d", 0)', ""),
('printf("%.0d", 1)', "1"),
('printf("%.d", 2)', "2"),
('printf("%d", -1)', "-1"),
('printf("%.3d", 5)', "005"),
('printf("%.3d", -5)', "-005"),
('printf("%5.3d", 5)', " 005"),
('printf("%-5.3d", -5)', "-005 "),
('printf("%-d", 5)', "5"),
('printf("%-+d", 5)', "+5"),
('printf("%+-d", 5)', "+5"),
('printf("%+d", -5)', "-5"),
('printf("% d", 5)', " 5"),
('printf("% .0d", 0)', " "),
('printf("%03d", 5)', "005"),
('printf("%03d", -5)', "-05"),
('printf("% +d", 5)', "+5"),
('printf("%-03d", -5)', "-5 "),
('printf("%o", 5)', "5"),
('printf("%o", 8)', "10"),
('printf("%o", 0)', "0"),
('printf("%.0o", 0)', ""),
('printf("%.0o", 1)', "1"),
('printf("%.3o", 5)', "005"),
('printf("%.3o", 8)', "010"),
('printf("%5.3o", 5)', " 005"),
('printf("%u", 5)', "5"),
('printf("%u", 0)', "0"),
('printf("%.0u", 0)', ""),
('printf("%.0u", 1)', "1"),
('printf("%.3u", 5)', "005"),
('printf("%5.3u", 5)', " 005"),
('printf("%u", 5)', "5"),
('printf("%u", 0)', "0"),
('printf("%.0u", 0)', ""),
('printf("%.0u", 1)', "1"),
('printf("%.3u", 5)', "005"),
('printf("%5.3u", 5)', " 005"),
('printf("%-x", 5)', "5"),
('printf("%03x", 5)', "005"),
('printf("%-x", 5)', "5"),
('printf("%03x", 5)', "005"),
('printf("%-X", 5)', "5"),
('printf("%03X", 5)', "005"),
('printf("%.2s", "abc")', "ab"),
('printf("%.6s", "abc")', "abc"),
('printf("%5s", "abc")', " abc"),
('printf("%-5s", "abc")', "abc "),
('printf("%5.2s", "abc")', " ab"),
('printf("%%")', "%"),
),
)
@pytest.mark.skipif(which("gvpr") is None, reason="gvpr not available")
def test_gvpr_printf(statement: str, expected: str):
"""
check various behaviors of `printf` in a GVPR program
"""
# a program that performs the given `printf`
program = f"BEGIN {{ {statement}; }}"
# run this through GVPR with no input graph
gvpr_bin = which("gvpr")
result = run([gvpr_bin, program], stdin=subprocess.DEVNULL)
# confirm we got the expected output
assert result == expected, "incorrect GVPR printf behavior"
usage_info = """\
Usage: dot [-Vv?] [-(GNEA)name=val] [-(KTlso)<val>] <dot files>
(additional options for neato) [-x] [-n<v>]
(additional options for fdp) [-L(gO)] [-L(nUCT)<val>]
(additional options for config) [-cv]
-V - Print version and exit
-v - Enable verbose mode
-Gname=val - Set graph attribute 'name' to 'val'
-Nname=val - Set node attribute 'name' to 'val'
-Ename=val - Set edge attribute 'name' to 'val'
-Aname=val - Set attribute 'name' to 'val' for graph, node, and edge
-Tv - Set output format to 'v'
-Kv - Set layout engine to 'v' (overrides default based on command name)
-lv - Use external library 'v'
-ofile - Write output to 'file'
-O - Automatically generate an output filename based on the input filename with a .'format' appended. (Causes all -ofile options to be ignored.)
-P - Internally generate a graph of the current plugins.
-q[l] - Set level of message suppression (=1)
-s[v] - Scale input by 'v' (=72)
-y - Invert y coordinate in output
-n[v] - No layout mode 'v' (=1)
-x - Reduce graph
-Lg - Don't use grid
-LO - Use old attractive force
-Ln<i> - Set number of iterations to i
-LU<i> - Set unscaled factor to i
-LC<v> - Set overlap expansion factor to v
-LT[*]<v> - Set temperature (temperature factor) to v
-c - Configure plugins (Writes $prefix/lib/graphviz/config
with available plugin information. Needs write privilege.)
-? - Print usage and exit
"""
def test_dot_questionmarkV():
"""
test the output from two short options combined
"""
out = run(["dot", "-?V"])
assert out == usage_info, "unexpected usage info"
def test_dot_randomV():
"""
test the output from a malformed command
"""
expected = f"Error: dot: option -r unrecognized\n\n{usage_info}"
proc = subprocess.run(
["dot", "-randomV"],
stderr=subprocess.PIPE,
text=True,
check=False,
)
assert proc.returncode != 0, "malformed options were accepted"
assert proc.stderr == expected, "unexpected usage info"
def test_dot_V():
"""
test the output from `dot -V`
"""
proc = subprocess.run(["dot", "-V"], stderr=subprocess.PIPE, text=True, check=True)
c_src = (Path(__file__).parent / "get-package-version.c").resolve()
assert c_src.exists(), "missing test case"
package_version, _ = run_c(c_src)
assert proc.stderr.startswith(
f"dot - graphviz version {package_version.strip()} ("
), "unexpected -V info"
def test_dot_Vquestionmark():
"""
test the output from two short options combined
"""
proc = subprocess.run(["dot", "-V?"], stderr=subprocess.PIPE, text=True, check=True)
c_src = (Path(__file__).parent / "get-package-version.c").resolve()
assert c_src.exists(), "missing test case"
package_version, _ = run_c(c_src)
assert proc.stderr.startswith(
f"dot - graphviz version {package_version.strip()} ("
), "unexpected -V info"
def test_dot_Vrandom():
"""
test the output from a short option mixed with long
"""
proc = subprocess.run(
["dot", "-Vrandom"], stderr=subprocess.PIPE, text=True, check=True
)
c_src = (Path(__file__).parent / "get-package-version.c").resolve()
assert c_src.exists(), "missing test case"
package_version, _ = run_c(c_src)
assert proc.stderr.startswith(
f"dot - graphviz version {package_version.strip()} ("
), "unexpected -V info"
def test_pic_font_size():
"""
font size in PIC output format should not be clamped down to 1
related to https://gitlab.com/graphviz/graphviz/-/issues/2487
"""
# run a basic graph through PIC generation
src = "graph { a -- b; }"
pic = dot("pic", source=src)
# confirm we got a non-1 font size
m = re.search(r"^\.ps (\d+)", pic, flags=re.MULTILINE)
assert int(m.group(1)) > 1, "font size clamped down to 1"
@pytest.mark.skipif(which("mm2gv") is None, reason="mm2gv not available")
def test_mm_banner_overflow(tmp_path: Path):
"""mm2gv should be robust against files with a corrupted banner"""
# construct a file with a corrupted banner > MM_MAX_TOKEN_LENGTH and < MM_MAX_LINE_LENGTH
mm = tmp_path / "matrix.mm"
mm.write_text(f"%{'a' * 10000}", encoding="utf-8")
# run this through mm2gv
ret = subprocess.call(["mm2gv", "-o", os.devnull, mm])
assert ret in (0, 1), "mm2gv crashed when processing malformed input"
assert ret == 1, "mm2gv did not reject malformed input"
def test_control_characters_in_error():
"""
malformed input should not result in misleading control data making it to the
output terminal unfiltered
"""
# Run something through Graphviz that will trigger an error where the error message
# will contain a color control sequence. This could be used to disrupt the user’s
# terminal in confusing ways.
src = 'graph { a[image="\033[31mfoo"]; }'
ret = subprocess.run(
["dot", "-Tsvg", "-o", os.devnull],
input=src,
stderr=subprocess.PIPE,
check=False,
text=True,
)
assert "\033" not in ret.stderr, "control character appears in error message"
# Now try something more malicious. Use the backspace character to display a different
# filename in the error message to what was referenced.
src = 'graph { a[image="foo.svg\010\010\010png"]; }'
ret = subprocess.run(
["dot", "-Tsvg", "-o", os.devnull],
input=src,
stderr=subprocess.PIPE,
check=False,
text=True,
)
assert "\010" not in ret.stderr, "control character appears in error message"
def test_fig_max_colors():
"""
using a large number of colors should not crash the FIG renderer
"""
# contruct a graph that uses well over 256 colors
buf = io.StringIO()
buf.write("graph {\n")
for red in range(256):
for green in range(10):
buf.write(f' n_{red}_{green}[color="#{red:02x}{green:02x}00"];\n')
buf.write("}\n")
# render this using the FIG renderer
dot("fig", source=buf.getvalue())
@pytest.mark.skipif(which("gvpr") is None, reason="gvpr not available")
def test_gvpr_s2f():
"""
casting a string to floating point in GVPR should work
"""
# a GVPR program that casts a string to floating point and prints the result
program = 'BEGIN { float x = (float)"1.5"; printf("%0.1f\\n", x); }'
# run this through GVPR with no input graph
gvpr_bin = which("gvpr")
result = run([gvpr_bin, program], stdin=subprocess.DEVNULL)
# confirm we got the expected output
assert result == "1.5\n", "incorrect GVPR float cast behavior"
def test_changelog():
"""
sanity checks on ../CHANGELOG.md
"""
changelog = Path(__file__).parent / "../CHANGELOG.md"
assert changelog.exists(), "CHANGELOG.md missing"
with open(changelog, "rt", encoding="utf-8") as f:
for lineno, line in enumerate(f, 1):
ignore_h2 = False
# an exception for an old heading
if line == "## [2.42.3] and earlier\n":
ignore_h2 = True
# an exception for unreleased versions
if line.startswith("## ") and "Unreleased" in line:
ignore_h2 = True
if (m := re.match("##(?P<remainder>[^#].*)$", line)) and not ignore_h2:
expected_format = r" \[\d+\.\d+\.\d+\] [\-–] \d{4}-\d{2}-\d{2}$"
assert re.match(expected_format, m.group("remainder")), (
f"CHANGELOG.md:{lineno}: second-level heading did not match "
f'regex r"{expected_format}": {line}'
)
if m := re.match("###(?P<remainder>.*)$", line):
assert m.group("remainder") in (
" Added",
" Changed",
" Fixed",
" Removed",
), f"CHANGELOG.md:{lineno}: unexpected third-level heading: {line}"
if m := re.match(
r"\[(?P<version>\d+\.\d+\.\d+)\]:(?P<remainder>.*)$", line
):
prefix = " https://gitlab.com/graphviz/graphviz/compare/"
assert m.group("remainder").startswith(
prefix
), f"CHANGELOG.md:{lineno}: unexpected finalized history link: {line}"
remainder = m.group("remainder")[len(prefix) :]
assert m.group("remainder").endswith(
f'...{m.group("version")}'
), f"CHANGELOG.md:{lineno}: history link is for wrong version: {line}"
version_range = re.match(
r"(?P<start_major>\d+)\.(?P<start_minor>\d+)\.(?P<start_patch>\d+)"
r"\.\.\."
r"(?P<end_major>\d+)\.(?P<end_minor>\d+)\.(?P<end_patch>\d+)$",
remainder,
)
assert (
version_range
), f"CHANGELOG.md:{lineno}: unexpected finalized history link: {line}"
start = tuple(
int(version_range.group(v))
for v in ("start_major", "start_minor", "start_patch")
)
end = tuple(
int(version_range.group(v))
for v in ("end_major", "end_minor", "end_patch")
)
assert (
start < end
), f"CHANGELOG.md:{lineno}: invalid version range: {line}"
def test_agxbuf_print_nul():
"""
`agxbprint` should not account for nor append a NUL byte
"""
# find co-located test source
c_src = (Path(__file__).parent / "agxbuf-print-nul.c").resolve()
assert c_src.exists(), "missing test case"
lib = Path(__file__).parents[1] / "lib"
if platform.system() == "Windows" and not is_mingw():
cflags = [f"/I{lib}"]
else:
# gnu17 needed for `strndup`
cflags = ["-std=gnu17", f"-I{lib}"]
run_c(c_src, cflags=cflags)
def test_agxbuf_use_implicit_nul():
"""
`agxbuf` should be able to use its entire memory as an inline string
"""
# find co-located test source
c_src = (Path(__file__).parent / "agxbuf-use-implicit-nul.c").resolve()
assert c_src.exists(), "missing test case"
lib = Path(__file__).parents[1] / "lib"
if platform.system() == "Windows" and not is_mingw():
cflags = [f"/I{lib}"]
else:
# gnu17 needed for `strndup`
cflags = ["-std=gnu17", f"-I{lib}"]
run_c(c_src, cflags=cflags)
@pytest.mark.skipif(which("edgepaint") is None, reason="edgepaint not available")
def test_edgepaint_error_message():
"""
when failing to open its output, edgepaint should not dereference a null
pointer
"""
# try to open a non-existent file
edgepaint = which("edgepaint")
proc = subprocess.run(
[edgepaint, "-o", "/a/nonexistent/path"],
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
check=False,
text=True,
)
# edgepaint should name itself in the error message, not “(null)”
assert re.search(
r"\bedgepaint\b", proc.stderr
), "edgepaint does not know its own name"
@pytest.mark.skipif(which("gvpr") is None, reason="gvpr not available")
def test_lock_graph():
"""GVPR’s `lock` should not misinterpret numbers >INT_MAX"""
# find co-located test sources
program1 = Path(__file__).parent / "lock_graph1.gvpr"
assert program1.exists(), "missing test case"
program2 = Path(__file__).parent / "lock_graph2.gvpr"
assert program2.exists(), "missing test case"
# a basic graph
src = "digraph { a -> b; }"
# process this with a conventional locking program
gvpr_bin = which("gvpr")
output = run([gvpr_bin, "-f", program1], input=src)
assert output == "0\n1\n", "locking a graph did not work"
# now try this with a large integer for the locking operation
output = run([gvpr_bin, "-f", program2], input=src)
assert output == "0\n1\n", "locking a graph using a large integer did not work"
def test_duplicate_font_family():
"""
SVG output should not contain duplicate `font-family` items
https://gitlab.com/graphviz/graphviz/-/merge_requests/4298
"""
# a sample graph to exercise font families
source = textwrap.dedent(
"""\
graph G {
graph [fontnames=svg];
N [label="node" fontname="Helvetica"];
}
"""
)
# convert this to SVG
svg = dot("svg", source=source)
# extract font families
for ff in re.findall(r'font-family="(?P<families>[^"]*)', svg):
families = [f.strip() for f in ff.split(",")]
assert len(families) == len(set(families)), "duplicate font families listed"
def test_plugin_version_cmake():
"""confirm the plugin version defined in CMake matches Autotools"""
autotools_current, autotools_revision, autotools_age = plugin_version()
# the CMake build system assumes the last component is 0 for now
cmake_age = 0
assert (
autotools_age == cmake_age
), "CMake build system assumes plugin age is 0 and it is not"
# parse the equivalent out of the CMake build system
cmakelists = Path(__file__).resolve().parents[1] / "CMakeLists.txt"
cmake_current: Optional[int] = None
cmake_revision: Optional[int] = None
with open(cmakelists, "rt", encoding="utf-8") as f:
for line in f:
if m := re.match(
r"\s*set\s*\(\s*GVPLUGIN_CURRENT\s+(?P<current>\d+)\s*\)\s*$",
line,
):
cmake_current = int(m.group("current"))
if cmake_revision is not None:
break
if m := re.match(
r"\s*set\s*\(\s*GVPLUGIN_REVISION\s+(?P<revision>\d+)\s*\)\s*$",
line,
):
cmake_revision = int(m.group("revision"))
if cmake_current is not None:
break
assert (
cmake_current is not None
), "failed to parse CMake build system’s plugin current version"
assert (
cmake_revision is not None
), "failed to parse CMake build system’s plugin revision"
assert (
autotools_current == cmake_current
), "Autotools and CMake build systems disagree on plugin current version"
assert (
autotools_revision == cmake_revision
), "Autotools and CMake build systems disagree on plugin revision"
def test_plugin_version_redhat():
"""confirm the plugin version defined in Red Hat spec files matches Autotools"""
autotools_current, _, _ = plugin_version()
# parse the equivalent out of the spec file
spec = Path(__file__).resolve().parents[1] / "redhat/graphviz.spec.fedora.in"
rpm_current: Optional[int] = None
with open(spec, "rt", encoding="utf-8") as f:
for line in f:
if m := re.match(
r"\s*%\s*global\s+pluginsver\s+(?P<current>\d+)\s*$",
line,
):
rpm_current = int(m.group("current"))
break
assert (
rpm_current is not None
), "failed to parse Red Hat spec file’s plugin current version"
assert (
autotools_current == rpm_current
), "Autotools and Red Hat spec file disagree on plugin current version"
@pytest.mark.parametrize("lib", ("cdt", "cgraph", "gvc", "gvpr", "pathplan", "xdot"))
def test_library_so_version(lib: str):
"""test library SO versions are consistently defined"""
# parse the canonical version out of Autotools
makefile_am = Path(__file__).resolve().parents[1] / "lib" / lib / "Makefile.am"
version: Optional[tuple[int, int, int]] = None
with open(makefile_am, "rt", encoding="utf-8") as f:
for line in f:
if m := re.match(
r"\s*"
+ lib.upper()
+ r'_VERSION\s*=\s*"(?P<current>\d+):(?P<revision>\d+):(?P<age>\d+)"\s*$',
line,
):
version = (
int(m.group("current")),
int(m.group("revision")),
int(m.group("age")),
)
break
assert version is not None, "failed to parse library version"
# parse the equivalent out of the CMake build system
cmakelists = Path(__file__).resolve().parents[1] / "lib" / lib / "CMakeLists.txt"
cmake_version: Optional[tuple[int, int, int]] = None
cmake_soversion: Optional[int] = None
with open(cmakelists, "rt", encoding="utf-8") as f:
for line in f:
if m := re.match(
r"\s*VERSION\s+(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\s*$", line
):
cmake_version = (
int(m.group("major")),
int(m.group("minor")),
int(m.group("patch")),
)
if cmake_soversion is not None:
break
continue
if m := re.match(r"\s*SOVERSION\s+(?P<major>\d+)\s*$", line):
cmake_soversion = int(m.group("major"))
if cmake_version is not None:
break
continue
assert cmake_version is not None, "failed to parse version from CMake build system"
assert (
cmake_soversion is not None
), "failed to parse SO version from CMake build system"
assert cmake_version[0] == cmake_soversion, "major version and SO version disagree"
# unconditionally use the mapping rule `major = current - age` even though this is
# platform-dependent, because all the platforms we support use this mapping
assert (
cmake_version[0] == version[0] - version[2]
), "CMake and Autotools build systems disagree on library major version"
assert (
cmake_version[1] == version[2]
), "CMake and Autotools build systems disagree on library minor version"
assert (
cmake_version[2] == version[1]
), "CMake and Autotools build systems disagree on library patch version"
# parse the equivalent out of the Debian rules
rules = Path(__file__).resolve().parents[1] / "debian/rules"
deb_soname: Optional[int] = None
with open(rules, "rt", encoding="utf-8") as f:
for line in f:
if m := re.match(
r"\s*" + lib.upper() + r"_SONAME\s*=\s*(?P<soversion>\d+)\s*$", line
):
deb_soname = int(m.group("soversion"))
break
assert deb_soname is not None, "failed to parse SONAME from Debian rules"
# again, we use a common mapping rule `major = current - age`
assert (
version[0] - version[2] == deb_soname
), "Autotools and Debian rules disagree on library version"
# parse the equivalent out of the Debian lintian overrides
overrides = (
Path(__file__).resolve().parents[1] / "debian/libgraphviz4.lintian-overrides"
)
overrides_version1: Optional[int] = None
overrides_version2: Optional[int] = None
with open(overrides, "rt", encoding="utf-8") as f:
for line in f:
if m := re.search(r"\blib" + lib + r"\.so\.(?P<soversion>\d+)\b", line):
overrides_version1 = int(m.group("soversion"))
if overrides_version2 is not None:
break
continue
if m := re.search(r"\blib" + lib + r"(?P<soversion>\d+)\b", line):
overrides_version2 = int(m.group("soversion"))
if overrides_version1 is not None:
break
continue
# libgvpr has no overrides
if lib == "gvpr":
assert overrides_version1 is None
assert overrides_version2 is None
return
assert (
overrides_version1 is not None
), f"failed to parse lib{lib}.so.* from Debian lintian overrides"
assert (
overrides_version2 is not None
), f"failed to parse lib{lib}* from Debian lintian overrides"
# again, we use a common mapping rule `major = current - age`
assert (
version[0] - version[2] == overrides_version1
), "Autotools and Debian lintian overrides disagree on library version"
assert (
version[0] - version[2] == overrides_version2
), "Autotools and Debian lintian overrides disagree on library version"
|