File: due.test.py

package info (click to toggle)
task 3.4.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 7,332 kB
  • sloc: cpp: 42,567; python: 12,689; sh: 775; perl: 189; makefile: 35
file content (145 lines) | stat: -rwxr-xr-x 5,130 bytes parent folder | download
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
#!/usr/bin/env python3
###############################################################################
#
# Copyright 2006 - 2021, Tomas Babej, Paul Beckingham, Federico Hernandez.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# https://www.opensource.org/licenses/mit-license.php
#
###############################################################################

import sys
import os
import unittest
from datetime import datetime, timedelta

# Ensure python finds the local simpletap module
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from basetest import Task, TestCase


def timestamp_without_leading_zeros(time):
    t = time.strftime("%m/%d/%Y")
    return "/".join([x.lstrip("0") for x in t.split("/")])


class TestDue(TestCase):
    def setUp(self):
        self.t = Task()

        self.t.config("due", "4")
        self.t.config("color", "on")
        self.t.config("color.due", "red")
        self.t.config("color.alternate", "")
        self.t.config("_forcecolor", "on")
        self.t.config("dateformat", "m/d/Y")

        just = datetime.now() + timedelta(days=3)
        almost = datetime.now() + timedelta(days=5)

        self.just = timestamp_without_leading_zeros(just)
        self.almost = timestamp_without_leading_zeros(almost)

        self.t("add one due:{0}".format(self.just))
        self.t("add two due:{0}".format(self.almost))

    def test_due(self):
        """due tasks displayed correctly"""
        code, out, err = self.t("list")
        self.assertRegex(out, "\033\\[31m.+{0}.+\033\\[0m".format(self.just))
        self.assertRegex(out, r"\s+{0}\s+".format(self.almost))


class TestBug418(TestCase):
    # NOTE: Originally Bug #418: due.before:eow not working
    #   - with dateformat 'MD'
    def setUp(self):
        self.t = Task()

        self.t.config("due", "4")
        self.t.config("dateformat", "m/d/Y")
        self.t.config("report.foo.description", "Sample")
        self.t.config("report.foo.columns", "id,due,description")
        self.t.config("report.foo.labels", "ID,Due,Description")
        self.t.config("report.foo.sort", "due+")
        self.t.config("report.foo.filter", "status:pending")
        self.t.config("report.foo.dateformat", "MD")

    def test_bug_418(self):
        """due.before:eow bad with dateformat 'MD'"""
        self.t("add one   due:6/28/2010")
        self.t("add two   due:6/29/2010")
        self.t("add three due:6/30/2010")
        self.t("add four  due:7/1/2010")
        self.t("add five  due:7/2/2010")
        self.t("add six   due:7/3/2010")
        self.t("add seven due:7/4/2010")
        self.t("add eight due:7/5/2010")
        self.t("add nine  due:7/6/2010")

        code, out, err = self.t("foo")
        self.assertIn("one", out)
        self.assertIn("two", out)
        self.assertIn("three", out)
        self.assertIn("four", out)
        self.assertIn("five", out)
        self.assertIn("six", out)
        self.assertIn("seven", out)
        self.assertIn("eight", out)
        self.assertIn("nine", out)

        code, out, err = self.t("foo due.before:7/2/2010")
        self.assertIn("one", out)
        self.assertIn("two", out)
        self.assertIn("three", out)
        self.assertIn("four", out)
        self.assertNotIn("five", out)
        self.assertNotIn("six", out)
        self.assertNotIn("seven", out)
        self.assertNotIn("eight", out)
        self.assertNotIn("nine", out)


class TestBug2519(TestCase):
    def setUp(self):
        self.t = Task()

    def test_due_today_includes_eod(self):
        """Verify that virtual tag +TODAY matches a task due eod"""
        self.t("add zero due:eod")

        code, out, err = self.t("+TODAY ls")
        self.assertIn("zero", out)

    def test_eoy_is_not_before_eoy(self):
        """Verify that end of year is not before end of year"""
        self.t("add zero due:eoy")

        code, out, err = self.t.runError("due.before:eoy")
        self.assertNotIn("1", out)


if __name__ == "__main__":
    from simpletap import TAPTestRunner

    unittest.main(testRunner=TAPTestRunner())

# vim: ai sts=4 et sw=4 ft=python