File: uda.t

package info (click to toggle)
task 2.6.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,088 kB
  • sloc: cpp: 45,965; python: 12,713; sh: 785; perl: 189; makefile: 21
file content (369 lines) | stat: -rwxr-xr-x 12,271 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
###############################################################################
#
# 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 re
import unittest
# Ensure python finds the local simpletap module
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from basetest import Task, TestCase

# NOTE Test classes are ordered alphabetically


class TestBaseUda(TestCase):
    def setUp(self):
        self.t = Task()
        self.t.config("uda.extra.label", "Extra")
        self.t.config("report.uda.description", "UDA Test")
        self.t.config("report.uda.columns", "id,extra,description")
        self.t.config("report.uda.sort", "extra,description")
        self.t.config("report.uda.labels", "ID,Extra,Description")


class TestUdaCommand(TestBaseUda):
    def setUp(self):
        super(TestUdaCommand, self).setUp()
        self.t.config("uda.extra.type", "string")

    def test_uda_command(self):
        """The 'udas' command should list 'priority' and 'extra'"""
        code, out, err = self.t("udas")
        self.assertIn("priority", out)
        self.assertIn("extra", out)

    def test_uda_helper_command(self):
        """The '_udas' helper command should list 'priority' and 'extra'"""
        code, out, err = self.t("_udas")
        self.assertIn("priority", out)
        self.assertIn("extra", out)


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

    def test_uda_command_orphans(self):
        """The 'udas' command should list 'orphans'"""
        # Create a task with a UDA.
        self.t.config("uda.orphan.label", "orphan")
        self.t.config("uda.orphan.type", "string")
        self.t("add one orphan:Annie")

        # Convert the UDA to an orphan.
        self.t.del_config("uda.orphan.label")
        self.t.del_config("uda.orphan.type")

        code, out, err = self.t("udas")
        self.assertIn("1 UDA defined", out)
        self.assertIn("1 Orphan UDA", out)


class TestUdaDate(TestBaseUda):
    def setUp(self):
        super(TestUdaDate, self).setUp()

        self.t.config("uda.extra.type", "date")
        self.t.config("dateformat", "m/d/Y")

    def test_uda_date_task(self):
        """Add tasks with and without a UDA date"""

        code, out, err = self.t("add with extra:tomorrow")
        self.assertIn("Created task", out)

        code, out, err = self.t("add without")
        self.assertIn("Created task", out)

        code, out, err = self.t("uda")
        self.assertRegex(out, "1\s+[\d\/]+\s+with")
        self.assertRegex(out, "2\s+without")

    def test_uda_bad_date_task(self):
        """Add tasks with an invalid UDA date"""
        code, out, err = self.t.runError("add bad extra:bad_date")
        self.assertNotIn("Created task", out)
        self.assertIn("not a valid date", err)


class TestUdaDefault(TestBaseUda):
    def setUp(self):
        super(TestUdaDefault, self).setUp()

        self.t.config("uda.extra.type", "numeric")
        self.t.config("uda.smell.type", "string")
        self.t.config("uda.smell.label", "Smell")
        self.t.config("uda.smell.values", "weak,strong")
        self.t.config("uda.smell.default", "weak")

        self.t.config("report.uda.columns", "id,smell,extra,description")
        self.t.config("report.uda.sort", "id")
        self.t.config("report.uda.labels", "ID,Smell,Size,Description")

    def test_uda_nondefault_task(self):
        """Add tasks with non default UDA"""

        code, out, err = self.t("add one smell:strong")
        self.assertIn("Created task", out)

        code, out, err = self.t("uda")
        self.assertRegex(out, "1\s+strong\s+one")

    def test_uda_default_task(self):
        """Add tasks with default UDA"""

        code, out, err = self.t("add two")
        self.assertIn("Created task", out)

        code, out, err = self.t("uda")
        self.assertRegex(out, "1\s+weak\s+two")

    def test_uda_without_default_task(self):
        """Add tasks without default UDA"""

        code, out, err = self.t("add three extra:10")
        self.assertIn("Created task", out)

        code, out, err = self.t("uda")
        self.assertRegex(out, "1\s+weak\s+10\s+three")


class TestUdaDuration(TestBaseUda):
    def setUp(self):
        super(TestUdaDuration, self).setUp()

        self.t.config("uda.extra.type", "duration")

    def test_uda_duration_task(self):
        """Add tasks with and without a UDA duration"""
        code, out, err = self.t("add with extra:1day")
        code, out, err = self.t("add without")

        code, out, err = self.t("_get 1.extra")
        self.assertEqual("P1D\n", out)

        code, out, err = self.t("_get 2.extra")
        self.assertEqual("\n", out)

        # Ensure 'extra' is stored in original form.
        code, out, err = self.t("1 export")
        self.assertRegex(out, '"extra":"P1D"')

    def test_uda_bad_duration_task(self):
        """Add tasks with an invalid UDA duration"""
        code, out, err = self.t.runError("add bad extra:bad_duration")
        self.assertNotIn("Created task", out)
        self.assertIn("The duration value 'bad_duration' is not supported",
                      err)


