Beispiel #1
0
 def test_gitprepush(self):
     revs = (('refs/heads/master', 'a'*40, 'refs/heads/foreign', 'b'*40),
             ('refs/heads/master', 'a'*40, 'refs/heads/foreign', '0'*40))
     dummyinput = [' '.join(r)+'\n' for r in revs]
     hooklib_input.readlines = MagicMock(return_value=dummyinput)
     revdata = inputparser.fromphase('pre-push').parse()
     assert(revdata.revstobepushed == revs)
Beispiel #2
0
 def test_git_update(self):
     os.environ["GIT_DIR"] = "."
     sys.argv = ["program.name", "a"*40, "0"*40, "1"*40]
     revdata = inputparser.fromphase('update').parse()
     assert(revdata.refname == "a"*40)
     assert(revdata.old == "0"*40)
     assert(revdata.new == "1"*40)
Beispiel #3
0
 def test_gitpostreceive(self):
     revs = (('a'*40, 'b'*40, 'refs/heads/master'),
             ('c'*40, 'd'*40, 'refs/heads/stable'))
     dummyinput = [' '.join(r)+'\n' for r in revs]
     hooklib_input.readlines = MagicMock(return_value=dummyinput)
     revdata = inputparser.fromphase('post-receive').parse()
     assert(revdata.receivedrevs == revs)
Beispiel #4
0
 def test_gitprerebasecurrentbranch(self):
     sys.argv = ['program.name', 'upstream']
     parser = inputparser.fromphase('pre-rebase')
     assert(isinstance(parser, gitprerebaseinputparser))
     revdata = parser.parse()
     assert(revdata.upstream == 'upstream')
     assert(revdata.rebased is None)
Beispiel #5
0
    def test_gitpreparecommitmsg(self):
        # possible options
        # message, template, merge, squash, commit
        cases = (
                    # valid arg, list of args
                    (True, 'commitlogmsg', 'message'),
                    (False, 'commitlogmsg', 'message', 'a'*40),
                    (True, 'commitlogmsg', 'template'),
                    (False, 'commitlogmsg', 'template', 'a'*40),
                    (True, 'commitlogmsg', 'merge'),
                    (False, 'commitlogmsg', 'merge', 'a'*40),
                    (True, 'commitlogmsg', 'squash'),
                    (False, 'commitlogmsg', 'squash', 'a'*40),
                    (False, 'commitlogmsg', 'commit'),
                    (True, 'commitlogmsg', 'commit', 'a'*40),
                    (False, 'commitlogmsg', 'illegal'),
                )

        for case in cases:
            valid = case[0]
            args = case[1:]
            sys.argv = ['program.name'] + list(args)
            parser = inputparser.fromphase('prepare-commit-msg')
            assert(isinstance(parser, gitpreparecommitmsginputparser))
            if valid:
                parser.parse()  # not exception
            else:
                with self.assertRaises(ValueError):
                    parser.parse()
Beispiel #6
0
 def test_gitpreautogc(self):
     parser = inputparser.fromphase('pre-auto-gc')
     assert(isinstance(parser, gitpreautogcinputparser))
Beispiel #7
0
 def test_gitpostcommit(self):
     parser = inputparser.fromphase('post-commit')
     assert(isinstance(parser, gitpostcommitinputparser))
Beispiel #8
0
 def test_gitcommitmsg(self):
     sys.argv = ['program.name', 'messagefile']
     revdata = inputparser.fromphase('commit-msg').parse()
     assert(revdata.messagefile == 'messagefile')
Beispiel #9
0
 def test_hg_postupdate(self):
     os.environ["HG_NODE"] = "."
     with self.assertRaises(NotImplementedError):
         revdata = inputparser.fromphase('post-update')
Beispiel #10
0
 def test_gitpostapplypatch(self):
     parser = inputparser.fromphase('post-applypatch')
     assert(isinstance(parser, gitpostapplypatchinputparser))
     assert(isinstance(parser.parse(), gitinforesolver))
Beispiel #11
0
 def test_gitapplypatchmsg(self):
     sys.argv = ['program.name', 'messagefile']
     revdata = inputparser.fromphase('applypatch-msg').parse()
     assert(revdata.messagefile == 'messagefile')
Beispiel #12
0
 def test_unknown_hookname(self):
     with self.assertRaises(NotImplementedError):
         revdata = inputparser.fromphase('unknown-phase')
Beispiel #13
0
 def test_hg_precommit(self):
     os.environ["HG_NODE"] = "."
     with self.assertRaises(NotImplementedError):
         revdata = inputparser.fromphase('pre-commit')
Beispiel #14
0
 def test_git_precommit(self):
     os.environ["GIT_DIR"] = "."
     sys.argv = ["program.name"]
     revdata = inputparser.fromphase('pre-commit').parse()
     assert(isinstance(revdata, gitinforesolver))
Beispiel #15
0
 def test_hg_update(self):
     os.environ["HG_NODE"] = "a"*40
     revdata = inputparser.fromphase('update').parse()
     assert(revdata.revs == ["a"*40])
Beispiel #16
0
 def __init__(self, phase=None, phases=None):
     self.runlist = []
     if phases is not None:
         self.revdata = inputparser.fromphases(phases).parse()
     else:
         self.revdata = inputparser.fromphase(phase).parse()
Beispiel #17
0
 def __init__(self, phase=None, phases=None):
     self.runlist = []
     if phases is not None:
         self.revdata = inputparser.fromphases(phases).parse()
     else:
         self.revdata = inputparser.fromphase(phase).parse()
Beispiel #18
0
 def test_git_postupdate(self):
     os.environ["GIT_DIR"] = "."
     sys.argv = ["program.name", "a"*40]
     revdata = inputparser.fromphase('post-update').parse()
     assert(revdata.revs == ["a"*40])