forked from andrewmcwattersandco/git-fetch-file
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_git_fetch_file.py
More file actions
57 lines (46 loc) · 2.01 KB
/
Copy pathtest_git_fetch_file.py
File metadata and controls
57 lines (46 loc) · 2.01 KB
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
import unittest
import subprocess
import tempfile
import os
import shutil
import configparser
class TestArgumentParser(unittest.TestCase):
def test_argparse_argumentparser(self):
"""
Test for `argparse.ArgumentParser`.
"""
script_path = subprocess.check_output(
["git", "config", "alias.fetch-file"], text=True
).strip()
if script_path.startswith("!python3 "):
script_path = script_path[len("!python3 "):]
with open(script_path, "r") as f:
source = f.read()
self.assertIn("argparse.ArgumentParser", source, "failed to find argparse.ArgumentParser")
class TestGitRepository(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.oldpwd = os.getcwd()
os.chdir(self.tmpdir)
subprocess.run(["git", "init"], check=True)
subprocess.run(["git", "config", "user.name", "Test User"], check=True)
subprocess.run(["git", "config", "user.email", "test@example.com"], check=True)
def tearDown(self):
shutil.rmtree(self.tmpdir)
os.chdir(self.oldpwd)
class TestAdd(TestGitRepository):
def test_add(self):
"""Test `git fetch-file add <repository> <path>`."""
subprocess.run(["git", "fetch-file", "add", "https://github.com/octocat/Hello-World.git", "README"], check=True)
config = configparser.ConfigParser()
config.read(".git-remote-files")
section = 'file "README" from "https://github.com/octocat/Hello-World.git"'
self.assertIn(section, config.sections(), "section not found in .git-remote-files")
class TestPull(TestGitRepository):
def test_pull(self):
"""Test `git fetch-file pull`."""
subprocess.run(["git", "fetch-file", "add", "https://github.com/octocat/Hello-World.git", "README"], check=True)
subprocess.run(["git", "fetch-file", "pull"], check=True)
self.assertTrue(os.path.exists("README"), "README not found after pull")
if __name__ == "__main__":
unittest.main()