Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: refactor test_main and test_storage #1199

Merged

Conversation

IronCore864
Copy link
Contributor

@IronCore864 IronCore864 commented Apr 24, 2024

Refactor test_storage and test_main to pytest style.

Before Refactor

test_main.py:

$ python -m tox -e unit -- test/test_main.py
unit: commands[0]> coverage run --source=ops/ -m pytest --ignore=test/smoke -v --tb native test/test_main.py
===================================================================== test session starts ======================================================================
platform darwin -- Python 3.11.8, pytest-7.4.4, pluggy-1.4.0 -- /Users/tiexin/work/operator3/.tox/unit/bin/python
cachedir: .tox/unit/.pytest_cache
rootdir: /Users/tiexin/work/operator3
collected 108 items
======================================================================= warnings summary =======================================================================
test/test_main.py::CharmInitTestCase::test_storage_with_storage
  /Users/tiexin/work/operator3/ops/main.py:456: DeprecationWarning: Controller storage is deprecated; it's intended for podspec charms and will be removed in a future release.
    warnings.warn("Controller storage is deprecated; it's intended for "

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================== 108 passed, 1 warning in 168.68s (0:02:48) ==========================================================
unit: commands[1]> coverage report
Name                       Stmts   Miss Branch BrPart  Cover   Missing
----------------------------------------------------------------------
ops/__init__.py               10      0      0      0   100%
ops/_private/__init__.py       0      0      0      0   100%
ops/_private/timeconv.py      61     51     28      0    11%   42-62, 74-114, 122-129
ops/_private/yaml.py           9      1      0      0    89%   33
ops/charm.py                 643    196    177     20    65%   50-80, 135-136, 147, 154-157, 164, 211, 219, 227, 270, 288, 421, 451-464, 471-479, 486-505, 580-582, 589-592, 603-605, 612-613, 647-648, 655-660, 667-686, 735-737, 744-747, 754-758, 782-783, 790-795, 802-806, 817-819, 824-825, 832, 839-840, 870, 888-889, 894, 901-903, 910-911, 923-924, 929, 936-938, 945-946, 954, 1021-1031, 1167-1168, 1198, 1203, 1208, 1218, 1226-1235, 1345, 1347, 1393-1394, 1401, 1404, 1407, 1410, 1413, 1416, 1418->1420, 1465, 1514, 1518, 1563->1572, 1566, 1568, 1594-1597, 1610-1611, 1659-1663, 1703, 1738-1740, 1743, 1763, 1772-1782, 1799-1800, 1804, 1809, 1819-1821
ops/framework.py             685    236    270     43    60%   62->exit, 64->exit, 65->exit, 66->exit, 123, 126, 129, 147, 157-172, 194, 244-245, 252, 259, 280, 288, 318, 363, 391-392, 415, 465, 467, 470, 495, 498-500, 515-516, 519, 534, 559, 562, 597-598, 609-610, 614->616, 633-635, 671->675, 687, 693, 713, 722, 733-735, 746, 758, 780, 783, 795, 808-809, 837-847, 849, 876-889, 895-954, 957, 961->exit, 982-987, 1001, 1012-1021, 1053-1055, 1062-1066, 1074-1075, 1085, 1089, 1094, 1096, 1100-1110, 1116, 1153, 1160, 1169, 1174, 1181, 1192, 1210, 1220, 1225-1227, 1231-1235, 1246, 1249-1250, 1253-1254, 1257, 1260, 1264, 1268, 1284-1285, 1288-1289, 1296-1297, 1301-1302, 1306, 1310, 1313-1318, 1321-1326, 1329-1334, 1337-1342, 1351-1352, 1359-1360, 1367-1368, 1371, 1374, 1377, 1388, 1391-1396, 1399-1404, 1407-1412
ops/jujuversion.py            80     40     48      4    42%   42, 53, 57, 61-67, 75-95, 102, 107, 124, 130, 135-142
ops/lib/__init__.py          176    176     77      0     0%   15-282
ops/log.py                    27     17      4      0    32%   29-30, 38, 55-75
ops/main.py                  262    117     92      9    49%   56-62, 75-100, 118-122, 132-143, 147, 152-220, 264, 281-301, 307, 331-332, 375-376, 408->410, 455->460, 465-469, 484, 504->509, 546
ops/model.py                1532    957    628     10    33%   100->exit, 101->exit, 146, 158, 163, 172, 177, 189, 197, 205, 225, 245, 259, 279-285, 300, 305, 317->exit, 319->exit, 326, 357, 384-395, 399-413, 432-436, 439, 465-473, 478-485, 515->exit, 520, 544-552, 556-566, 569, 579-584, 594-597, 606-608, 616-619, 633-641, 668, 696, 700, 724-735, 757-759, 796, 800-803, 806, 809, 812, 815, 818, 821, 843-844, 852, 855, 858, 861-871, 880, 883-905, 924-938, 942, 945, 948, 958-961, 964, 969-978, 985-989, 1026-1042, 1052-1055, 1066-1069, 1091-1112, 1138-1143, 1148-1154, 1164, 1191-1198, 1201-1206, 1211-1214, 1219-1242, 1262, 1281-1289, 1325, 1338-1341, 1349, 1356, 1369-1373, 1392-1397, 1414-1416, 1432-1434, 1451-1453, 1461-1463, 1508-1536, 1539, 1558-1568, 1573, 1576, 1579, 1582, 1585, 1595-1598, 1605, 1609-1613, 1618-1657, 1667-1697, 1703-1705, 1708, 1713-1719, 1722-1723, 1727, 1730-1733, 1736-1740, 1753, 1769-1771, 1774-1776, 1779, 1795-1799, 1805, 1825, 1842, 1845, 1870, 1921-1925, 1951-1953, 1965, 1968, 1971, 1974-1984, 1995-1998, 2005, 2015-2018, 2023, 2028-2029, 2034, 2039-2042, 2051, 2072-2073, 2076, 2079, 2107-2112, 2130-2145, 2149, 2153, 2157-2160, 2164-2177, 2181-2184, 2201, 2210, 2218-2220, 2228-2233, 2247-2248, 2256-2261, 2265, 2269, 2289, 2326, 2347, 2399-2432, 2484-2506, 2511-2534, 2556-2570, 2590-2596, 2600-2606, 2610-2616, 2642, 2661, 2683, 2705, 2737-2742, 2771-2774, 2782-2787, 2802, 2813, 2827, 2830, 2833, 2836, 2847, 2850, 2853, 2856, 2859, 2870, 2873, 2876, 2879, 2882, 2894-2899, 2969-2995, 3018, 3033-3060, 3064, 3067-3069, 3072-3079, 3083-3104, 3108-3127, 3130-3150, 3153-3154, 3161-3175, 3178-3179, 3183-3196, 3205-3230, 3241-3243, 3246-3248, 3251-3261, 3264-3269, 3272-3274, 3277-3278, 3283-3284, 3287, 3290, 3293, 3303-3308, 3312-3313, 3322-3331, 3335-3350, 3354, 3366-3373, 3377, 3384-3402, 3406-3411, 3416-3424, 3432-3445, 3453-3469, 3472-3475, 3478-3481, 3484-3487, 3490-3491, 3494-3495, 3502-3511, 3515-3525, 3528-3535, 3542-3543, 3553-3554, 3559-3560, 3567-3574, 3580-3585, 3610-3618, 3621-3622, 3626-3627, 3630-3634, 3661, 3705
ops/pebble.py               1282    891    431     12    26%   172->exit, 184->exit, 186->exit, 190->exit, 192->exit, 194->exit, 204-268, 284->exit, 286->exit, 288->exit, 290->exit, 292->exit, 310-315, 319-324, 331-332, 336, 346, 351-353, 360, 386-387, 390, 393, 413-417, 420, 434-435, 438-450, 453, 492-495, 498-507, 529, 534, 537, 552-557, 562, 573, 592-594, 599, 606, 617, 635-643, 648, 662, 679, 698-707, 712, 727, 749-760, 770, 778, 786, 790-796, 800, 805-809, 831-843, 848, 852-860, 863, 867-872, 881-903, 907-931, 939-947, 950, 954-959, 986-988, 992, 997-1005, 1012, 1023-1048, 1052-1064, 1067, 1071-1076, 1098-1107, 1111-1119, 1122, 1125-1130, 1191-1200, 1205-1209, 1223, 1288-1293, 1298-1306, 1316, 1389-1393, 1464-1478, 1481-1483, 1495-1497, 1500-1532, 1546-1573, 1582-1589, 1594-1600, 1609-1623, 1629-1649, 1656, 1660, 1664-1667, 1671, 1678-1680, 1684, 1688-1717, 1721, 1751-1758, 1763-1768, 1784-1793, 1802-1807, 1816-1844, 1848-1849, 1853-1855, 1859-1861, 1867-1871, 1875-1876, 1880-1882, 1899, 1917, 1938, 1959, 1980, 1986-2002, 2027-2031, 2035-2056, 2060-2075, 2080-2089, 2101-2121, 2125-2126, 2134-2138, 2142, 2146, 2168-2206, 2210-2216, 2249-2268, 2276-2287, 2293-2329, 2350-2360, 2387-2396, 2412-2420, 2442, 2464, 2608-2721, 2724-2729, 2732-2734, 2748-2761, 2779-2785, 2802-2812, 2820-2821, 2854-2864, 2871-2894, 2897-2916, 2919-2937, 2941-2943, 2947, 2950-2952, 2955, 2959, 2963, 2967-2974, 3002-3023, 3027-3069, 3079-3104
ops/storage.py               159     52     30      4    63%   47, 63->65, 76-77, 82-83, 153, 157-164, 168, 173, 191, 207-208, 243, 257-258, 265, 269-271, 275-277, 289-293, 301-307, 315, 355-356, 376-382, 394-396, 406, 416
ops/testing.py              1589   1589    768      0     0%   15-3568
ops/version.py                 2      0      0      0   100%
----------------------------------------------------------------------
TOTAL                       6517   4323   2553    102    29%

test_storage.py:

$ python -m tox -e unit -- test/test_storage.py
unit: commands[0]> coverage run --source=ops/ -m pytest --ignore=test/smoke -v --tb native test/test_storage.py
=================================================================== test session starts ====================================================================
platform darwin -- Python 3.11.8, pytest-7.4.4, pluggy-1.4.0 -- /Users/tiexin/work/operator3/.tox/unit/bin/python
cachedir: .tox/unit/.pytest_cache
rootdir: /Users/tiexin/work/operator3
collected 37 items
=================================================================== 37 passed in 27.82s ====================================================================
unit: commands[1]> coverage report
Name                       Stmts   Miss Branch BrPart  Cover   Missing
----------------------------------------------------------------------
ops/__init__.py               10      0      0      0   100%
ops/_private/__init__.py       0      0      0      0   100%
ops/_private/timeconv.py      61     51     28      0    11%   42-62, 74-114, 122-129
ops/_private/yaml.py           9      2      0      0    78%   28, 33
ops/charm.py                 643    315    177      2    45%   50-80, 135-136, 147, 154-157, 164, 211, 219, 227, 270, 288, 421, 451-464, 471-479, 486-505, 580-582, 589-592, 603-605, 612-613, 647-648, 655-660, 667-686, 735-737, 744-747, 754-758, 782-783, 790-795, 802-806, 817-819, 824-825, 832, 839-840, 870, 888-889, 894, 901-903, 910-911, 923-924, 929, 936-938, 945-946, 954, 1021-1031, 1167-1168, 1171-1193, 1198, 1203, 1208, 1213, 1218, 1226-1235, 1324-1377, 1383-1396, 1399-1420, 1438-1444, 1465, 1505-1521, 1555-1572, 1594-1597, 1610-1611, 1657-1665, 1672-1678, 1703, 1731-1743, 1763, 1772-1782, 1799-1800, 1804, 1809, 1819-1821
ops/framework.py             685    279    270     42    53%   62->exit, 64->exit, 65->exit, 66->exit, 123, 126, 129, 147, 164->169, 166->169, 170, 194, 244-245, 252, 259, 280, 288, 304, 309->311, 318, 363, 391-392, 415, 431, 463-477, 480-488, 492, 495, 498-500, 508, 515-516, 519, 534, 559, 562, 597-598, 612, 615, 633-635, 654, 670-675, 679, 687, 698-704, 713, 722, 733-735, 746, 758, 780, 783, 795, 808-809, 838, 840, 841->847, 848->exit, 859, 881-889, 897->903, 899, 905-907, 915, 918, 924, 927->948, 935-936, 942, 949, 956->exit, 961-963, 981-1001, 1012-1021, 1040, 1044, 1048-1049, 1053-1055, 1062-1066, 1069-1081, 1085, 1089, 1093-1097, 1100-1110, 1114-1116, 1145-1146, 1153, 1160, 1166-1210, 1215-1221, 1225-1227, 1231-1235, 1242-1243, 1246, 1249-1250, 1253-1254, 1257, 1260, 1263-1268, 1277-1278, 1281, 1284-1285, 1288-1289, 1292, 1296-1297, 1301-1302, 1305-1310, 1313-1318, 1321-1326, 1329-1334, 1337-1342, 1351-1352, 1359-1360, 1367-1368, 1371, 1374, 1377, 1388, 1391-1396, 1399-1404, 1407-1412
ops/jujuversion.py            80     57     48      0    26%   40-49, 52-58, 61-67, 75-95, 100-103, 107, 111, 115, 124, 130, 135-142
ops/lib/__init__.py          176    176     77      0     0%   15-282
ops/log.py                    27     17      4      0    32%   29-30, 38, 55-75
ops/main.py                  262    213     92      0    14%   49-52, 56-62, 75-100, 118-122, 132-143, 147, 152-220, 240-247, 251-264, 272-301, 305-308, 316-317, 328-336, 345, 351-368, 375-376, 406-424, 427-429, 432-439, 442-475, 483-494, 504-511, 515, 519-523, 539-546, 555
ops/model.py                1532   1022    628      6    30%   100->exit, 101->exit, 118-130, 138, 146, 158, 163, 172, 177, 189, 197, 205, 215, 225, 245, 259, 279-285, 300, 305, 312-314, 317->exit, 319->exit, 323-330, 349-354, 357, 384-395, 399-413, 432-436, 439, 465-473, 478-485, 504-517, 520, 544-552, 556-566, 569, 579-584, 594-597, 606-608, 616-619, 633-641, 668, 696, 700, 724-735, 757-759, 796, 800-803, 806, 809, 812, 815, 818, 821, 841-849, 852, 855, 858, 861-871, 880, 883-905, 916-917, 924-938, 942, 945, 948, 958-961, 964, 969-978, 985-989, 1026-1042, 1052-1055, 1066-1069, 1091-1112, 1138-1143, 1148-1154, 1164, 1191-1198, 1201-1206, 1211-1214, 1219-1242, 1262, 1281-1289, 1325, 1338-1341, 1349, 1356, 1369-1373, 1392-1397, 1414-1416, 1432-1434, 1451-1453, 1461-1463, 1508-1536, 1539, 1558-1568, 1573, 1576, 1579, 1582, 1585, 1595-1598, 1605, 1609-1613, 1618-1657, 1667-1697, 1703-1705, 1708, 1713-1719, 1722-1723, 1727, 1730-1733, 1736-1740, 1750, 1753, 1769-1771, 1774-1776, 1779, 1795-1799, 1805, 1825, 1842, 1845, 1870, 1909-1910, 1921-1925, 1940, 1951-1953, 1960-1961, 1965, 1968, 1971, 1974-1984, 1995-1998, 2005, 2015-2018, 2023, 2028-2029, 2034, 2039-2042, 2051, 2072-2073, 2076, 2079, 2107-2112, 2130-2145, 2149, 2153, 2157-2160, 2164-2177, 2181-2184, 2201, 2210, 2218-2220, 2228-2233, 2247-2248, 2256-2261, 2265, 2269, 2289, 2326, 2347, 2399-2432, 2484-2506, 2511-2534, 2556-2570, 2590-2596, 2600-2606, 2610-2616, 2642, 2661, 2683, 2705, 2737-2742, 2771-2774, 2782-2787, 2802, 2813, 2824, 2827, 2830, 2833, 2836, 2847, 2850, 2853, 2856, 2859, 2870, 2873, 2876, 2879, 2882, 2894-2899, 2969-2995, 3016-3028, 3033-3060, 3064, 3067-3069, 3072-3079, 3083-3104, 3108-3127, 3130-3150, 3153-3154, 3161-3175, 3178-3179, 3183-3196, 3205-3230, 3241-3243, 3246-3248, 3251-3261, 3264-3269, 3272-3274, 3277-3278, 3283-3284, 3287, 3290, 3293, 3303-3308, 3312-3313, 3322-3331, 3335-3350, 3354, 3366-3373, 3377, 3384-3402, 3406-3411, 3416-3424, 3432-3445, 3453-3469, 3472-3475, 3478-3481, 3484-3487, 3490-3491, 3494-3495, 3502-3511, 3515-3525, 3528-3535, 3542-3543, 3553-3554, 3559-3560, 3567-3574, 3580-3585, 3610-3618, 3621-3622, 3626-3627, 3630-3634, 3661, 3705
ops/pebble.py               1282    891    431     12    26%   172->exit, 184->exit, 186->exit, 190->exit, 192->exit, 194->exit, 204-268, 284->exit, 286->exit, 288->exit, 290->exit, 292->exit, 310-315, 319-324, 331-332, 336, 346, 351-353, 360, 386-387, 390, 393, 413-417, 420, 434-435, 438-450, 453, 492-495, 498-507, 529, 534, 537, 552-557, 562, 573, 592-594, 599, 606, 617, 635-643, 648, 662, 679, 698-707, 712, 727, 749-760, 770, 778, 786, 790-796, 800, 805-809, 831-843, 848, 852-860, 863, 867-872, 881-903, 907-931, 939-947, 950, 954-959, 986-988, 992, 997-1005, 1012, 1023-1048, 1052-1064, 1067, 1071-1076, 1098-1107, 1111-1119, 1122, 1125-1130, 1191-1200, 1205-1209, 1223, 1288-1293, 1298-1306, 1316, 1389-1393, 1464-1478, 1481-1483, 1495-1497, 1500-1532, 1546-1573, 1582-1589, 1594-1600, 1609-1623, 1629-1649, 1656, 1660, 1664-1667, 1671, 1678-1680, 1684, 1688-1717, 1721, 1751-1758, 1763-1768, 1784-1793, 1802-1807, 1816-1844, 1848-1849, 1853-1855, 1859-1861, 1867-1871, 1875-1876, 1880-1882, 1899, 1917, 1938, 1959, 1980, 1986-2002, 2027-2031, 2035-2056, 2060-2075, 2080-2089, 2101-2121, 2125-2126, 2134-2138, 2142, 2146, 2168-2206, 2210-2216, 2249-2268, 2276-2287, 2293-2329, 2350-2360, 2387-2396, 2412-2420, 2442, 2464, 2608-2721, 2724-2729, 2732-2734, 2748-2761, 2779-2785, 2802-2812, 2820-2821, 2854-2864, 2871-2894, 2897-2916, 2919-2937, 2941-2943, 2947, 2950-2952, 2955, 2959, 2963, 2967-2974, 3002-3023, 3027-3069, 3079-3104
ops/storage.py               159     12     30      2    90%   46, 112, 157-164, 306, 416
ops/testing.py              1589   1589    768      0     0%   15-3568
ops/version.py                 2      0      0      0   100%
----------------------------------------------------------------------
TOTAL                       6517   4624   2553     64    25%

After Refactor

test_main.py:

$ python -m tox -e unit -- test/test_main.py
unit: commands[0]> coverage run --source=ops/ -m pytest --ignore=test/smoke -v --tb native test/test_main.py
=================================================================================================================================================== test session starts ====================================================================================================================================================
platform darwin -- Python 3.11.8, pytest-7.4.4, pluggy-1.4.0 -- /Users/tiexin/work/operator3/.tox/unit/bin/python
cachedir: .tox/unit/.pytest_cache
rootdir: /Users/tiexin/work/operator3
collected 114 items
======================================================================================================================================== 114 passed, 1 warning in 178.77s (0:02:58) ========================================================================================================================================
unit: commands[1]> coverage report
Name                       Stmts   Miss Branch BrPart  Cover   Missing
----------------------------------------------------------------------
ops/__init__.py               10      0      0      0   100%
ops/_private/__init__.py       0      0      0      0   100%
ops/_private/timeconv.py      61     51     28      0    11%   42-62, 74-114, 122-129
ops/_private/yaml.py           9      1      0      0    89%   33
ops/charm.py                 643    196    177     20    65%   50-80, 135-136, 147, 154-157, 164, 211, 219, 227, 270, 288, 421, 451-464, 471-479, 486-505, 580-582, 589-592, 603-605, 612-613, 647-648, 655-660, 667-686, 735-737, 744-747, 754-758, 782-783, 790-795, 802-806, 817-819, 824-825, 832, 839-840, 870, 888-889, 894, 901-903, 910-911, 923-924, 929, 936-938, 945-946, 954, 1021-1031, 1167-1168, 1198, 1203, 1208, 1218, 1226-1235, 1345, 1347, 1393-1394, 1401, 1404, 1407, 1410, 1413, 1416, 1418->1420, 1465, 1514, 1518, 1563->1572, 1566, 1568, 1594-1597, 1610-1611, 1659-1663, 1703, 1738-1740, 1743, 1763, 1772-1782, 1799-1800, 1804, 1809, 1819-1821
ops/framework.py             685    236    270     43    60%   62->exit, 64->exit, 65->exit, 66->exit, 123, 126, 129, 147, 157-172, 194, 244-245, 252, 259, 280, 288, 318, 363, 391-392, 415, 465, 467, 470, 495, 498-500, 515-516, 519, 534, 559, 562, 597-598, 609-610, 614->616, 633-635, 671->675, 687, 693, 713, 722, 733-735, 746, 758, 780, 783, 795, 808-809, 837-847, 849, 876-889, 895-954, 957, 961->exit, 982-987, 1001, 1012-1021, 1053-1055, 1062-1066, 1074-1075, 1085, 1089, 1094, 1096, 1100-1110, 1116, 1153, 1160, 1169, 1174, 1181, 1192, 1210, 1220, 1225-1227, 1231-1235, 1246, 1249-1250, 1253-1254, 1257, 1260, 1264, 1268, 1284-1285, 1288-1289, 1296-1297, 1301-1302, 1306, 1310, 1313-1318, 1321-1326, 1329-1334, 1337-1342, 1351-1352, 1359-1360, 1367-1368, 1371, 1374, 1377, 1388, 1391-1396, 1399-1404, 1407-1412
ops/jujuversion.py            80     40     48      4    42%   42, 53, 57, 61-67, 75-95, 102, 107, 124, 130, 135-142
ops/lib/__init__.py          176    176     77      0     0%   15-282
ops/log.py                    27     17      4      0    32%   29-30, 38, 55-75
ops/main.py                  262    117     92      9    49%   56-62, 75-100, 118-122, 132-143, 147, 152-220, 264, 281-301, 307, 331-332, 375-376, 408->410, 455->460, 465-469, 484, 504->509, 546
ops/model.py                1532    957    628     10    33%   100->exit, 101->exit, 146, 158, 163, 172, 177, 189, 197, 205, 225, 245, 259, 279-285, 300, 305, 317->exit, 319->exit, 326, 357, 384-395, 399-413, 432-436, 439, 465-473, 478-485, 515->exit, 520, 544-552, 556-566, 569, 579-584, 594-597, 606-608, 616-619, 633-641, 668, 696, 700, 724-735, 757-759, 796, 800-803, 806, 809, 812, 815, 818, 821, 843-844, 852, 855, 858, 861-871, 880, 883-905, 924-938, 942, 945, 948, 958-961, 964, 969-978, 985-989, 1026-1042, 1052-1055, 1066-1069, 1091-1112, 1138-1143, 1148-1154, 1164, 1191-1198, 1201-1206, 1211-1214, 1219-1242, 1262, 1281-1289, 1325, 1338-1341, 1349, 1356, 1369-1373, 1392-1397, 1414-1416, 1432-1434, 1451-1453, 1461-1463, 1508-1536, 1539, 1558-1568, 1573, 1576, 1579, 1582, 1585, 1595-1598, 1605, 1609-1613, 1618-1657, 1667-1697, 1703-1705, 1708, 1713-1719, 1722-1723, 1727, 1730-1733, 1736-1740, 1753, 1769-1771, 1774-1776, 1779, 1795-1799, 1805, 1825, 1842, 1845, 1870, 1921-1925, 1951-1953, 1965, 1968, 1971, 1974-1984, 1995-1998, 2005, 2015-2018, 2023, 2028-2029, 2034, 2039-2042, 2051, 2072-2073, 2076, 2079, 2107-2112, 2130-2145, 2149, 2153, 2157-2160, 2164-2177, 2181-2184, 2201, 2210, 2218-2220, 2228-2233, 2247-2248, 2256-2261, 2265, 2269, 2289, 2326, 2347, 2399-2432, 2484-2506, 2511-2534, 2556-2570, 2590-2596, 2600-2606, 2610-2616, 2642, 2661, 2683, 2705, 2737-2742, 2771-2774, 2782-2787, 2802, 2813, 2827, 2830, 2833, 2836, 2847, 2850, 2853, 2856, 2859, 2870, 2873, 2876, 2879, 2882, 2894-2899, 2969-2995, 3018, 3033-3060, 3064, 3067-3069, 3072-3079, 3083-3104, 3108-3127, 3130-3150, 3153-3154, 3161-3175, 3178-3179, 3183-3196, 3205-3230, 3241-3243, 3246-3248, 3251-3261, 3264-3269, 3272-3274, 3277-3278, 3283-3284, 3287, 3290, 3293, 3303-3308, 3312-3313, 3322-3331, 3335-3350, 3354, 3366-3373, 3377, 3384-3402, 3406-3411, 3416-3424, 3432-3445, 3453-3469, 3472-3475, 3478-3481, 3484-3487, 3490-3491, 3494-3495, 3502-3511, 3515-3525, 3528-3535, 3542-3543, 3553-3554, 3559-3560, 3567-3574, 3580-3585, 3610-3618, 3621-3622, 3626-3627, 3630-3634, 3661, 3705
ops/pebble.py               1282    891    431     12    26%   172->exit, 184->exit, 186->exit, 190->exit, 192->exit, 194->exit, 204-268, 284->exit, 286->exit, 288->exit, 290->exit, 292->exit, 310-315, 319-324, 331-332, 336, 346, 351-353, 360, 386-387, 390, 393, 413-417, 420, 434-435, 438-450, 453, 492-495, 498-507, 529, 534, 537, 552-557, 562, 573, 592-594, 599, 606, 617, 635-643, 648, 662, 679, 698-707, 712, 727, 749-760, 770, 778, 786, 790-796, 800, 805-809, 831-843, 848, 852-860, 863, 867-872, 881-903, 907-931, 939-947, 950, 954-959, 986-988, 992, 997-1005, 1012, 1023-1048, 1052-1064, 1067, 1071-1076, 1098-1107, 1111-1119, 1122, 1125-1130, 1191-1200, 1205-1209, 1223, 1288-1293, 1298-1306, 1316, 1389-1393, 1464-1478, 1481-1483, 1495-1497, 1500-1532, 1546-1573, 1582-1589, 1594-1600, 1609-1623, 1629-1649, 1656, 1660, 1664-1667, 1671, 1678-1680, 1684, 1688-1717, 1721, 1751-1758, 1763-1768, 1784-1793, 1802-1807, 1816-1844, 1848-1849, 1853-1855, 1859-1861, 1867-1871, 1875-1876, 1880-1882, 1899, 1917, 1938, 1959, 1980, 1986-2002, 2027-2031, 2035-2056, 2060-2075, 2080-2089, 2101-2121, 2125-2126, 2134-2138, 2142, 2146, 2168-2206, 2210-2216, 2249-2268, 2276-2287, 2293-2329, 2350-2360, 2387-2396, 2412-2420, 2442, 2464, 2608-2721, 2724-2729, 2732-2734, 2748-2761, 2779-2785, 2802-2812, 2820-2821, 2854-2864, 2871-2894, 2897-2916, 2919-2937, 2941-2943, 2947, 2950-2952, 2955, 2959, 2963, 2967-2974, 3002-3023, 3027-3069, 3079-3104
ops/storage.py               159     52     30      4    63%   47, 63->65, 76-77, 82-83, 153, 157-164, 168, 173, 191, 207-208, 243, 257-258, 265, 269-271, 275-277, 289-293, 301-307, 315, 355-356, 376-382, 394-396, 406, 416
ops/testing.py              1589   1589    768      0     0%   15-3568
ops/version.py                 2      0      0      0   100%
----------------------------------------------------------------------
TOTAL                       6517   4323   2553    102    29%

Test cases number increased because of parametrize.

test_storage.py:

$ python -m tox -e unit -- test/test_storage.py
unit: commands[0]> coverage run --source=ops/ -m pytest --ignore=test/smoke -v --tb native test/test_storage.py
=================================================================================================================================================== test session starts ====================================================================================================================================================
platform darwin -- Python 3.11.8, pytest-7.4.4, pluggy-1.4.0 -- /Users/tiexin/work/operator3/.tox/unit/bin/python
cachedir: .tox/unit/.pytest_cache
rootdir: /Users/tiexin/work/operator3
collected 37 items
=================================================================================================================================================== 37 passed in 25.12s ====================================================================================================================================================
unit: commands[1]> coverage report
Name                       Stmts   Miss Branch BrPart  Cover   Missing
----------------------------------------------------------------------
ops/__init__.py               10      0      0      0   100%
ops/_private/__init__.py       0      0      0      0   100%
ops/_private/timeconv.py      61     51     28      0    11%   42-62, 74-114, 122-129
ops/_private/yaml.py           9      2      0      0    78%   28, 33
ops/charm.py                 643    315    177      2    45%   50-80, 135-136, 147, 154-157, 164, 211, 219, 227, 270, 288, 421, 451-464, 471-479, 486-505, 580-582, 589-592, 603-605, 612-613, 647-648, 655-660, 667-686, 735-737, 744-747, 754-758, 782-783, 790-795, 802-806, 817-819, 824-825, 832, 839-840, 870, 888-889, 894, 901-903, 910-911, 923-924, 929, 936-938, 945-946, 954, 1021-1031, 1167-1168, 1171-1193, 1198, 1203, 1208, 1213, 1218, 1226-1235, 1324-1377, 1383-1396, 1399-1420, 1438-1444, 1465, 1505-1521, 1555-1572, 1594-1597, 1610-1611, 1657-1665, 1672-1678, 1703, 1731-1743, 1763, 1772-1782, 1799-1800, 1804, 1809, 1819-1821
ops/framework.py             685    279    270     42    53%   62->exit, 64->exit, 65->exit, 66->exit, 123, 126, 129, 147, 164->169, 166->169, 170, 194, 244-245, 252, 259, 280, 288, 304, 309->311, 318, 363, 391-392, 415, 431, 463-477, 480-488, 492, 495, 498-500, 508, 515-516, 519, 534, 559, 562, 597-598, 612, 615, 633-635, 654, 670-675, 679, 687, 698-704, 713, 722, 733-735, 746, 758, 780, 783, 795, 808-809, 838, 840, 841->847, 848->exit, 859, 881-889, 897->903, 899, 905-907, 915, 918, 924, 927->948, 935-936, 942, 949, 956->exit, 961-963, 981-1001, 1012-1021, 1040, 1044, 1048-1049, 1053-1055, 1062-1066, 1069-1081, 1085, 1089, 1093-1097, 1100-1110, 1114-1116, 1145-1146, 1153, 1160, 1166-1210, 1215-1221, 1225-1227, 1231-1235, 1242-1243, 1246, 1249-1250, 1253-1254, 1257, 1260, 1263-1268, 1277-1278, 1281, 1284-1285, 1288-1289, 1292, 1296-1297, 1301-1302, 1305-1310, 1313-1318, 1321-1326, 1329-1334, 1337-1342, 1351-1352, 1359-1360, 1367-1368, 1371, 1374, 1377, 1388, 1391-1396, 1399-1404, 1407-1412
ops/jujuversion.py            80     57     48      0    26%   40-49, 52-58, 61-67, 75-95, 100-103, 107, 111, 115, 124, 130, 135-142
ops/lib/__init__.py          176    176     77      0     0%   15-282
ops/log.py                    27     17      4      0    32%   29-30, 38, 55-75
ops/main.py                  262    213     92      0    14%   49-52, 56-62, 75-100, 118-122, 132-143, 147, 152-220, 240-247, 251-264, 272-301, 305-308, 316-317, 328-336, 345, 351-368, 375-376, 406-424, 427-429, 432-439, 442-475, 483-494, 504-511, 515, 519-523, 539-546, 555
ops/model.py                1532   1022    628      6    30%   100->exit, 101->exit, 118-130, 138, 146, 158, 163, 172, 177, 189, 197, 205, 215, 225, 245, 259, 279-285, 300, 305, 312-314, 317->exit, 319->exit, 323-330, 349-354, 357, 384-395, 399-413, 432-436, 439, 465-473, 478-485, 504-517, 520, 544-552, 556-566, 569, 579-584, 594-597, 606-608, 616-619, 633-641, 668, 696, 700, 724-735, 757-759, 796, 800-803, 806, 809, 812, 815, 818, 821, 841-849, 852, 855, 858, 861-871, 880, 883-905, 916-917, 924-938, 942, 945, 948, 958-961, 964, 969-978, 985-989, 1026-1042, 1052-1055, 1066-1069, 1091-1112, 1138-1143, 1148-1154, 1164, 1191-1198, 1201-1206, 1211-1214, 1219-1242, 1262, 1281-1289, 1325, 1338-1341, 1349, 1356, 1369-1373, 1392-1397, 1414-1416, 1432-1434, 1451-1453, 1461-1463, 1508-1536, 1539, 1558-1568, 1573, 1576, 1579, 1582, 1585, 1595-1598, 1605, 1609-1613, 1618-1657, 1667-1697, 1703-1705, 1708, 1713-1719, 1722-1723, 1727, 1730-1733, 1736-1740, 1750, 1753, 1769-1771, 1774-1776, 1779, 1795-1799, 1805, 1825, 1842, 1845, 1870, 1909-1910, 1921-1925, 1940, 1951-1953, 1960-1961, 1965, 1968, 1971, 1974-1984, 1995-1998, 2005, 2015-2018, 2023, 2028-2029, 2034, 2039-2042, 2051, 2072-2073, 2076, 2079, 2107-2112, 2130-2145, 2149, 2153, 2157-2160, 2164-2177, 2181-2184, 2201, 2210, 2218-2220, 2228-2233, 2247-2248, 2256-2261, 2265, 2269, 2289, 2326, 2347, 2399-2432, 2484-2506, 2511-2534, 2556-2570, 2590-2596, 2600-2606, 2610-2616, 2642, 2661, 2683, 2705, 2737-2742, 2771-2774, 2782-2787, 2802, 2813, 2824, 2827, 2830, 2833, 2836, 2847, 2850, 2853, 2856, 2859, 2870, 2873, 2876, 2879, 2882, 2894-2899, 2969-2995, 3016-3028, 3033-3060, 3064, 3067-3069, 3072-3079, 3083-3104, 3108-3127, 3130-3150, 3153-3154, 3161-3175, 3178-3179, 3183-3196, 3205-3230, 3241-3243, 3246-3248, 3251-3261, 3264-3269, 3272-3274, 3277-3278, 3283-3284, 3287, 3290, 3293, 3303-3308, 3312-3313, 3322-3331, 3335-3350, 3354, 3366-3373, 3377, 3384-3402, 3406-3411, 3416-3424, 3432-3445, 3453-3469, 3472-3475, 3478-3481, 3484-3487, 3490-3491, 3494-3495, 3502-3511, 3515-3525, 3528-3535, 3542-3543, 3553-3554, 3559-3560, 3567-3574, 3580-3585, 3610-3618, 3621-3622, 3626-3627, 3630-3634, 3661, 3705
ops/pebble.py               1282    891    431     12    26%   172->exit, 184->exit, 186->exit, 190->exit, 192->exit, 194->exit, 204-268, 284->exit, 286->exit, 288->exit, 290->exit, 292->exit, 310-315, 319-324, 331-332, 336, 346, 351-353, 360, 386-387, 390, 393, 413-417, 420, 434-435, 438-450, 453, 492-495, 498-507, 529, 534, 537, 552-557, 562, 573, 592-594, 599, 606, 617, 635-643, 648, 662, 679, 698-707, 712, 727, 749-760, 770, 778, 786, 790-796, 800, 805-809, 831-843, 848, 852-860, 863, 867-872, 881-903, 907-931, 939-947, 950, 954-959, 986-988, 992, 997-1005, 1012, 1023-1048, 1052-1064, 1067, 1071-1076, 1098-1107, 1111-1119, 1122, 1125-1130, 1191-1200, 1205-1209, 1223, 1288-1293, 1298-1306, 1316, 1389-1393, 1464-1478, 1481-1483, 1495-1497, 1500-1532, 1546-1573, 1582-1589, 1594-1600, 1609-1623, 1629-1649, 1656, 1660, 1664-1667, 1671, 1678-1680, 1684, 1688-1717, 1721, 1751-1758, 1763-1768, 1784-1793, 1802-1807, 1816-1844, 1848-1849, 1853-1855, 1859-1861, 1867-1871, 1875-1876, 1880-1882, 1899, 1917, 1938, 1959, 1980, 1986-2002, 2027-2031, 2035-2056, 2060-2075, 2080-2089, 2101-2121, 2125-2126, 2134-2138, 2142, 2146, 2168-2206, 2210-2216, 2249-2268, 2276-2287, 2293-2329, 2350-2360, 2387-2396, 2412-2420, 2442, 2464, 2608-2721, 2724-2729, 2732-2734, 2748-2761, 2779-2785, 2802-2812, 2820-2821, 2854-2864, 2871-2894, 2897-2916, 2919-2937, 2941-2943, 2947, 2950-2952, 2955, 2959, 2963, 2967-2974, 3002-3023, 3027-3069, 3079-3104
ops/storage.py               159     12     30      2    90%   46, 112, 157-164, 306, 416
ops/testing.py              1589   1589    768      0     0%   15-3568
ops/version.py                 2      0      0      0   100%
----------------------------------------------------------------------
TOTAL                       6517   4624   2553     64    25%

Unchanged.

@IronCore864 IronCore864 changed the title Pytest phase2 test storage main test: refactor test main and test storage Apr 24, 2024
@IronCore864 IronCore864 marked this pull request as ready for review April 24, 2024 14:47
Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking pretty reasonable. Just a few minor comments.

test/test_main.py Show resolved Hide resolved
test/test_main.py Outdated Show resolved Hide resolved
test/test_main.py Show resolved Hide resolved
test/test_main.py Outdated Show resolved Hide resolved
test/test_main.py Outdated Show resolved Hide resolved
test/test_storage.py Outdated Show resolved Hide resolved
Copy link
Contributor

@tonyandrewmeyer tonyandrewmeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really great! A couple of very small comments.

I'm loving getting all that typing mess out of test_main :)

test/test_main.py Outdated Show resolved Hide resolved
test/test_main.py Outdated Show resolved Hide resolved
test/test_main.py Outdated Show resolved Hide resolved
test/test_main.py Outdated Show resolved Hide resolved
@IronCore864
Copy link
Contributor Author

I have refactored the PR according to your reviews, also excluded mac-os python 3.9. Now tests are passing. Please take another look.

@IronCore864 IronCore864 changed the title test: refactor test main and test storage test: refactor test_main and test_storage Apr 26, 2024
Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me, thanks!

Copy link
Contributor

@tonyandrewmeyer tonyandrewmeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@IronCore864 IronCore864 merged commit 6557b10 into canonical:main May 16, 2024
25 checks passed
@IronCore864 IronCore864 deleted the pytest-phase2-test-storage-main branch May 16, 2024 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants