1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3###############################################################################
4#
5# Copyright 2006 - 2021, Tomas Babej, Paul Beckingham, Federico Hernandez.
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the "Software"), to deal
9# in the Software without restriction, including without limitation the rights
10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11# copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included
15# in all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23# SOFTWARE.
24#
25# https://www.opensource.org/licenses/mit-license.php
26#
27###############################################################################
28
29import sys
30import os
31import unittest
32# Ensure python finds the local simpletap module
33sys.path.append(os.path.dirname(os.path.abspath(__file__)))
34
35from basetest import Task, TestCase
36
37
38class TestInfoCommand(TestCase):
39    @classmethod
40    def setUpClass(cls):
41        """Executed once before any test in the class"""
42
43    def setUp(self):
44        """Executed before each test in the class"""
45        self.t = Task()
46
47    def test_missing_info(self):
48        """Verify bad filter yields error"""
49        code, out, err = self.t.runError("999 info")
50        self.assertIn("No matches.", err)
51
52    def test_info_display(self):
53        """Verify info command shows everything in the task"""
54        self.t.config("uda.u_one.type", "date")
55        self.t.config("uda.u_one.label", "U_ONE")
56        self.t.config("uda.u_two.type", "duration")
57        self.t.config("uda.u_two.label", "U_TWO")
58
59        self.t.config("urgency.user.project.P.coefficient", "1.0")
60        self.t.config("urgency.user.keyword.foo.coefficient", "1.0")
61        self.t.config("urgency.uda.u_one.coefficient", "1.0")
62
63        self.t("add foo project:P +tag priority:H start:now due:eom wait:eom scheduled:eom recur:P1M until:eoy u_one:now u_two:1day")
64        self.t("1 annotate bar", input="n\n")
65        code, out, err = self.t("1 info")
66
67        self.assertRegex(out, "ID\s+1")
68        self.assertRegex(out, "Description\s+foo")
69        self.assertRegex(out, "\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\s+bar")
70        self.assertRegex(out, "Status\s+Recurring")
71        self.assertRegex(out, "Project\s+P")
72        self.assertRegex(out, "Recurrence\s+P1M")
73        self.assertRegex(out, "Entered\s+\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}")
74        self.assertRegex(out, "Waiting until\s+\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}")
75        self.assertRegex(out, "Scheduled\s+\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}")
76        self.assertRegex(out, "Start\s+\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}")
77        self.assertRegex(out, "Due\s+\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}")
78        self.assertRegex(out, "Until\s+\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}")
79        self.assertRegex(out, "Last modified\s+\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}")
80
81        self.assertRegex(out, "Tags\s+tag")
82        self.assertIn("ACTIVE", out)
83        self.assertIn("ANNOTATED", out)
84        self.assertIn("MONTH", out)
85        self.assertIn("SCHEDULED", out)
86        self.assertIn("TAGGED", out)
87        self.assertIn("UNBLOCKED", out)
88        self.assertIn("UNTIL", out)
89        self.assertIn("YEAR", out)
90        self.assertIn("UDA", out)
91
92        self.assertRegex(out, "UUID\s+[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}")
93        self.assertRegex(out, "Urgency\s+\d+(\.\d+)?")
94        self.assertRegex(out, "Priority\s+H")
95
96        self.assertRegex(out, "Annotation of 'bar' added.")
97        self.assertIn("project", out)
98        self.assertIn("active", out)
99        self.assertIn("annotations", out)
100        self.assertIn("tags", out)
101        self.assertIn("due", out)
102        self.assertIn("UDA priority.H", out)
103        self.assertIn("U_ONE", out)
104        self.assertIn("U_TWO", out)
105
106        # TW-#2060: Make sure UDA attributes are formatted
107        self.assertRegex(out, r"U_ONE\s+\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}")
108        self.assertRegex(out, r"U_TWO\s+P1D")
109
110class TestBug425(TestCase):
111    def setUp(self):
112        self.t = Task()
113
114    def test_bug425(self):
115        """425: Make sure parser sees 'in' and not an abbreviated 'info'"""
116        self.t("add Foo")
117        self.t("1 modify Bar in Bar")
118
119        code, out, err = self.t("1 ls")
120        self.assertRegex(out, "1\s+Bar in Bar")
121
122
123if __name__ == "__main__":
124    from simpletap import TAPTestRunner
125    unittest.main(testRunner=TAPTestRunner())
126
127# vim: ai sts=4 et sw=4 ft=python
128