コード例 #1
0
    def test_statusparsing1(self):
        """ Test statusParse Checking Active Changes """
        self.reset_repo()
        repo = pygit2.Repository('mock-data/.git')

        status = repo.status()
        self.assertEqual(status, {})

        git = gamerepo.GitCmd('mock-data')

        with open(os.path.join(repo.workdir, 'game.json'), 'a') as f:
            f.write('#comment')
        repo.index.add('game.json')
        status = repo.status()
        parsed = git.statusParse('game.json', status['game.json'])
        self.assertEqual(parsed, {
            'name': 'game.json',
            'status': ['Staged File Changes']
        })

        with open(os.path.join(repo.workdir, 'game.json'), 'a') as f:
            f.write('#comment')
        status = repo.status()
        parsed = git.statusParse('game.json', status['game.json'])
        self.assertEqual(
            parsed, {
                'name': 'game.json',
                'status': [
                    'Unstaged File Changes',
                    'Staged File Changes',
                ]
            })

        self.reset_repo()
コード例 #2
0
    def test_revparsing(self):
        git = gamerepo.GitCmd('mock-data')
        rev1 = git.revparse('HEAD~2')
        rev2 = git.revparse('revparse')
        rev3 = git.revparse('test')
        rev5 = git.revparse('a7c0d')

        self.assertEqual(rev1.hex[:7], '21b4f39')
        self.assertEqual(rev2.hex[:7], '21b4f39')
        self.assertEqual(rev3.hex[:7], '775c873')
        self.assertEqual(rev5.hex[:7], 'a7c0de9')

        with self.assertRaises(ValueError) as context1:
            git.revparse('0df')

        with self.assertRaises(ValueError) as context2:
            git.revparse('eec655')

        with self.assertRaises(ValueError) as context3:
            git.revparse('fecfda')

        with self.assertRaises(ValueError) as context4:
            git.revparse('notabranch')

        self.assertEqual(str(context1.exception),
                         '0df: ambiguous lookup - OID prefix is too short')
        self.assertEqual(str(context2.exception), 'Object is not a commit.')
        self.assertEqual(str(context3.exception), 'Object is not a commit.')
        self.assertEqual(str(context4.exception),
                         "Value 'notabranch' does not refer to a git commit")
コード例 #3
0
    def test_file_check(self):

        fileName1 = os.pardir + os.sep
        fileName2 = "mock-data"
        fileName3 = "fileisnthere.cxx"
        GitCmd = gamerepo.GitCmd('mock-data')
        self.assertFalse(GitCmd.fileIsValid(fileName1))
        self.assertTrue(GitCmd.fileIsValid(fileName2))
        self.assertFalse(GitCmd.fileIsValid(fileName3))
コード例 #4
0
 def test_statusparsing2(self):
     """ Test statusParse Theoretical States """
     git = gamerepo.GitCmd('mock-data')
     self.assertEqual(
         git.statusParse('staged_modified', 258), {
             'name': 'staged_modified',
             'status': ['Unstaged File Changes', 'Staged File Changes']
         })
     self.assertEqual(git.statusParse('ignored', 16384), {
         'name': 'ignored',
         'status': ['Ignored']
     })
     self.assertEqual(
         git.statusParse('wtdeleted_staged', 514), {
             'name': 'wtdeleted_staged',
             'status': ['Unstaged File Deletion', 'Staged File Changes']
         })
コード例 #5
0
    def test_git_diff(self):
        repo = gamerepo.GitCmd('mock-data2')

        repo.do_diff('')
        self.assertEqual(
            repo.fullDiff,
            """=================================================================
--- old file: game.json in commit 21b4f39
+++ new file: game.json in unstaged changes

     },
     "player":{
         "filename":"alive",
-        "player":"alive"
+        "player":"player"
     },
     "rooms":{
         "filename":"alive",
""")

        repo.do_diff('cached')
        self.assertEqual(
            repo.fullDiff,
            """=================================================================
--- old file: game.json in commit 21b4f39
+++ new file: game.json in staged changes

     "alive":true,
     "inventory":{
         "filename":"alive",
-        "player":"alive"
+        "player":"player"
     },
     "player":{
         "filename":"alive",

             "west":"Impressive Caverns"
         }
     }
-}>
\ No newline at end of file
+}
""")

        repo.do_diff('HEAD')
        self.assertEqual(
            repo.fullDiff,
            """=================================================================
--- old file: game.json in commit 21b4f39
+++ new file: game.json in working directory

     "alive":true,
     "inventory":{
         "filename":"alive",
-        "player":"alive"
+        "player":"player"
     },
     "player":{
         "filename":"alive",
-        "player":"alive"
+        "player":"player"
     },
     "rooms":{
         "filename":"alive",

             "west":"Impressive Caverns"
         }
     }
-}>
\ No newline at end of file
+}
""")

        repo.do_diff('staged HEAD~1')
        self.assertEqual(
            repo.fullDiff,
            """=================================================================
--- characters/alive.jsondoes not exist in commit a7c0de9
+++ new file: characters/alive.json in staged changes

+{
+    "alive":true
+}
=================================================================
--- characters/relationship.jsondoes not exist in commit a7c0de9
+++ new file: characters/relationship.json in staged changes

+{
+    "knows_player": false,
+    "aware_of_presence": false,
+    "hostility_level": 4
+}
=================================================================
--- characters/status.jsondoes not exist in commit a7c0de9
+++ new file: characters/status.json in staged changes

+{
+    "asleep":true
+}
=================================================================
--- old file: game.json in commit a7c0de9
+++ new file: game.json in staged changes

     "alive":true,
     "inventory":{
         "filename":"alive",
-        "player":"alive"
+        "player":"player"
     },
     "player":{
         "filename":"alive",

             "west":"Impressive Caverns"
         }
     }
-}>
\ No newline at end of file
+}
""")

        repo.do_diff('HEAD~1 HEAD')
        self.assertEqual(
            repo.fullDiff,
            """=================================================================
--- characters/alive.jsondoes not exist in commit a7c0de9
+++ new file: characters/alive.json in commit 21b4f39

+{
+    "alive":true
+}
=================================================================
--- characters/relationship.jsondoes not exist in commit a7c0de9
+++ new file: characters/relationship.json in commit 21b4f39

+{
+    "knows_player": false,
+    "aware_of_presence": false,
+    "hostility_level": 4
+}
=================================================================
--- characters/status.jsondoes not exist in commit a7c0de9
+++ new file: characters/status.json in commit 21b4f39

+{
+    "asleep":true
+}
""")
コード例 #6
0
aliveJson = recordable.Recordable('saved-game', 'alive')
gameIntro = """    Welcome to Git Crystals!')
    ========================')

    Type "help" for commands.'
    Press Ctrl-C to Quit at Any Time
"""
gitIntro = """     Welcome to Git Crystals!
    ========================')
    You are dead. Git Crystals
    is playing in Git Mode.
    Press Ctrl-C to Quit at Any Time
"""

while playing:
    if aliveJson.data['alive'] == True:
        game = gitgame.GitGameCmd('saved-game')
        print(gameIntro)
        print(game.displayPlayerLocation(game.map))
        game.cmdloop()
        aliveJson.load()
    else:
        game = gamerepo.GitCmd('saved-game')
        print(gitIntro)
        game.cmdloop()
        aliveJson.load()

    gameContinue = input('Continue Y/N?')
    if gameContinue.lower() == 'n':
        break