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
|
#!/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 unittest
# Ensure python finds the local simpletap module
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from basetest import Task, TestCase
class TestProjects(TestCase):
def setUp(self):
self.t = Task()
self.STATUS = ("The project '{0}' has changed\. "
"Project '{0}' is {1} complete \({2} remaining\)\.")
def test_project_summary_count(self):
"""'task projects' shouldn't consider deleted tasks in summary.
Reported in bug 1044
"""
self.t("add project:A 1")
self.t("add project:B 2")
self.t("add project:B 3")
self.t("3 delete", input="y\n")
code, out, err = self.t("project:B projects")
expected = "1 project \(1 task\)"
self.assertRegex(out, expected)
def test_project_progress(self):
"""project status/progress is shown and is up-to-date"""
code, out, err = self.t("add one pro:foo")
self.assertRegex(err, self.STATUS.format("foo", "0%",
"1 task"))
code, out, err = self.t("add two pro:foo")
self.assertRegex(err, self.STATUS.format("foo", "0%",
"2 of 2 tasks"))
code, out, err = self.t("add three pro:foo")
self.assertRegex(err, self.STATUS.format("foo", "0%",
"3 of 3 tasks"))
code, out, err = self.t("add four pro:foo")
self.assertRegex(err, self.STATUS.format("foo", "0%",
"4 of 4 tasks"))
code, out, err = self.t("1 done")
self.assertRegex(err, self.STATUS.format("foo", "25%",
"3 of 4 tasks"))
code, out, err = self.t("2 delete", input="y\n")
self.assertRegex(err, self.STATUS.format("foo", "33%",
"2 of 3 tasks"))
code, out, err = self.t("3 modify pro:bar")
self.assertRegex(err, self.STATUS.format("foo", "50%",
"1 of 2 tasks"))
self.assertRegex(err, self.STATUS.format("bar", "0%",
"1 task"))
def test_project_spaces(self):
"""projects with spaces are handled correctly"""
self.t("add hello pro:bob")
code, out, err = self.t('1 mod pro:"foo bar"')
self.assertRegex(err, self.STATUS.format("foo bar", "0%",
"1 task"))
# Ensure filtering for project with spaces works
code, out, err = self.t('pro:"foo bar" count')
self.assertEqual(out.strip(), '1')
def test_project_spaces(self):
"""TW #2386: Filter for project:someday"""
self.t("add hello pro:someday")
# Ensure filtering for project with numeric date works
code, out, err = self.t('pro:someday count')
self.assertEqual(out.strip(), '1')
def add_tasks(self):
self.t("add testing project:existingParent")
self.t("add testing project:existingParent.child")
self.t("add testing project:abstractParent.kid")
self.t("add testing project:.myProject")
self.t("add testing project:myProject")
self.t("add testing project:.myProject.")
def validate_indentation(self, out):
order = (
".myProject ",
".myProject. ",
"abstractParent", # No space at EOL because this line in the summary ends here.
" kid ",
"existingParent ",
" child ",
"myProject ",
)
lines = out.splitlines(True) # True = keep newlines
# position where project names start on the lines list
position = 3
for i, proj in enumerate(order):
pos = position + i
self.assertTrue(
lines[pos].startswith(proj),
msg=("Project '{0}' is not in line #{1} or has an unexpected "
"indentation.{2}".format(proj, pos, out))
)
def test_project_indentation(self):
"""check project/subproject indentation in 'task projects'
Reported in bug 1056
See also the tests of helper functions for CmdProjects in util.t.cpp
"""
self.add_tasks()
code, out, err = self.t("projects")
self.validate_indentation(out)
def test_project_indentation_in_summary(self):
"""check project/subproject indentation in 'task summary'
Reported in bug 1056
"""
self.add_tasks()
code, out, err = self.t("summary")
self.validate_indentation(out)
def test_project_helper(self):
"""Verify _projects helper list projects"""
self.t("add project:A one")
self.t("add project:B two")
self.t("2 delete", input="y\n")
self.t("log project:C three")
self.t("list")
code, out, err = self.t("_projects")
self.assertIn("A", out)
self.assertNotIn("B", out)
self.assertNotIn("C", out)
code, out, err = self.t("_projects rc.list.all.projects:1")
self.assertIn("A", out)
self.assertIn("B", out)
self.assertIn("C", out)
class TestSubprojects(TestCase):
@classmethod
def setUpClass(cls):
"""Executed once before any test in the class"""
cls.t = Task()
cls.t("add project:abc abc")
cls.t("add project:ab ab")
cls.t("add project:a a")
cls.t("add project:b b")
def test_project_exact1(self):
"""Verify single character exact"""
code, out, err = self.t("list project:b")
self.assertRegex(out, r"\bb\s")
def test_project_top1(self):
"""Verify single character parent"""
code, out, err = self.t("list project:a")
self.assertRegex(out, r"\babc\s")
self.assertRegex(out, r"\bab\s")
self.assertRegex(out, r"\ba\s")
def test_project_top2(self):
"""Verify double character parent"""
code, out, err = self.t("list project:ab")
self.assertRegex(out, r"\babc\s")
self.assertRegex(out, r"\bab\s")
def test_project_exact3(self):
"""Verify triple character exact"""
code, out, err = self.t("list project:abc")
self.assertRegex(out, r"\babc\s")
def test_project_mismatch4(self):
"""Verify quad character mismatch"""
code, out, err = self.t.runError("list project:abcd")
self.assertIn("No matches", err)
class TestBug299(TestCase):
def setUp(self):
self.t = Task()
self.t("add project:one foo")
self.t("add project:ones faz")
self.t("add project:phone boo")
self.t("add project:bones too")
self.t("add project:two bar")
self.t("add project:three baz")
def test_project_exclusion_isnt(self):
"""299: check project exclusion using project.isnt:<name>
Reported in bug 299
"""
code, out, err = self.t("list project.isnt:one pro.isnt:two")
self.assertNotRegex(out, "one.*foo")
self.assertRegex(out, "ones.*faz")
self.assertRegex(out, "phone.*boo")
self.assertRegex(out, "bones.*too")
self.assertNotRegex(out, "two.*bar")
self.assertRegex(out, "three.*baz")
def test_project_exclusion_hasnt(self):
"""299: check project exclusion using project.hasnt:<name>
Reported in bug 299
"""
code, out, err = self.t("list project.hasnt:one pro.hasnt:two")
self.assertNotRegex(out, "one.*foo")
self.assertNotRegex(out, "ones.*faz")
self.assertNotRegex(out, "phone.*boo")
self.assertNotRegex(out, "bones.*too")
self.assertNotRegex(out, "two.*bar")
self.assertRegex(out, "three.*baz")
class TestBug555(TestCase):
def setUp(self):
self.t = Task()
def test_log_with_project_segfault(self):
"""555: log with a project causes a segfault
Reported in bug 555
"""
code, out, err = self.t("rc.verbose:new-uuid log description project:p")
self.assertNotIn("Segmentation fault", out)
self.assertNotIn("Segmentation fault", err)
self.assertIn("Logged task", out)
class TestBug605(TestCase):
def setUp(self):
self.t = Task()
def test_delete_task_for_empty_project(self):
"""605: Project correctly reports % completion when empty or all tasks completed
Reported in bug 605
"""
self.t("add One project:p1")
code, out, err = self.t("1 delete", input="y\n")
self.assertIn("is 0% complete", err)
self.t("add Two project:p1")
code, out, err = self.t("2 done")
self.assertIn("is 100% complete", err)
class TestBug835(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Task()
def test_project_hierarchy_filter(self):
"""835: Verify filter on project hierarchy, plus parentheses"""
self.t("add pro:main.subproject one")
code, out, err = self.t("ls")
self.assertIn("main.subproject", out)
code, out, err = self.t("(pro:main.subproject) ls")
self.assertIn("main.subproject", out)
self.assertNotIn("Mismatched parentheses in expression", out)
class TestBug906(TestCase):
def setUp(self):
self.t = Task()
def test_project_hierarchy_filter(self):
"""906: Test project hierarchy filters
Bug 906
"""
self.t("add zero")
self.t("add one pro:a.b")
self.t("add two pro:a")
code, out, err = self.t("pro:a list")
self.assertNotIn("zero", out)
self.assertIn("one", out)
self.assertIn("two", out)
code, out, err = self.t("pro:a.b list")
self.assertNotIn("zero", out)
self.assertIn("one", out)
self.assertNotIn("two", out)
code, out, err = self.t("pro.not:a list")
self.assertIn("zero", out)
self.assertNotIn("one", out)
self.assertNotIn("two", out)
code, out, err = self.t("pro.not:a.b list")
self.assertIn("zero", out)
self.assertNotIn("one", out)
self.assertIn("two", out)
class TestBug856(TestCase):
def setUp(self):
self.t = Task()
def test_project_hierarchy_filter(self):
"""856: Test project.none: works
Bug 856: "task list project.none:" does not work.
"""
self.t("add assigned project:X")
self.t("add floating")
code, out, err = self.t("project: ls")
self.assertIn("floating", out)
self.assertNotIn("assigned", out)
code, out, err = self.t("project:\'\' ls")
self.assertIn("floating", out)
self.assertNotIn("assigned", out)
code, out, err = self.t("project.none: ls")
self.assertIn("floating", out)
self.assertNotIn("assigned", out)
class TestBug1511(TestCase):
def setUp(self):
self.t = Task()
def test_project_hierarchy_filter(self):
"""1511: Test project:one-two can be added and queried
Bug 1511: Project titles not properly parsed if they contain hyphens
"""
self.t("add zero")
self.t("add one project:two-three")
code, out, err = self.t("project:two-three list")
self.assertIn("one", out)
self.assertNotIn("zero", out)
class TestBug1455(TestCase):
def setUp(self):
self.t = Task()
def test_project_hierarchy_filter(self):
"""1455: Test project:school)
Bug 1455: Filter parser does not properly handle parentheses in attributes
"""
self.t("add zero")
self.t("add one project:two)")
code, out, err = self.t("project:two) list")
self.assertIn("one", out)
self.assertNotIn("zero", out)
class TestBug899(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Task()
self.t.config("verbose", "1")
def test_log_project(self):
"""899: Verify task log behaves correctly when logging into a project"""
code, out, err = self.t("add one pro:A")
self.assertRegex(err, " 0% complete \(1 task ")
code, out, err = self.t("add two pro:A")
self.assertRegex(err, " 0% complete \(2 of 2 ")
code, out, err = self.t("1 done")
self.assertRegex(err, " 50% complete \(1 of 2 ")
code, out, err = self.t("log three pro:A")
self.assertRegex(err, " 66% complete \(1 of 3 ")
class TestBug1267(TestCase):
def setUp(self):
self.t = Task()
def test_add_task_no_project_with_default(self):
"""1267: Add a task without a project using direct rc change
"""
project = "MakePudding"
self.t("rc.default.project={0} add proj: 'Add cream'".format(project))
code, out, err = self.t("ls")
self.assertNotIn(project, out)
def test_add_task_no_project_with_default_rcfile(self):
"""1267: Add a task without a project writing to rc file
"""
project = "MakePudding"
self.t.config("default.project", project)
self.t("add proj: 'Add cream'")
code, out, err = self.t("ls")
self.assertNotIn(project, out)
class TestBug1430(TestCase):
def setUp(self):
self.t = Task()
def test_project_names_with_dots(self):
"""1430: Check that filtering works for project names with dots"""
self.t("add foo project:home.garden")
code, out, err = self.t("_get 1.project")
self.assertEqual("home.garden\n", out)
def test_project_names_with_slashes(self):
"""1430: Check that filtering works for project names with slashes"""
self.t("add foo project:home/garden")
code, out, err = self.t("_get 1.project")
self.assertEqual("home/garden\n", out)
class TestBug1617(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Task()
def test_multi_word_project(self):
"""1617: Verify search for multi-word project"""
self.t("add one")
self.t("add two project:'three four'")
code, out, err = self.t(r"project:\'three\ four\' list")
self.assertIn("two", out)
self.assertNotIn("one", out)
class TestBug1627(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Task()
def test_project_eval(self):
"""1627: Verify that a value of 'mon' is not eval'd to 'monday' for a project"""
self.t("add foo project:mon")
code, out, err = self.t("_get 1.project")
self.assertEqual("mon\n", out)
class TestBug1900(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Task()
def test_project_eval(self):
"""1900: Project name can contain dashes"""
self.t("add foo project:doo-bee")
code, out, err = self.t("_get 1.project")
self.assertEqual("doo-bee\n", out)
class TestBug1904(TestCase):
def setUp(self):
"""Executed before each test in the class"""
self.t = Task()
def add_tasks(self):
self.t("add pro:a-b test1")
self.t("add pro:a.b test2")
def validate_order(self, out):
order = ("a",
" b",
"a-b")
lines = out.splitlines(True)
# position where project names start on the lines list
position = 3
for i, proj in enumerate(order):
pos = position + i
self.assertTrue(
lines[pos].startswith(proj),
msg=("Project '{0}' is not in line #{1} or has an unexpected "
"indentation.{2}".format(proj, pos, out))
)
def test_project_eval(self):
"""1904: verify correct order under projects command"""
self.add_tasks()
code, out, err = self.t("projects")
self.validate_order(out)
if __name__ == "__main__":
from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner())
# vim: ai sts=4 et sw=4 ft=python
|