File: uda_orphan.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 (111 lines) | stat: -rwxr-xr-x 4,228 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
#!/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

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

from basetest import Task, TestCase


class TestUDAOrphans(TestCase):
    @classmethod
    def setUpClass(cls):
        """Executed once before any test in the class"""

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

    def test_orphan_handling(self):
        """Verify that orphans are preserved during various operations"""

        self.t("rc.uda.extra.type:string rc.uda.extra.label:Extra add one extra:foo")
        code, out, err = self.t(
            "rc.uda.extra.type:string rc.uda.extra.label:Extra _get 1.extra"
        )
        self.assertEqual("foo\n", out)

        # DOM access for orphans is not supported.
        self.t.runError("_get 1.extra")

        # 'info' should show orphans.
        code, out, err = self.t("1 info")
        self.assertRegex(out, r"\[extra\s+foo\]")

        # 'modify' should not change the orphan
        self.t("1 modify /one/two/")
        code, out, err = self.t("1 info")
        self.assertRegex(out, r"\[extra\s+foo\]")

        # 'export' should include orphans.
        code, out, err = self.t("1 export")
        self.assertIn('"extra":"foo"', out)

    def test_orphan_import(self):
        """Verify importing an orphan succeeds and is visible"""
        json = '{"description":"one","extra":"foo","status":"pending"}'
        code, out, err = self.t("import -", input=json)
        self.assertIn("Imported 1 tasks.", err)

        code, out, err = self.t("export")
        self.assertIn('"extra":"foo"', out)

    def test_orphan_creation_forbidden(self):
        """It should not be possible to create and orphan from the command line"""
        self.t("add one extra:foo")
        code, out, err = self.t("_get 1.description")
        self.assertIn("one extra:foo", out)

    def test_orphan_identification(self):
        """Verify that orphans are identified by +ORPHAN tag and udas command"""

        # Create one task with legitimate orphan attribute and others without
        self.t("rc.uda.extra.type:string rc.uda.extra.label:Extra add one extra:foo")
        self.t("add two no attributes")
        self.t("add three +test ")
        self.t("add four +test depends:3")
        self.t("4 annotate annotation content")

        # Only the first task should be identified as orphan
        code, out, err = self.t("+ORPHAN ids")
        self.assertEqual("1", out.strip())

        # Only the first task should be identified as orphan
        code, out, err = self.t("udas")
        self.assertRegex(out, r"extra\s+1\s+1 Orphan UDA")


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

    unittest.main(testRunner=TAPTestRunner())

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