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()
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")
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))
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'] })
def test_git_diff(self): repo = gamerepo.GitCmd('mock-data2') repo.do_diff('') self.assertEqual( repo.fullDiff, """[0m================================================================= [31m--- old file: game.json in commit 21b4f39 [32m+++ new file: game.json in unstaged changes [0m }, [0m "player":{ [0m "filename":"alive", [31m- "player":"alive" [0m[32m+ "player":"player" [0m[0m }, [0m "rooms":{ [0m "filename":"alive", """) repo.do_diff('cached') self.assertEqual( repo.fullDiff, """[0m================================================================= [31m--- old file: game.json in commit 21b4f39 [32m+++ new file: game.json in staged changes [0m "alive":true, [0m "inventory":{ [0m "filename":"alive", [31m- "player":"alive" [0m[32m+ "player":"player" [0m[0m }, [0m "player":{ [0m "filename":"alive", [0m "west":"Impressive Caverns" [0m } [0m } [31m-}[0m[0m> \ No newline at end of file [32m+} [0m""") repo.do_diff('HEAD') self.assertEqual( repo.fullDiff, """[0m================================================================= [31m--- old file: game.json in commit 21b4f39 [32m+++ new file: game.json in working directory [0m "alive":true, [0m "inventory":{ [0m "filename":"alive", [31m- "player":"alive" [0m[32m+ "player":"player" [0m[0m }, [0m "player":{ [0m "filename":"alive", [31m- "player":"alive" [0m[32m+ "player":"player" [0m[0m }, [0m "rooms":{ [0m "filename":"alive", [0m "west":"Impressive Caverns" [0m } [0m } [31m-}[0m[0m> \ No newline at end of file [32m+} [0m""") repo.do_diff('staged HEAD~1') self.assertEqual( repo.fullDiff, """[0m================================================================= [31m--- characters/alive.jsondoes not exist in commit a7c0de9 [32m+++ new file: characters/alive.json in staged changes [32m+{ [0m[32m+ "alive":true [0m[32m+} [0m[0m================================================================= [31m--- characters/relationship.jsondoes not exist in commit a7c0de9 [32m+++ new file: characters/relationship.json in staged changes [32m+{ [0m[32m+ "knows_player": false, [0m[32m+ "aware_of_presence": false, [0m[32m+ "hostility_level": 4 [0m[32m+} [0m[0m================================================================= [31m--- characters/status.jsondoes not exist in commit a7c0de9 [32m+++ new file: characters/status.json in staged changes [32m+{ [0m[32m+ "asleep":true [0m[32m+} [0m[0m================================================================= [31m--- old file: game.json in commit a7c0de9 [32m+++ new file: game.json in staged changes [0m "alive":true, [0m "inventory":{ [0m "filename":"alive", [31m- "player":"alive" [0m[32m+ "player":"player" [0m[0m }, [0m "player":{ [0m "filename":"alive", [0m "west":"Impressive Caverns" [0m } [0m } [31m-}[0m[0m> \ No newline at end of file [32m+} [0m""") repo.do_diff('HEAD~1 HEAD') self.assertEqual( repo.fullDiff, """[0m================================================================= [31m--- characters/alive.jsondoes not exist in commit a7c0de9 [32m+++ new file: characters/alive.json in commit 21b4f39 [32m+{ [0m[32m+ "alive":true [0m[32m+} [0m[0m================================================================= [31m--- characters/relationship.jsondoes not exist in commit a7c0de9 [32m+++ new file: characters/relationship.json in commit 21b4f39 [32m+{ [0m[32m+ "knows_player": false, [0m[32m+ "aware_of_presence": false, [0m[32m+ "hostility_level": 4 [0m[32m+} [0m[0m================================================================= [31m--- characters/status.jsondoes not exist in commit a7c0de9 [32m+++ new file: characters/status.json in commit 21b4f39 [32m+{ [0m[32m+ "asleep":true [0m[32m+} [0m""")
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