~whosdaz/wajig/docfix

« back to all changes in this revision

Viewing changes to test.py

  • Committer: Bazaar Package Importer
  • Author(s): Graham Williams, Tshepang Lekhonkhobe
  • Date: 2010-09-15 17:22:16 UTC
  • Revision ID: james.westby@ubuntu.com-20100915172216-6kv2lnbfnnw11lxo
Tags: 2.0.49
[ Tshepang Lekhonkhobe ]

* UPGRADE: Don't automatically do an "apt-get update" with the backup
  option; the behaviour is not standard, and is not so-damn-fast.

* UPGRADE: Add command line argument for --backup to specify target
  directory.  * Used to be "wajig --backup upgrade BKDIR".  * Now it's
  "wajig --backup=BKDIR upgrade".

* UPGRADE: Proceed to upgrade after using -b|--backup option.

* UPGRADE: Remove the option to install listed packages. This helps
  reduce code complexity.

* CHANGELOG: Now only displays uninstalled entries by default. This
  makes the hacky NEWS command redundant, which is therefore
  removed. (Closes: #424668).

* CHANGELOG: Add -v|--verbose=1 option to display the whole thing. This
  was the default option, but suggestion offered in #424668 is more
  sane.

* CHANGELOG: Add -x|--pager option to allow scrolling. This also implies
  -v|--verbose=1 (see above).

* DIST-UPGRADE: Add -b|--backup=BKDIR option to allow backing up of
  packages before dist-upgrade.

* BUILD: Now uses sudo instead of fakeroot to avoid permission-related.
  build failures for some packages (EG, fakeroot & cdbs). (Closes:
  #464003).

* Fix a parsing bug where "wajig changelog libgtk2.0-0" didn't work.

* Switch to dpkg-source 3.0 (native) format

* RBUILDDEPS: New option allowing one to determine which packages
  build-depends on a particular package. The long form command is
  "reverse-build-depends", else just use "wajig rbuilddeps pkgname".
  (Closes: #335240).

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
import unittest
11
11
from src import perform
12
 
from src import wajig
 
12
from src import util
13
13
 
14
14
 
15
15
class WaJIGTests(unittest.TestCase):
52
52
        self.assertEqual(res, "'TEST1' 'TEST2' ")  # me not happy wit' this
53
53
 
54
54
    # ----
55
 
    # testing wajig.py
56
 
    #
57
 
    # missing:
58
 
    # * wajig_completer()
59
 
    # * wajig_listcommands()
 
55
    # testing util.py
60
56
    # ----
61
57
    def test_wajig_requires_args(self):
62
 
        res = wajig.requires_args("", [1])
 
58
        res = util.requires_args("", [1])
63
59
        self.assertFalse(res)
64
 
        res = wajig.requires_args("", [1, 2])
 
60
        res = util.requires_args("", [1, 2])
65
61
        self.assertTrue(res)
66
62
 
67
63
    def test_wajig_requires_no_args(self):
68
 
        res = wajig.requires_no_args("", [1], test=True)
 
64
        res = util.requires_no_args("", [1], test=True)
69
65
        self.assertTrue(res)
70
 
        res = wajig.requires_no_args("", [1, 2], test=True)
 
66
        res = util.requires_no_args("", [1, 2], test=True)
71
67
        self.assertFalse(res)
72
68
 
73
69
    def test_wajig_requires_opt_arg(self):
74
 
        res = wajig.requires_opt_arg("", [1, 2])
 
70
        res = util.requires_opt_arg("", [1, 2])
75
71
        self.assertTrue(res)
76
 
        res = wajig.requires_opt_arg("", [1, 2, 3])
 
72
        res = util.requires_opt_arg("", [1, 2, 3])
77
73
        self.assertFalse(res)
78
74
 
79
75
    def test_wajig_requires_one_arg(self):
80
 
        res = wajig.requires_one_arg("", [1])
 
76
        res = util.requires_one_arg("", [1])
81
77
        self.assertFalse(res)
82
 
        res = wajig.requires_one_arg("", [1, 2])
 
78
        res = util.requires_one_arg("", [1, 2])
83
79
        self.assertTrue(res)
84
 
        res = wajig.requires_one_arg("", [1, 2, 3])
 
80
        res = util.requires_one_arg("", [1, 2, 3])
85
81
        self.assertFalse(res)
86
82
 
87
83
    def test_wajig_requires_two_args(self):
88
 
        res = wajig.requires_two_args("", [1, 2])
 
84
        res = util.requires_two_args("", [1, 2])
89
85
        self.assertFalse(res)
90
 
        res = wajig.requires_two_args("", [1, 2, 3])
 
86
        res = util.requires_two_args("", [1, 2, 3])
91
87
        self.assertTrue(res)
92
 
        res = wajig.requires_two_args("", [1, 2, 3, 4])
 
88
        res = util.requires_two_args("", [1, 2, 3, 4])
93
89
        self.assertFalse(res)
94
90
 
95
91
    def test_wajig_requires_package(self):
96
 
        res = wajig.requires_package("ls", "/bin/ls", test=True)
 
92
        res = util.requires_package("ls", "/bin/ls", test=True)
97
93
        self.assertTrue(res)
98
 
        res = wajig.requires_package("ls", "TEST", test=True)
 
94
        res = util.requires_package("ls", "TEST", test=True)
99
95
        self.assertFalse(res)
100
96
 
 
97
    def test_wajig_package_exists(self):
 
98
        self.assertTrue(util.package_exists("dpkg", test=True))
 
99
        self.assertFalse(util.package_exists("pkg_does_not_exist", test=True))
 
100
 
 
101
    # ----
 
102
    # testing bash_completion.py
 
103
    #
 
104
    def test_bash_completion(self):
 
105
        bc_ref = """\
 
106
have wajig &&
 
107
_wajig()
 
108
{
 
109
        local cur prev opt
 
110
 
 
111
        COMPREPLY=()
 
112
        cur=${COMP_WORDS[COMP_CWORD]}
 
113
        prev=${COMP_WORDS[COMP_CWORD-1]}
 
114
 
 
115
        if [ "$COMP_CWORD" -ge "2" ]; then
 
116
           COMPREPLY=($( compgen -W "$(apt-cache pkgnames "$cur")" -- $cur ) )
 
117
        elif [[ "$cur" == -* ]]; then
 
118
            COMPREPLY=($( compgen -W '-b --backup -d --debug -h --help  \ 
 
119
                                  -n --noauth -p --pause -x --pager  \ 
 
120
                                  -q --quiet -s --simulate -t --teaching  \ 
 
121
                                  -y --yes -v --verbose' -- $cur ) )
 
122
        else
 
123
            COMPREPLY=($( compgen -W '
 
124
            addcdrom addrepo auto-alts auto-clean auto-download \ 
 
125
            auto-install auto-remove available bug build \ 
 
126
            build-depend changelog clean contents daily-upgrade \ 
 
127
            dependents describe describe-new detail detail-new \ 
 
128
            dist-upgrade docs download download-file \ 
 
129
            editsources extract find-file find-pkg fix-configure \ 
 
130
            fix-install fix-missing force help hold init \ 
 
131
            info install install-file installr installrs \ 
 
132
            installs install integrity large last-update \ 
 
133
            list list-all list-alts list-cache list-commands \ 
 
134
            list-daemons list-files list-hold list-installed \ 
 
135
            list-log list-names list-orphans list-scripts \ 
 
136
            list-section list-sections list-status list-wide \ 
 
137
            local-dist-upgrade local-upgrade madison \ 
 
138
            move new new-upgrades non-free orphans policy \ 
 
139
            purge purge-depend purge-orphans purge-removed \ 
 
140
            rbuilddeps readme recursive reconfigure reinstall \ 
 
141
            reload remove remove-depend remove-file remove-orphans \ 
 
142
            repackage reset restart rpm rpminstall search \ 
 
143
            search-apt setup showdistupgrade showinstall \ 
 
144
            showremove showupgrade sizes snapshot source \ 
 
145
            start status status-search stop tasksel toupgrade \ 
 
146
            unhold update update-alts update-pci-ids \ 
 
147
            update-usb-ids upgrade verify version versions \ 
 
148
            whatis whichpkg' -- $cur ) )
 
149
        fi
 
150
}
 
151
complete -F _wajig $default wajig""".split("\n")
 
152
 
 
153
        import os, difflib
 
154
 
 
155
        wc = "wajig.completion"
 
156
        os.system("python bash_completion.py")
 
157
        bc_gen = list()
 
158
 
 
159
        with open(wc) as f:
 
160
            for line in f:
 
161
                bc_gen.append(line[:-1])  # remove trailing "\n" char
 
162
 
 
163
        if (bc_ref != bc_gen):
 
164
            diff = difflib.unified_diff(bc_ref, bc_gen, fromfile="reference", \
 
165
                                        tofile="generated", lineterm="")
 
166
            for line in diff:
 
167
                print line
 
168
 
 
169
        self.assertEqual(bc_ref, bc_gen, "Check diff above.")
 
170
        if os.path.exists(wc):
 
171
            os.unlink(wc)
 
172
 
 
173
 
101
174
if __name__ == '__main__':
102
175
    unittest.main()