class TestUdaNumeric(TestBaseUda):
    def setUp(self):
        super(TestUdaNumeric, self).setUp()

        self.t.config("uda.extra.type", "numeric")

    def test_uda_numeric_task(self):
        """Add tasks with and without a UDA numeric"""

        code, out, err = self.t("add with extra:123")
        self.assertIn("Created task", out)

        code, out, err = self.t("add without")
        self.assertIn("Created task", out)

        code, out, err = self.t("uda")
        self.assertRegex(out, "1\s+\d+\s+with")
        self.assertRegex(out, "2\s+without")

    def test_uda_bad_numeric_task(self):
        """Add tasks with an invalid UDA numeric"""
        code, out, err = self.t.runError("add bad extra:bad_numeric")
        self.assertNotIn("Created task", out)
        self.assertIn("The value 'bad_numeric' is not a valid numeric value", err)


class TestUdaString(TestBaseUda):
    def setUp(self):
        super(TestUdaString, self).setUp()

        self.t.config("uda.extra.type", "string")

    def test_uda_string_task(self):
        """Add tasks with and without a UDA string"""

        code, out, err = self.t("add with extra:'one two'")
        self.assertIn("Created task", out)
        code, out, err = self.t("add without")
        self.assertIn("Created task", out)

        code, out, err = self.t("uda")
        self.assertRegex(out, "1\s+one two\s+with")
        self.assertRegex(out, "2\s+without")


class TestUdaValue(TestBaseUda):
    def setUp(self):
        super(TestUdaValue, self).setUp()

        self.t.config("uda.extra.type", "string")
        self.t.config("uda.extra.values", "weak,strong")

    def test_uda_value_task(self):
        """Add tasks with valid UDA values"""

        code, out, err = self.t("add one extra:weak")
        self.assertIn("Created task", out)
        code, out, err = self.t("add two extra:strong")
        self.assertIn("Created task", out)

        code, out, err = self.t("uda")
        self.assertRegex(out, "1\s+weak\s+one")
        self.assertRegex(out, "2\s+strong\s+two")

    def test_uda_invalid_value_task(self):
        """Add tasks with invalid UDA value"""

        code, out, err = self.t("add one extra:strong")
        self.assertIn("Created task", out)

        code, out, err = self.t.runError("add two extra:toxic")
        self.assertIn("The 'extra' attribute does not allow a value of "
                      "'toxic'", err)

        code, out, err = self.t("uda")
        self.assertRegex(out, "1\s+strong\s+one")
        self.assertNotRegex(out, "1\s+toxic\s+two")


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

        self.t.config("uda.foo.type", "numeric")
        self.t.config("uda.foo.label", "Foo")
        self.t.config("report.bar.columns", "foo,description")
        self.t.config("report.bar.description", "Bar")
        self.t.config("report.bar.labels", "Foo,Desc")
        self.t.config("report.bar.sort", "foo-")

    def test_sortable_uda(self):
        """1063: numeric UDA fields are sortable

        Reported as bug 1063
        """

        self.t("add four foo:4")
        self.t("add one foo:1")
        self.t("add three foo:3")
        self.t("add two foo:2")

        code, out, err = self.t("bar")
        expected = re.compile("4.+3.+2.+1", re.DOTALL)  # dot matches \n too
        self.assertRegex(out, expected)

        code, out, err = self.t("bar rc.report.bar.sort=foo+")
        expected = re.compile("1.+2.+3.+4", re.DOTALL)  # dot matches \n too
        self.assertRegex(out, expected)


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

    def test_almost_UDA(self):
        """21: do not match a UDA if not followed by colon"""
        self.t.config('uda.foo.type', 'string')
        self.t.config('uda.foo.label', 'FOO')

        self.t("add this is a foo bar")
        code, out, err = self.t("1 info")

        self.assertIn("this is a foo bar", out)


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

    def test_filter_uda(self):
        """1447: Verify ability to filter on empty UDA that resembles named date"""
        self.t.config('uda.sep.type', 'string')
        self.t('add one')
        self.t('add two sep:foo')
        code, out, err = self.t('sep: list')
        self.assertEqual(0, code, "Exit code was non-zero ({0})".format(code))
        self.assertIn('one', out)


class Test1542(TestCase):
    def setUp(self):
        self.t = Task()
        self.t.config("uda.bugid.type", "numeric")
        self.t.config("uda.bugid.label", "BugID")

    def test_large_numeric_uda_retains_value(self):
        """
        1542: Make sure the numeric UDA value 1187962 does not get converted to
        scientific notation on export.
        """
        self.t('add large bugid:1187962')
        code, out, err = self.t('1 export')
        self.assertIn("\"bugid\":1187962,", out)

    def test_small_numeric_uda_retains_value(self):
        """
        1542: Make sure the numeric UDA value 43.21 does not get converted to
        integer on export.
        """
        self.t('add small bugid:43.21')
        code, out, err = self.t('1 export')
        self.assertIn("\"bugid\":43.21", out)


class TestBug1622(TestCase):
    def setUp(self):
        """Executed before each test in the class"""
        self.t = Task()

    def test_uda_duration_expression(self):
        """1622: Verify that a UDA of type 'duration' accepts an expression"""
        self.t.config("uda.dur.type", "duration")
        self.t("add Run 3 miles dur:33min+18s")

        code, out, err = self.t("_get 1.dur")
        self.assertEqual("PT33M18S\n", out)


if __name__ == "__main__":
    from simpletap import TAPTestRunner
    unittest.main(testRunner=TAPTestRunner())

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