summaryrefslogtreecommitdiff
path: root/test/performance/lib.py
blob: d0727b6009a9e84dd4842cf779160d5cd1d57036 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Contains library functions"""
import os
from git.test.lib import *
import shutil
import tempfile

from git.db import (
						GitCmdObjectDB,
						GitDB
					)

from git import (
	Repo
	)

#{ Invvariants
k_env_git_repo = "GIT_PYTHON_TEST_GIT_REPO_BASE"
#} END invariants


#{ Utilities
def resolve_or_fail(env_var):
	""":return: resolved environment variable or raise EnvironmentError"""
	try:
		return os.environ[env_var]
	except KeyError:
		raise EnvironmentError("Please set the %r envrionment variable and retry" % env_var)
	# END exception handling

#} END utilities


#{ Base Classes 

class TestBigRepoR(TestBase):
	"""TestCase providing access to readonly 'big' repositories using the following 
	member variables:
	
	* gitrorepo
	
	 * Read-Only git repository - actually the repo of git itself
	 
    * puregitrorepo
    
     * As gitrepo, but uses pure python implementation
    """
	 
	#{ Invariants
	head_sha_2k = '235d521da60e4699e5bd59ac658b5b48bd76ddca'
	head_sha_50 = '32347c375250fd470973a5d76185cac718955fd5'
	#} END invariants 
	
	@classmethod
	def setUpAll(cls):
		super(TestBigRepoR, cls).setUpAll()
		repo_path = resolve_or_fail(k_env_git_repo)
		cls.gitrorepo = Repo(repo_path, odbt=GitCmdObjectDB)
		cls.puregitrorepo = Repo(repo_path, odbt=GitDB)


class TestBigRepoRW(TestBigRepoR):
	"""As above, but provides a big repository that we can write to.
	
	Provides ``self.gitrwrepo`` and ``self.puregitrwrepo``"""
	
	@classmethod
	def setUpAll(cls):
		super(TestBigRepoRW, cls).setUpAll()
		dirname = tempfile.mktemp()
		os.mkdir(dirname)
		cls.gitrwrepo = cls.gitrorepo.clone(dirname, shared=True, bare=True, odbt=GitCmdObjectDB)
		cls.puregitrwrepo = Repo(dirname, odbt=GitDB)
	
	@classmethod
	def tearDownAll(cls):
		shutil.rmtree(cls.gitrwrepo.working_dir)
		
#} END base classes