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
|
# -*- coding: utf-8 -*-
'''
Task Coach - Your friendly task manager
Copyright (C) 2004-2014 Task Coach developers <developers@taskcoach.org>
Task Coach is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Task Coach is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import xml.parsers.expat
import wx
import StringIO
import os
import tempfile
import base64
import test
from taskcoachlib import persistence, config, operating_system
from taskcoachlib.domain import date, task
class XMLTemplateReaderTestCase(test.TestCase):
def convert(self, old_format, now=date.Now):
return persistence.TemplateXMLReader.convert_old_format(old_format, now)
def testConvertNow(self):
self.assertEqual('now', self.convert('Now()'))
def testConvertToday(self):
self.assertEqual('00:00 AM today', self.convert('Today()'))
def testConvertTomorrow(self):
self.assertEqual('11:59 PM tomorrow', self.convert('Tomorrow()'))
def testConvertEndOfDay(self):
self.assertEqual('11:59 PM today', self.convert('Now().endOfDay()'))
def testConvertTomorrow2(self):
self.assertEqual('11:59 PM tomorrow',
self.convert('Now().endOfDay() + oneDay'))
def testConvertNowAndPositiveTimeDelta(self):
self.assertEqual('%d minutes from now' % date.TimeDelta(2, 1861, 0).minutes(),
self.convert('Now() + TimeDelta(2, 1861, 0)'))
def testConvertNowAndNegativeTimeDelta(self):
self.assertEqual('%d minutes ago' % date.TimeDelta(2, 1861, 0).minutes(),
self.convert('Now() - TimeDelta(2, 1861, 0)'))
def testConvertTodayAndPositiveTimeDelta(self):
now = date.Now()
expectedDate = date.Now() + date.TimeDelta(17)
expectedDateTime = date.DateTime(expectedDate.year, expectedDate.month,
expectedDate.day)
expectedMinutes = (expectedDateTime - now).minutes()
actualMinutes = int(self.convert('Today() + TimeDelta(17)').split(' ')[0])
self.failUnless(abs(actualMinutes - expectedMinutes) <= 1)
def testConvertTodayAndZeroTimeDelta(self):
now = date.Now()
expectedMinutes = (now - now.startOfDay()).minutes()
actualMinutes = int(self.convert('Today() + TimeDelta(0)').split(' ')[0])
self.failUnless(abs(actualMinutes - expectedMinutes) <= 1)
class XMLReaderTestCase(test.TestCase):
tskversion = 'Subclass responsibility'
def setUp(self):
super(XMLReaderTestCase, self).setUp()
task.Task.settings = config.Settings(load=False)
def writeAndRead(self, xml_contents):
# pylint: disable=W0201
self.fd = StringIO.StringIO()
self.fd.name = 'testfile.tsk'
self.reader = persistence.XMLReader(self.fd)
all_xml = '<?taskcoach release="whatever" ' \
'tskversion="%d"?>\n' % self.tskversion + xml_contents
self.fd.write(all_xml)
self.fd.seek(0)
return self.reader.read()
def writeAndReadTasks(self, xml_contents):
return self.writeAndRead(xml_contents)[0]
def writeAndReadCategories(self, xml_contents):
return self.writeAndRead(xml_contents)[1]
def writeAndReadNotes(self, xml_contents):
return self.writeAndRead(xml_contents)[2]
def writeAndReadSyncMLConfig(self, xml_contents):
return self.writeAndRead(xml_contents)[3]
def writeAndReadGUID(self, xml_contents):
return self.writeAndRead(xml_contents)[5]
def writeAndReadTasksAndCategories(self, xml_contents):
tasks, categories, _, _, _, _ = self.writeAndRead(xml_contents)
return tasks, categories
def writeAndReadTasksAndCategoriesAndNotes(self, xml_contents):
tasks, categories, notes, _, _, _ = self.writeAndRead(xml_contents)
return tasks, categories, notes
def writeAndReadCategoriesAndNotes(self, xml_contents):
_, categories, notes, _, _, _ = self.writeAndRead(xml_contents)
return categories, notes
class TempFileLockTest(XMLReaderTestCase):
tskversion = 25
def setUp(self):
self.oldMkstemp = tempfile.mkstemp
def newMkstemp(*args, **kwargs): # pragma: no cover
handle, name = self.oldMkstemp(*args, **kwargs)
self.__filename = name # pylint: disable=W0201
return handle, name
tempfile.mkstemp = newMkstemp
super(TempFileLockTest, self).setUp()
def tearDown(self):
tempfile.mkstemp = self.oldMkstemp
super(TempFileLockTest, self).tearDown()
def testLock(self):
if os.name == 'nt': # pragma: no cover
self.writeAndReadTasks(\
'<tasks>\n<task status="0">\n'
'<attachment type="mail" status="0">\n'
'<data extension="eml">%s</data>\n'
'</attachment>\n</task>\n</tasks>\n' % base64.encodestring('Data'))
try:
os.remove(self.__filename)
os.remove(self.__filename + '.delta')
except:
pass # pylint: disable=W0702
self.assert_(os.path.exists(self.__filename))
class XMLReaderVersion6Test(XMLReaderTestCase):
tskversion = 6
def testDescription(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task description="%s" id="foo"/>
</tasks>\n''' % u'Description')
self.assertEqual(u'Description', tasks[0].description())
def testEffortDescription(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task id="foo">
<effort start="2004-01-01 10:00:00.123000"
stop="2004-01-01 10:30:00.123000"
description="Yo"/>
</task>
</tasks>''')
self.assertEqual('Yo', tasks[0].efforts()[0].description())
class XMLReaderVersion8Test(XMLReaderTestCase):
tskversion = 8
def testReadTaskWithoutPriority(self):
tasks = self.writeAndReadTasks('<tasks><task id="foo"/></tasks>')
self.assertEqual(0, tasks[0].priority())
class XMLReaderVersion9Test(XMLReaderTestCase):
tskversion = 9
def testReadTaskWithoutId(self):
tasks = self.writeAndReadTasks('<tasks><task id="foo"/></tasks>')
self.failUnless(tasks[0].id())
class XMLReaderVersion10Test(XMLReaderTestCase):
tskversion = 10
def testReadTaskWithoutFee(self):
tasks = self.writeAndReadTasks('<tasks><task id="foo"/></tasks>')
self.assertEqual(0, tasks[0].hourlyFee())
self.assertEqual(0, tasks[0].fixedFee())
class XMLReaderVersion11Test(XMLReaderTestCase):
tskversion = 11
def testReadTaskWithoutReminder(self):
tasks = self.writeAndReadTasks('<tasks><task id="foo"/></tasks>')
self.assertEqual(date.DateTime(), tasks[0].reminder())
class XMLReaderVersion12Test(XMLReaderTestCase):
tskversion = 12
def testReadTaskWithoutMarkCompletedWhenAllChildrenCompletedSetting(self):
tasks = self.writeAndReadTasks('<tasks><task id="foo"/></tasks>')
self.assertEqual(None,
tasks[0].shouldMarkCompletedWhenAllChildrenCompleted())
class XMLReaderVersion13Test(XMLReaderTestCase):
tskversion = 13
def testOneCategory(self):
tasks, categories = self.writeAndReadTasksAndCategories('''
<tasks>
<task id="1">
<category>test</category>
</task>
</tasks>''')
self.assertEqual('test', categories[0].subject())
self.assertEqual(set([tasks[0]]), categories[0].categorizables())
self.assertEqual(set([categories[0]]), tasks[0].categories())
def testMultipleCategories(self):
tasks, categories = self.writeAndReadTasksAndCategories('''
<tasks>
<task id="1">
<category>test</category>
<category>another</category>
<category>yetanother</category>
</task>
</tasks>''')
for category in categories:
self.assertEqual(set([tasks[0]]), category.categorizables())
self.failUnless(category in tasks[0].categories())
def testSubTaskWithCategories(self):
tasks, categories = self.writeAndReadTasksAndCategories('''
<tasks>
<task id="1">
<category>test</category>
<task id="1.1">
<category>another</category>
</task>
</task>
</tasks>''')
testCategory = categories[0]
anotherCategory = categories[1]
self.assertEqual("1", list(testCategory.categorizables())[0].id())
self.assertEqual("1.1", list(anotherCategory.categorizables())[0].id())
self.assertEqual(set([testCategory]), tasks[0].categories())
self.assertEqual(set([anotherCategory]), tasks[0].children()[0].categories())
class XMLReaderVersion14Test(XMLReaderTestCase):
tskversion = 14
def testEffortWithMilliseconds(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<effort start="2004-01-01 10:00:00.123000"
stop="2004-01-01 10:30:00.123000"/>
</task>
</tasks>''')
self.assertEqual(1, len(tasks[0].efforts()))
self.assertEqual(date.TimeDelta(minutes=30), tasks[0].timeSpent())
self.assertEqual(tasks[0], tasks[0].efforts()[0].task())
class XMLReaderVersion16Text(XMLReaderTestCase):
tskversion = 16
def testOneAttachmentCompat(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<attachment>whatever.tsk</attachment>
</task>
</tasks>''')
self.assertEqual(['whatever.tsk'],
[att.location() for att in tasks[0].attachments()])
self.assertEqual(['whatever.tsk'],
[att.subject() for att in tasks[0].attachments()])
def testTwoAttachmentsCompat(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<attachment>whatever.tsk</attachment>
<attachment>another.txt</attachment>
</task>
</tasks>''')
self.assertEqual(['whatever.tsk', 'another.txt'],
[att.location() for att in tasks[0].attachments()])
self.assertEqual(['whatever.tsk', 'another.txt'],
[att.subject() for att in tasks[0].attachments()])
def testOneAttachment(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<attachment>FILE:whatever.tsk</attachment>
</task>
</tasks>''')
self.assertEqual(['whatever.tsk'],
[att.location() for att in tasks[0].attachments()])
self.assertEqual(['whatever.tsk'],
[att.subject() for att in tasks[0].attachments()])
def testTwoAttachments(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<attachment>FILE:whatever.tsk</attachment>
<attachment>FILE:another.txt</attachment>
</task>
</tasks>''')
self.assertEqual(['whatever.tsk', 'another.txt'],
[att.location() for att in tasks[0].attachments()])
self.assertEqual(['whatever.tsk', 'another.txt'],
[att.subject() for att in tasks[0].attachments()])
# There's no XMLReaderVersion17Test because the only difference between version
# 17 and 18 is the addition of an optional color attribute to categories in
# version 18. So the tests for version 18 test version 17 as well.
class XMLReaderVersion18Test(XMLReaderTestCase):
tskversion = 18
def testLastModificationTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task lastModificationTime="2004-01-01 10:00:00"/>
</tasks>''')
self.assertEqual(1, len(tasks)) # Ignore lastModificationTime
class XMLReaderVersion19Test(XMLReaderTestCase):
tskversion = 19 # New in release 0.69.0?
def testDailyRecurrence(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task recurrence="daily"/>
</tasks>''')
self.assertEqual('daily', tasks[0].recurrence().unit)
def testWeeklyRecurrence(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task recurrence="weekly"/>
</tasks>''')
self.assertEqual('weekly', tasks[0].recurrence().unit)
def testMonthlyRecurrence(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task recurrence="monthly"/>
</tasks>''')
self.assertEqual('monthly', tasks[0].recurrence().unit)
def testRecurrenceCount(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task recurrenceCount="10"/>
</tasks>''')
self.assertEqual(10, tasks[0].recurrence().count)
def testMaxRecurrenceCount(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task maxRecurrenceCount="10"/>
</tasks>''')
self.assertEqual(10, tasks[0].recurrence().max)
def testRecurrenceFrequency(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task recurrenceFrequency="3"/>
</tasks>''')
self.assertEqual(3, tasks[0].recurrence().amount)
class XMLReaderVersion20Test(XMLReaderTestCase):
tskversion = 20 # New in release 0.71.0
def testReadEmptyStream(self):
reader = persistence.XMLReader(StringIO.StringIO())
try:
reader.read()
self.fail('Expected ExpatError or ParseError') # pragma: no cover
except xml.parsers.expat.ExpatError:
pass # pragma: no cover
except xml.etree.ElementTree.ParseError:
pass # pragma: no cover
def testNoTasksAndNoCategories(self):
tasks, categories, notes = self.writeAndReadTasksAndCategoriesAndNotes('<tasks/>\n')
self.assertEqual(([], [], []), (tasks, categories, notes))
def testOneTask(self):
tasks = self.writeAndReadTasks('<tasks><task/></tasks>\n')
self.assertEqual(1, len(tasks))
self.assertEqual('', tasks[0].subject())
def testTwoTasks(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task subject="1"/>
<task subject="2"/>
</tasks>\n''')
self.assertEqual(2, len(tasks))
self.assertEqual('1', tasks[0].subject())
self.assertEqual('2', tasks[1].subject())
def testOneTask_Subject(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task subject="Yo"/>
</tasks>\n''')
self.assertEqual('Yo', tasks[0].subject())
def testOneTask_UnicodeSubject(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task subject="???"/>
</tasks>\n''')
self.assertEqual('???', tasks[0].subject())
def testBudget(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task budget="4:10:10"/>
</tasks>\n''')
self.assertEqual(date.TimeDelta(hours=4, minutes=10, seconds=10),
tasks[0].budget())
def testBudget_NoBudget(self):
tasks = self.writeAndReadTasks('<tasks><task/></tasks>\n')
self.assertEqual(date.TimeDelta(), tasks[0].budget())
def testDescription(self):
description = u'Description\nline 2'
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<description>%s</description>
</task>
</tasks>\n''' % description)
self.assertEqual(description, tasks[0].description())
def testNoChildren(self):
tasks = self.writeAndReadTasks('<tasks><task/></tasks>\n')
self.failIf((tasks[0].children()))
def testChild(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<task/>
</task>
</tasks>\n''')
self.assertEqual(1, len(tasks[0].children()))
self.assertEqual(1, len(tasks))
def testChildren(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<task/>
<task/>
</task>
</tasks>\n''')
self.assertEqual(2, len(tasks[0].children()))
self.assertEqual(1, len(tasks))
def testGrandchild(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<task>
<task/>
</task>
</task>
</tasks>\n''')
self.assertEqual(1, len(tasks))
parent = tasks[0]
self.assertEqual(1, len(parent.children()))
self.assertEqual(1, len(parent.children()[0].children()))
def testEffort(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<effort start="2004-01-01 10:00:00"
stop="2004-01-01 10:30:00"/>
</task>
</tasks>''')
self.assertEqual(1, len(tasks[0].efforts()))
self.assertEqual(date.TimeDelta(minutes=30), tasks[0].timeSpent())
self.assertEqual(tasks[0], tasks[0].efforts()[0].task())
def testChildEffort(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<task>
<effort start="2004-01-01 10:00:00"
stop="2004-01-01 10:30:00"/>
</task>
</task>
</tasks>''')
child = tasks[0].children()[0]
self.assertEqual(1, len(child.efforts()))
self.assertEqual(date.TimeDelta(minutes=30), child.timeSpent())
self.assertEqual(child, child.efforts()[0].task())
def testEffortDescription(self):
description = u'Description\nLine 2'
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<effort start="2004-01-01 10:00:00">
<description>%s</description>
</effort>
</task>
</tasks>''' % description)
self.assertEqual(description, tasks[0].efforts()[0].description())
def testActiveEffort(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<effort start="2004-01-01 10:00:00"/>
</task>
</tasks>''')
self.assertEqual(1, len(tasks[0].efforts()))
self.failUnless(tasks[0].isBeingTracked())
def testPriority(self):
tasks = self.writeAndReadTasks('<tasks><task priority="5"/></tasks>')
self.assertEqual(5, tasks[0].priority())
def testTaskId(self):
tasks = self.writeAndReadTasks('<tasks><task id="xyz"/></tasks>')
self.assertEqual('xyz', tasks[0].id())
def testTaskColor(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task color="(255, 0, 0, 255)"/>
</tasks>''')
self.assertEqual(wx.RED, tasks[0].backgroundColor())
def testHourlyFee(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task hourlyFee="100"/>
<task hourlyFee="5.5"/>
</tasks>''')
self.assertEqual(100, tasks[0].hourlyFee())
self.assertEqual(5.5, tasks[1].hourlyFee())
def testFixedFee(self):
tasks = self.writeAndReadTasks('<tasks><task fixedFee="240.50"/></tasks>')
self.assertEqual(240.5, tasks[0].fixedFee())
def testNoReminder(self):
tasks = self.writeAndReadTasks('<tasks><task reminder="None"/></tasks>')
self.assertEqual(date.DateTime(), tasks[0].reminder())
def testReminder(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task reminder="2004-01-01 10:00:00"/>
</tasks>''')
self.assertEqual(date.DateTime(2004, 1, 1, 10, 0, 0, 0),
tasks[0].reminder())
def testMarkCompletedWhenAllChildrenCompletedSetting_True(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task shouldMarkCompletedWhenAllChildrenCompleted="True"/>
</tasks>''')
self.assertEqual(True,
tasks[0].shouldMarkCompletedWhenAllChildrenCompleted())
def testMarkCompletedWhenAllChildrenCompletedSetting_False(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task shouldMarkCompletedWhenAllChildrenCompleted="False"/>
</tasks>''')
self.assertEqual(False,
tasks[0].shouldMarkCompletedWhenAllChildrenCompleted())
def testMarkCompletedWhenAllChildrenCompletedSetting_None(self):
tasks = self.writeAndReadTasks('<tasks><task/></tasks>')
self.assertEqual(None,
tasks[0].shouldMarkCompletedWhenAllChildrenCompleted())
def testTaskWithoutAttachments(self):
tasks = self.writeAndReadTasks('<tasks><task/></tasks>')
self.assertEqual([], tasks[0].attachments())
def testNoteWithoutAttachments(self):
notes = self.writeAndReadNotes('<tasks><note/></tasks>')
self.assertEqual([], notes[0].attachments())
def testCategoryWithoutAttachments(self):
categories = self.writeAndReadCategories('<tasks><category/></tasks>')
self.assertEqual([], categories[0].attachments())
def testTaskWithOneAttachment(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<attachment type="file">
<description>whatever.tsk</description>
<data>whateverdata.tsk</data>
</attachment>
</task>
</tasks>''')
self.assertEqual([os.path.join(os.getcwd(),
'testfile_attachments',
'whateverdata.tsk')],
[att.location() for att in tasks[0].attachments()])
self.assertEqual(['whatever.tsk'], [att.subject() for att in tasks[0].attachments()])
def testNoteWithOneAttachment(self):
notes = self.writeAndReadNotes('''
<tasks>
<note>
<attachment type="file">
<description>whatever.tsk</description>
<data>whateverdata.tsk</data>
</attachment>
</note>
</tasks>''')
self.assertEqual([os.path.join(os.getcwd(),
'testfile_attachments',
'whateverdata.tsk')],
[att.location() for att in notes[0].attachments()])
self.assertEqual(['whatever.tsk'], [att.subject() for att in notes[0].attachments()])
def testCategoryWithOneAttachment(self):
categories = self.writeAndReadCategories('''
<tasks>
<category>
<attachment type="file">
<description>whatever.tsk</description>
<data>whateverdata.tsk</data>
</attachment>
</category>
</tasks>''')
self.assertEqual([os.path.join(os.getcwd(),
'testfile_attachments',
'whateverdata.tsk')],
[att.location() for att in categories[0].attachments()])
self.assertEqual(['whatever.tsk'],
[att.subject() for att in categories[0].attachments()])
def testTaskWithTwoAttachments(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<attachment type="file">
<description>whatever.tsk</description>
<data>whateverdata.tsk</data>
</attachment>
<attachment type="file">
<description>another.txt</description>
<data>anotherdata.txt</data>
</attachment>
</task>
</tasks>''')
self.assertEqual([os.path.join(os.getcwd(),
'testfile_attachments',
'whateverdata.tsk'),
os.path.join(os.getcwd(),
'testfile_attachments',
'anotherdata.txt')],
[att.location() for att in tasks[0].attachments()])
self.assertEqual(['whatever.tsk', 'another.txt'],
[att.subject() for att in tasks[0].attachments()])
def testOneCategory(self):
categories = self.writeAndReadCategories('<tasks><category subject="cat"/></tasks>')
self.assertEqual('cat', categories[0].subject())
def testTwoCategories(self):
categories = self.writeAndReadCategories('''
<tasks>
<category subject="cat1"/>
<category subject="cat2"/>
</tasks>''')
self.assertEqual(['cat1', 'cat2'],
[category.subject() for category in categories])
def testCategoryId(self):
categories = self.writeAndReadCategories('''
<tasks>
<category id="catId"/>
</tasks>''')
self.assertEqual('catId', categories[0].id())
def testCategoryWithDescription(self):
categories = self.writeAndReadCategories('''
<tasks>
<category subject="cat">
<description>Description</description>
</category>
</tasks>''')
self.assertEqual('Description', categories[0].description())
def testCategoryColor(self):
categories = self.writeAndReadCategories('''
<tasks>
<category subject="cat" color="(255, 0, 0, 255)"/>
</tasks>''')
self.assertEqual(wx.RED, categories[0].backgroundColor())
def testOneTaskWithCategory(self):
tasks, categories = self.writeAndReadTasksAndCategories('''
<tasks>
<category subject="cat" categorizables="1"/>
<task id="1"/>
</tasks>''')
self.assertEqual(set(tasks), categories[0].categorizables())
def testTwoRecursiveCategories(self):
categories = self.writeAndReadCategories('''
<tasks>
<category subject="cat1">
<category subject="cat1.1"/>
</category>
</tasks>''')
self.assertEqual('cat1.1', categories[0].children()[0].subject())
def testRecursiveCategoriesNotInResultList(self):
categories = self.writeAndReadCategories('''
<tasks>
<category subject="cat1">
<category subject="cat1.1"/>
</category>
</tasks>''')
self.assertEqual(1, len(categories))
def testRecursiveCategoriesWithTwoTasks(self):
tasks, categories = self.writeAndReadTasksAndCategories('''
<tasks>
<category subject="cat1" categorizables="1">
<category subject="cat1.1" categorizables="2"/>
</category>
<task subject="task1" id="1"/>
<task subject="task2" id="2"/>
</tasks>''')
self.assertEqual(tasks[0], list(categories[0].categorizables())[0])
self.assertEqual(tasks[1],
list(categories[0].children()[0].categorizables())[0])
def testSubtaskCategory(self):
tasks, categories = self.writeAndReadTasksAndCategories('''
<tasks>
<category subject="cat1" categorizables="1.1"/>
<task subject="task1" id="1">
<task subject="task2" id="1.1"/>
</task>
</tasks>''')
self.assertEqual(tasks[0].children()[0],
list(categories[0].categorizables())[0])
def testFilteredCategory(self):
categories = self.writeAndReadCategories('''
<tasks>
<category filtered="True" subject="category"/>
</tasks>''')
self.failUnless(categories[0].isFiltered())
def testCategoryWithDeletedTasks(self):
''' There's a bug in release 0.61.5 that causes the task file to contain
references to deleted tasks. Ignore these when loading the task
file.'''
categories = self.writeAndReadCategories('''
<tasks>
<category subject="cat" tasks="some_task_id"/>
</tasks>''')
self.failIf(categories[0].categorizables())
def testNote(self):
notes = self.writeAndReadNotes('''
<tasks>
<note/>
</tasks>''')
self.failUnless(notes)
def testNoteSubject(self):
notes = self.writeAndReadNotes('''
<tasks>
<note subject="Note"/>
</tasks>''')
self.assertEqual('Note', notes[0].subject())
def testNoteDescription(self):
notes = self.writeAndReadNotes('''
<tasks>
<note>
<description>Description</description>
</note>
</tasks>''')
self.assertEqual('Description', notes[0].description())
def testNoteChild(self):
notes = self.writeAndReadNotes('''
<tasks>
<note>
<note/>
</note>
</tasks>''')
self.assertEqual(1, len(notes[0].children()))
def testNoteChildWithAttachment(self):
notes = self.writeAndReadNotes('''
<tasks>
<note>
<note>
<attachment type="file">
<description>whatever.tsk</description>
<data>whateverdata.tsk</data>
</attachment>
</note>
</note>
</tasks>''')
self.assertEqual([os.path.join(os.getcwd(),
'testfile_attachments',
'whateverdata.tsk')],
[att.location() for att in notes[0].children()[0].attachments()])
self.assertEqual(['whatever.tsk'],
[att.subject() for att in notes[0].children()[0].attachments()])
def testNoteCategory(self):
categories, notes = self.writeAndReadCategoriesAndNotes('''
<tasks>
<note id="noteId" subject="Note"/>
<category categorizables="noteId" subject="Category"/>
</tasks>''')
self.assertEqual(notes[0], list(categories[0].categorizables())[0])
def testNoteId(self):
notes = self.writeAndReadNotes('''
<tasks>
<note id="noteId"/>
</tasks>''')
self.assertEqual('noteId', notes[0].id())
def testNoteColor(self):
notes = self.writeAndReadNotes('''
<tasks>
<note color="(255, 0, 0, 255)"/>
</tasks>''')
self.assertEqual(wx.RED, notes[0].backgroundColor())
def testNoRecurrence(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task/>
</tasks>''')
self.failIf(tasks[0].recurrence())
def testDailyRecurrence(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task><recurrence unit="daily"/></task>
</tasks>''')
self.assertEqual('daily', tasks[0].recurrence().unit)
def testWeeklyRecurrence(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task><recurrence unit="weekly"/></task>
</tasks>''')
self.assertEqual('weekly', tasks[0].recurrence().unit)
def testRecurrenceAmount(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task><recurrence unit="daily" amount="2"/></task>
</tasks>''')
self.assertEqual(2, tasks[0].recurrence().amount)
def testRecurrenceMax(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task><recurrence unit="daily" max="2"/></task>
</tasks>''')
self.assertEqual(2, tasks[0].recurrence().max)
def testRecurrenceCount(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task><recurrence unit="daily" count="2"/></task>
</tasks>''')
self.assertEqual(2, tasks[0].recurrence().count)
def testRecurrenceSameWeekday(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task><recurrence unit="daily" sameWeekday="True"/></task>
</tasks>''')
self.failUnless(tasks[0].recurrence().sameWeekday)
def testTaskWithNote(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<note/>
</task>
</tasks>''')
self.assertEqual(1, len(tasks[0].notes()))
def testTaskWithNotes(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<note/><note/>
</task>
</tasks>''')
self.assertEqual(2, len(tasks[0].notes()))
def testTaskWithNestedNotes(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<note>
<note/>
</note>
</task>
</tasks>''')
self.assertEqual(1, len(tasks[0].notes()[0].children()))
def testTaskNotesDontGetAddedToOverallNotesList(self):
notes = self.writeAndReadNotes('''
<tasks>
<task>
<note/>
</task>
</tasks>''')
self.failIf(notes)
def testCategoryWithNote(self):
categories = self.writeAndReadCategories('''
<tasks>
<category>
<note/>
</category>
</tasks>''')
self.assertEqual(1, len(categories[0].notes()))
def testCategoryWithNotes(self):
categories = self.writeAndReadCategories('''
<tasks>
<category>
<note/><note/>
</category>
</tasks>''')
self.assertEqual(2, len(categories[0].notes()))
def testCategoryWithNestedNotes(self):
categories = self.writeAndReadCategories('''
<tasks>
<category>
<note>
<note/>
</note>
</category>
</tasks>''')
self.assertEqual(1, len(categories[0].notes()[0].children()))
def testCategoryNotesDontGetAddedToOverallNotesList(self):
notes = self.writeAndReadNotes('''
<tasks>
<category>
<note/>
</category>
</tasks>''')
self.failIf(notes)
def testTaskExpansion(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task expandedContexts="('None',)"/>
</tasks>''')
self.failUnless(tasks[0].isExpanded())
def testTaskExpansion_MultipleContexts(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task expandedContexts="('None','Test')"/>
</tasks>''')
self.failUnless(tasks[0].isExpanded(context='Test'))
def testCategoryExpansion(self):
categories = self.writeAndReadCategories('''
<tasks>
<category expandedContexts="('None',)"/>
</tasks>''')
self.failUnless(categories[0].isExpanded())
def testNoteExpansion(self):
notes = self.writeAndReadNotes('''
<tasks>
<note expandedContexts="('None',)"/>
</tasks>''')
self.failUnless(notes[0].isExpanded())
class XMLReaderVersion21Test(XMLReaderTestCase):
tskversion = 21 # New in release 0.71.0
def testAttachmentLocation(self):
categories = self.writeAndReadCategories('''
<tasks>
<category>
<attachment type="file" location="location">
<description>description</description>
</attachment>
</category>
</tasks>''')
self.assertEqual(['location'], [os.path.split(att.location())[-1] for att in categories[0].attachments()])
class XMLReaderVersion22Test(XMLReaderTestCase):
tskversion = 22
def testStatus(self):
tasks = self.writeAndReadTasks(\
'<tasks><task subject="Task" status="2"></task></tasks>')
self.assertEqual(2, tasks[0].getStatus())
class XMLReaderVersion23Test(XMLReaderTestCase):
tskversion = 23
def testDescription(self):
tasks = self.writeAndReadTasks(\
'<tasks><task subject="Task" status="0">'
'<description>\nDescription\n</description>'
'</task></tasks>')
self.assertEqual('\nDescription\n', tasks[0].description())
def testAttachmentData(self):
tasks = self.writeAndReadTasks(\
'<tasks>\n<task status="0">\n'
'<attachment type="mail" status="0">\n'
'<data extension="eml">%s</data>\n'
'</attachment>\n</task>\n</tasks>\n' % base64.encodestring('Data'))
self.assertEqual('Data', tasks[0].attachments()[0].data())
def testGUID(self):
guid = self.writeAndReadGUID('<tasks><guid>GUID</guid></tasks>')
self.assertEqual('GUID', guid)
def testSyncMLConfig(self):
syncmlConfig = self.writeAndReadSyncMLConfig('<tasks><syncml><property name="name">value</property></syncml></tasks>')
self.assertEqual('value', syncmlConfig.get('name'))
class XMLReaderVersion24Test(XMLReaderTestCase):
tskversion = 24 # New in release 0.72.9
# tskversion 24 introduces newlines so that the XML is not on one long
# line anymore. We have to be sure not to introduce new lines in
# text nodes though.
def testDescription(self):
tasks = self.writeAndReadTasks(\
'<tasks>\n<task subject="Task" status="0">\n'
'<description>\nDescription\n</description>\n'
'</task>\n</tasks>\n')
self.assertEqual('Description', tasks[0].description())
def testAttachmentData(self):
tasks = self.writeAndReadTasks(\
'<tasks>\n<task status="0">\n'
'<attachment type="mail" status="0">\n'
'<data extension="eml">\n%s\n</data>\n'
'</attachment>\n</task>\n</tasks>\n' % base64.encodestring('Data'))
self.assertEqual('Data', tasks[0].attachments()[0].data())
def testGUID(self):
guid = self.writeAndReadGUID('<tasks>\n<guid>\nGUID\n</guid>\n</tasks>')
self.assertEqual('GUID', guid)
def testSyncMLConfig(self):
syncmlConfig = self.writeAndReadSyncMLConfig(\
'<tasks>\n<syncml>\n'
'<property name="name">\nvalue\n</property>\n'
'</syncml>\n</tasks>\n')
self.assertEqual('value', syncmlConfig.get('name'))
def testSyncMLConfigWithNewLinesInXMLNodes(self):
''' Release 0.72.9 (and earlier?) had a bug where tags in the syncml
config information would be split across multiple lines. Fixed in
release 0.72.10. '''
expectedGUID = '0000011d209a4b6c3f9f7c32000a00b100240032'
actualGUID = self.writeAndReadGUID(\
'<tasks>\n<syncml><TaskCoach-\n'
'0000011d209a4b6c3f9f7c32000a00b100240032\n'
'><spds><sources><TaskCoach-\n'
'0000011d209a4b6c3f9f7c32000a00b100240032\n'
'.Tasks/><TaskCoach-\n'
'0000011d209a4b6c3f9f7c32000a00b100240032\n'
'.Notes/></sources><syncml><Auth/><Conn/></syncml></spds></TaskCoach-\n'
'0000011d209a4b6c3f9f7c32000a00b100240032\n'
'><TaskCoach-0000011d209a4b6c3f9f7c32000a00b100240032><spds><sources><TaskCoach-0000011d209a4b6c3f9f7c32000a00b100240032.Tasks/><TaskCoach-0000011d209a4b6c3f9f7c32000a00b100240032.Notes/></sources><syncml><Auth/><Conn/></syncml></spds></TaskCoach-0000011d209a4b6c3f9f7c32000a00b100240032></syncml><guid>\n'
'0000011d209a4b6c3f9f7c32000a00b100240032\n'
'</guid></tasks>')
self.assertEqual(expectedGUID, actualGUID)
class XMLReaderVersion26Test(XMLReaderTestCase):
tskversion = 26 # New in release 0.75.0
# Release 0.75.0 introduces percentage complete for tasks
def testPercentageComplete(self):
tasks = self.writeAndReadTasks(\
'<tasks>\n<task subject="Task" status="0" percentageComplete="50"/>\n'
'</tasks>\n')
self.assertEqual(50, tasks[0].percentageComplete())
class XMLReaderVersion27Test(XMLReaderTestCase):
tskversion = 27 # New in release 0.76.0
# Release 0.76.0 introduces exclusive subcategories
def testExclusiveSubcategories(self):
categories = self.writeAndReadCategories(\
'<categories>\n'
'<category subject="Category" exclusiveSubcategories="True"'
' status="0"/>\n'
'</categories>\n')
self.failUnless(categories[0].hasExclusiveSubcategories())
def testNoExclusiveSubcategoriesByDefault(self):
categories = self.writeAndReadCategories(\
'<categories>\n'
'<category subject="Category" status="0"/>\n'
'</categories>\n')
self.failIf(categories[0].hasExclusiveSubcategories())
class XMLReaderVersion28Test(XMLReaderTestCase):
tskversion = 28 # New in release 0.78.0
# Release 0.78.0 introduces foreground colors and fonts that can be set per object.
def testTaskForegroundColor(self):
tasks = self.writeAndReadTasks(\
'<tasks>\n<task subject="Task" fgColor="(255,0,0)"/>\n'
'</tasks>\n')
self.assertEqual(wx.RED, tasks[0].foregroundColor())
def testTaskBackgroundColor(self):
tasks = self.writeAndReadTasks(\
'<tasks>\n<task subject="Task" bgColor="(255,0,0)"/>\n'
'</tasks>\n')
self.assertEqual(wx.RED, tasks[0].backgroundColor())
def testCategoryForegroundColor(self):
categories = self.writeAndReadCategories(\
'<categories>\n<category subject="Category" fgColor="(255,0,0)"/>\n'
'</categories>\n')
self.assertEqual(wx.RED, categories[0].foregroundColor())
def testCategoryBackgroundColor(self):
categories = self.writeAndReadCategories(\
'<categories>\n<category subject="Category" bgColor="(255,0,0)"/>\n'
'</categories>\n')
self.assertEqual(wx.RED, categories[0].backgroundColor())
def testNoteForegroundColor(self):
notes = self.writeAndReadNotes(\
'<notes>\n<note subject="Note" fgColor="(255,0,0)"/>\n'
'</notes>\n')
self.assertEqual(wx.RED, notes[0].foregroundColor())
def testNoteBackgroundColor(self):
notes = self.writeAndReadNotes(\
'<notes>\n<note subject="Note" bgColor="(255,0,0)"/>\n'
'</notes>\n')
self.assertEqual(wx.RED, notes[0].backgroundColor())
def testTaskFont(self):
tasks = self.writeAndReadTasks(\
'<tasks>\n<task subject="Task" font="%s"/>\n'
'</tasks>\n' % wx.NORMAL_FONT.GetNativeFontInfoDesc())
self.assertEqual(wx.NORMAL_FONT, tasks[0].font())
def testNoTaskFont(self):
tasks = self.writeAndReadTasks(\
'<tasks>\n<task subject="Task"/>\n</tasks>\n')
self.assertEqual(None, tasks[0].font())
def testCategoryFont(self):
categories = self.writeAndReadCategories(\
'<categories>\n<category subject="Category" font="%s"/>\n'
'</categories>\n' % wx.NORMAL_FONT.GetNativeFontInfoDesc())
self.assertEqual(wx.NORMAL_FONT, categories[0].font())
def testNoteFont(self):
notes = self.writeAndReadNotes(\
'<notes>\n<note subject="Note" font="%s"/>\n'
'</notes>\n' % wx.NORMAL_FONT.GetNativeFontInfoDesc())
self.assertEqual(wx.NORMAL_FONT, notes[0].font())
def testAttachmentFont(self):
tasks = self.writeAndReadTasks(\
'<tasks>\n<task subject="Task">\n'
'<attachment type="file" location="whatever" font="%s"/>\n'
'</task>\n</tasks>\n' % wx.NORMAL_FONT.GetNativeFontInfoDesc())
self.assertEqual(wx.NORMAL_FONT, tasks[0].attachments()[0].font())
class XMLReaderVersion29Test(XMLReaderTestCase):
tskversion = 29
def testEffortNewId(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task id="foo">
<effort id="foobar" start="2004-01-01 10:00:00.123000"
stop="2004-01-01 10:30:00.123000"
status="1"
description="Yo"/>
</task>
</tasks>''')
self.assertEqual('foobar', tasks[0].efforts()[0].id())
def testTaskIcon(self):
tasks = self.writeAndReadTasks('<tasks><task icon="icon"/></tasks>')
self.assertEqual('icon', tasks[0].icon())
def testSelectedTaskIcon(self):
tasks = self.writeAndReadTasks('<tasks><task selectedIcon="icon"/></tasks>')
self.assertEqual('icon', tasks[0].selectedIcon())
def testNoteIcon(self):
notes = self.writeAndReadNotes('<tasks><note icon="icon"/></tasks>')
self.assertEqual('icon', notes[0].icon())
def testSelectedNoteIcon(self):
notes = self.writeAndReadNotes('<tasks><note selectedIcon="icon"/></tasks>')
self.assertEqual('icon', notes[0].selectedIcon())
def testCategoryIcon(self):
categories = self.writeAndReadCategories('<tasks><category icon="icon"/></tasks>')
self.assertEqual('icon', categories[0].icon())
def testSelectedCategoryIcon(self):
categories = self.writeAndReadCategories('<tasks><category selectedIcon="icon"/></tasks>')
self.assertEqual('icon', categories[0].selectedIcon())
def testAttachmentIcon(self):
tasks = self.writeAndReadTasks(\
'<tasks><task subject="Task">'
'<attachment type="file" location="whatever" icon="icon"/>'
'</task></tasks>')
self.assertEqual('icon', tasks[0].attachments()[0].icon())
def testSelectedAttachmentIcon(self):
tasks = self.writeAndReadTasks(\
'<tasks><task subject="Task">'
'<attachment type="file" location="whatever" selectedIcon="icon"/>'
'</task></tasks>')
self.assertEqual('icon', tasks[0].attachments()[0].selectedIcon())
class XMLReaderVersion30Test(XMLReaderTestCase):
tskversion = 30 # New in release 1.1.0.
def testStartDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task startdate="2005-04-17 10:05:11"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 4, 17, 10, 5, 11),
tasks[0].plannedStartDateTime())
def testStartDateTimeWithoutTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task startdate="2005-04-17"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 4, 17),
tasks[0].plannedStartDateTime())
def testNoStartDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task />
</tasks>\n''')
self.assertEqual(date.DateTime(), tasks[0].plannedStartDateTime())
def testStartDateTimeWithMicroseconds(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task startdate="2005-01-01 22:01:30.456"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 1, 1, 22, 1, 30, 456),
tasks[0].plannedStartDateTime())
def testDueDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task duedate="2005-04-17 13:05:59"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 4, 17, 13, 5, 59),
tasks[0].dueDateTime())
def testDueDateTimeWithoutTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task duedate="2005-04-17"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 4, 17, 23, 59, 59, 999999),
tasks[0].dueDateTime())
def testDueDateTimeWithoutTimeWhenEndHourIs24(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task duedate="2005-04-17"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 4, 17, 23, 59, 59, 999999),
tasks[0].dueDateTime())
def testNoDueDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task />
</tasks>\n''')
self.assertEqual(date.DateTime(), tasks[0].dueDateTime())
def testDueDateTimeWithMicroseconds(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task duedate="2005-01-01 22:01:30.456000"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 1, 1, 22, 1, 30, 456000),
tasks[0].dueDateTime())
def testCompletionDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task completiondate="2005-01-01 22:01:30"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 1, 1, 22, 1, 30),
tasks[0].completionDateTime())
self.failUnless(tasks[0].completed())
def testCompletionDateTimeWithMicroseconds(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task completiondate="2005-01-01 22:01:30.456000"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 1, 1, 22, 1, 30, 456000),
tasks[0].completionDateTime())
self.failUnless(tasks[0].completed())
def testNoCompletionDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task />
</tasks>\n''')
self.assertEqual(date.DateTime(), tasks[0].completionDateTime())
def testCompletionDateTimeWithoutTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task completiondate="2005-01-01"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 1, 1, 23, 59, 59, 999999),
tasks[0].completionDateTime())
self.failUnless(tasks[0].completed())
def testEmptyFontDescription(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task font=""/>
</tasks>\n''')
self.assertEqual(None, tasks[0].font())
def testHelveticaMacFont(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task font="0;11;70;90;90;0;Helvetica Neue Light;0"/>
</tasks>\n''')
size = tasks[0].font().GetPointSize()
if operating_system.isMac(): # pragma: no cover
self.assertEqual(11, size)
else: # pragma: no cover
self.failUnless(size > 0)
def testSans9LinuxFont(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task font="Sans 9"/>
</tasks>\n''')
if operating_system.isMac(): # pragma: no cover
self.assertEqual(None, tasks[0].font())
else: # pragma: no cover
expectedFontSize = 9 if operating_system.isGTK() else 8
self.assertEqual(expectedFontSize, tasks[0].font().GetPointSize())
class XMLReaderVersion31Test(XMLReaderTestCase):
tskversion = 31 # New in release 1.2.0.
def writeAndReadTasks(self, *args, **kwargs):
tasks = super(XMLReaderVersion31Test, self).writeAndReadTasks(*args,
**kwargs)
tasksById = dict()
def collectIds(tasks):
for eachTask in tasks:
tasksById[eachTask.id()] = eachTask
collectIds(eachTask.children())
collectIds(tasks)
return tasksById
def assertDepends(self, prerequisite, dependency):
self.failUnless(prerequisite in dependency.prerequisites())
self.failUnless(dependency in prerequisite.dependencies())
def testOnePrerequisite(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task id="1"/>
<task id="2" prerequisites="1"/>
</tasks>\n''')
self.assertDepends(tasks['1'], tasks['2'])
def testTwoPrerequisites(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task id="1"/>
<task id="2" prerequisites="1 3"/>
<task id="3"/>
</tasks>\n''')
self.assertDepends(tasks['1'], tasks['2'])
self.assertDepends(tasks['3'], tasks['2'])
def testChainOfPrerequisites(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task id="1"/>
<task id="2" prerequisites="1"/>
<task id="3" prerequisites="2"/>
</tasks>\n''')
self.assertDepends(tasks['1'], tasks['2'])
self.assertDepends(tasks['2'], tasks['3'])
def testSubTaskPrerequisite(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task id="1">
<task id="1.1"/>
</task>
<task id="2" prerequisites="1.1"/>
</tasks>\n''')
self.assertDepends(tasks['1.1'], tasks['2'])
def testInterSubTaskPrerequisite(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task id="1">
<task id="1.1"/>
<task id="1.2" prerequisites="1.1"/>
</task>
</tasks>\n''')
self.assertDepends(tasks['1.1'], tasks['1.2'])
def testMutualPrerequisites(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task id="1" prerequisites="2"/>
<task id="2" prerequisites="1"/>
</tasks>\n''')
self.assertDepends(tasks['1'], tasks['2'])
self.assertDepends(tasks['2'], tasks['1'])
def testMutualPrerequisiteWithChild(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task id="1" prerequisites="1.1">
<task id="1.1" prerequisites="1"/>
</task>
</tasks>\n''')
self.assertDepends(tasks['1'], tasks['1.1'])
self.assertDepends(tasks['1.1'], tasks['1'])
def testSelfPrerequisite(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task id="1" prerequisites="1"/>
</tasks>\n''')
self.assertDepends(tasks['1'], tasks['1'])
class XMLReaderVersion33Test(XMLReaderTestCase):
tskversion = 33 # New in release 1.2.24.
def testReminderBeforeSnooze(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task reminder="2004-01-01 10:00:00"
reminderBeforeSnooze="2004-01-01 9:00:00"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2004, 1, 1, 9, 0, 0),
tasks[0].reminder(includeSnooze=False))
self.assertEqual(date.DateTime(2004, 1, 1, 10, 0, 0),
tasks[0].reminder())
def testReminder(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task reminder="2004-01-01 10:00:00"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2004, 1, 1, 10, 0, 0),
tasks[0].reminder(includeSnooze=False))
self.assertEqual(date.DateTime(2004, 1, 1, 10, 0, 0),
tasks[0].reminder())
def testRecurrenceNotBasedOnCompletion(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task><recurrence unit="daily"/></task>
</tasks>''')
self.failIf(tasks[0].recurrence().recurBasedOnCompletion)
def testRecurrenceBasedOnCompletion(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<recurrence unit="daily" recurBasedOnCompletion="True"/>
</task>
</tasks>''')
self.failUnless(tasks[0].recurrence().recurBasedOnCompletion)
class XMLReaderVersion34Test(XMLReaderTestCase):
tskversion = 34 # New in release 1.3.5.
def testPlannedStartDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task plannedstartdate="2005-04-17 10:05:11"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 4, 17, 10, 5, 11),
tasks[0].plannedStartDateTime())
def testPlannedStartDateTimeWithoutTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task plannedstartdate="2005-04-17"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 4, 17),
tasks[0].plannedStartDateTime())
def testNoPlannedStartDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task />
</tasks>\n''')
self.assertEqual(date.DateTime(), tasks[0].plannedStartDateTime())
def testPlannedStartDateTimeWithMicroseconds(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task plannedstartdate="2005-01-01 22:01:30.456"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 1, 1, 22, 1, 30, 456),
tasks[0].plannedStartDateTime())
def testActualStartDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task actualstartdate="2005-04-17 10:05:11"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 4, 17, 10, 5, 11),
tasks[0].actualStartDateTime())
def testActualStartDateTimeWithoutTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task actualstartdate="2005-04-17"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 4, 17),
tasks[0].actualStartDateTime())
def testNoActualStartDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task />
</tasks>\n''')
self.assertEqual(date.DateTime(), tasks[0].actualStartDateTime())
def testActualStartDateTimeWithMicroseconds(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task actualstartdate="2005-01-01 22:01:30.456"/>
</tasks>\n''')
self.assertEqual(date.DateTime(2005, 1, 1, 22, 1, 30, 456),
tasks[0].actualStartDateTime())
def testTaskWithNoteWithCategory(self):
tasks, categories = self.writeAndReadTasksAndCategories('''
<tasks>
<task>
<note subject="note" id="note1"/>
</task>
<category id="cat1" categorizables="note1"/>
</tasks>\n''')
self.assertEqual(list(tasks[0].notes())[0],
list(categories[0].categorizables())[0])
class XMLReaderVersion35Test(XMLReaderTestCase):
tskversion = 35 # New in release 1.3.19.
def testRecurrenceStopDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task>
<recurrence stop_datetime="2000-01-10 13:13:13"/>
</task>
</tasks>''')
self.assertEqual(date.DateTime(2000, 1, 10, 13, 13, 13),
tasks[0].recurrence().stop_datetime)
def testCreationDateTimeIsSetToMinDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task/>
</tasks>''')
self.assertEqual(date.DateTime.min, tasks[0].creationDateTime())
class XMLReaderVersion36Test(XMLReaderTestCase):
tskversion = 36 # New in release 1.3.21
def testCreationDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task creationDateTime="2012-12-12 12:00:00.12345"/>
</tasks>''')
self.assertEqual(date.DateTime(2012, 12, 12, 12, 0, 0, 12345),
tasks[0].creationDateTime())
class XMLReaderVersion37Test(XMLReaderTestCase):
tskversion = 37 # New in release 1.3.23
def testModificationDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task modificationDateTime="2012-12-12 12:00:00.12345"/>
</tasks>''')
self.assertEqual(date.DateTime(2012, 12, 12, 12, 0, 0, 12345),
tasks[0].modificationDateTime())
def testModificationDateTimeWithOtherAttributes(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task modificationDateTime="2012-12-12 12:00:00.12345"/>
</tasks>''')
self.assertEqual(date.DateTime(2012, 12, 12, 12, 0, 0, 12345),
tasks[0].modificationDateTime())
def testAdjustDueDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task duedate="2012-12-12 23:59:00:000000" />
</tasks>''')
self.assertEqual(date.DateTime(2012, 12, 12, 23, 59, 59, 999999),
tasks[0].dueDateTime())
def test_dontAdjustPlannedStartDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task plannedstartdate="2012-12-12 23:59:00:000000" />
</tasks>''')
self.assertEqual(date.DateTime(2012, 12, 12, 23, 59, 0, 0),
tasks[0].plannedStartDateTime())
def test_dontAdjustActualStartDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task actualstartdate="2012-12-12 23:59:00:000000" />
</tasks>''')
self.assertEqual(date.DateTime(2012, 12, 12, 23, 59, 0, 0),
tasks[0].actualStartDateTime())
def test_dontAdjustCompletionDateTime(self):
tasks = self.writeAndReadTasks('''
<tasks>
<task completiondate="2012-12-12 23:59:00:000000" />
</tasks>''')
self.assertEqual(date.DateTime(2012, 12, 12, 23, 59, 0, 0),
tasks[0].completionDateTime())
def testTaskNoteCategory(self):
categories = self.writeAndReadCategories('''
<tasks>
<task>
<note id="noteid" />
</task>
<category categorizables="noteid" />
</tasks>''')
self.assert_('noteid' in [obj.id() for obj in categories[0].categorizables()])
def testSubtaskNoteCategory(self):
categories = self.writeAndReadCategories('''
<tasks>
<task>
<task>
<note id="noteid" />
</task>
</task>
<category categorizables="noteid" />
</tasks>''')
self.assert_('noteid' in [obj.id() for obj in categories[0].categorizables()])
def testCategoryNoteCategory(self):
categories = self.writeAndReadCategories('''
<tasks>
<category categorizables="noteid">
<note id="noteid" />
</category>
</tasks>''')
self.assert_('noteid' in [obj.id() for obj in categories[0].categorizables()])
def testSubcategoryNoteCategory(self):
categories = self.writeAndReadCategories('''
<tasks>
<category categorizables="noteid">
<category>
<note id="noteid" />
</category>
</category>
</tasks>''')
self.assert_('noteid' in [obj.id() for obj in categories[0].categorizables()])
def testTaskAttachmentNoteCategory(self):
categories = self.writeAndReadCategories('''
<tasks>
<task>
<attachment location="test" type="file">
<note id="noteid" />
</attachment>
</task>
<category categorizables="noteid" />
</tasks>''')
self.assert_('noteid' in [obj.id() for obj in categories[0].categorizables()])
def testSubtaskAttachmentNoteCategory(self):
categories = self.writeAndReadCategories('''
<tasks>
<task subject="Task">
<task subject="Subtask">
<attachment location="test" type="file" subject="Attachment">
<note id="noteid" subject="Note" />
</attachment>
</task>
</task>
<category categorizables="noteid" subject="Category" />
</tasks>''')
self.assert_('noteid' in [obj.id() for obj in categories[0].categorizables()])
|