Skip to content

Commit ee91306

Browse files
authored
Merge pull request #293 from AKSW/feature/pytest
Use pytest and setDefaultBranch (master/main)
2 parents 464f9e7 + 7c7a18a commit ee91306

5 files changed

Lines changed: 215 additions & 19 deletions

File tree

poetry.lock

Lines changed: 161 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ uWSGI = "^2.0.20"
1818
[tool.poetry.dev-dependencies]
1919
pylava = "^0.3.0"
2020
coveralls = "^3.3.1"
21+
pytest = "^6.2.5"
22+
pytest-cov = "^3.0.0"
2123

2224
[build-system]
2325
requires = ["poetry-core>=1.0.0"]

quit/core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ def getDefaultBranch(self):
124124
repository_current_head = self.repository.current_head
125125
if repository_current_head:
126126
return repository_current_head
127+
try:
128+
git_config_default_branch = pygit2.Config.get_global_config()['init.defaultBranch']
129+
if git_config_default_branch:
130+
return git_config_default_branch
131+
except KeyError:
132+
pass
127133
return "master"
128134

129135
def rebuild(self):

tests/test_conf.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from glob import glob
55
from os import remove
66
from os.path import join, isdir
7+
import pygit2
78
from pygit2 import init_repository, Repository, clone_repository
89
from pygit2 import GIT_SORT_TOPOLOGICAL, GIT_SORT_REVERSE, Signature
910
from quit.conf import QuitStoreConfiguration, QuitGraphConfiguration
@@ -14,6 +15,10 @@
1415
from tempfile import TemporaryDirectory, NamedTemporaryFile
1516
import rdflib
1617

18+
try:
19+
DEFAULT_BRANCH = pygit2.Config.get_global_config()['init.defaultBranch']
20+
except KeyError:
21+
DEFAULT_BRANCH = 'master'
1722

1823
class TestConfiguration(unittest.TestCase):
1924
ns = 'http://quit.instance/'
@@ -68,8 +73,9 @@ def testExistingRepoGraphFiles(self):
6873
content2 += '<urn:a> <urn:b> <urn:c> .\n'
6974
repoContent = {'http://example.org/': content1, 'http://aksw.org/': content2}
7075
with TemporaryRepositoryFactory().withGraphs(repoContent) as repo:
76+
current_head = repo.head.shorthand
7177
conf = QuitGraphConfiguration(repository=repo)
72-
conf.initgraphconfig('master')
78+
conf.initgraphconfig(current_head)
7379
self.assertEqual(conf.mode, 'graphfiles')
7480

7581
graphs = conf.getgraphs()
@@ -103,8 +109,9 @@ def testExistingRepoWithErroneousGraphFiles(self):
103109
content3 = '<urn:a> <urn:b> <urn:c> .'
104110
repoContent = {'no uri': content1, 'http://aksw.org/': content2, '': content3}
105111
with TemporaryRepositoryFactory().withGraphs(repoContent) as repo:
112+
current_head = repo.head.shorthand
106113
conf = QuitGraphConfiguration(repository=repo)
107-
conf.initgraphconfig('master')
114+
conf.initgraphconfig(current_head)
108115
self.assertEqual(conf.mode, 'graphfiles')
109116

110117
graphs = conf.getgraphs()
@@ -116,6 +123,7 @@ def testExistingRepoWithErroneousGraphFiles(self):
116123

117124
serialization = conf.getserializationoffile('graph_1.nt')
118125
self.assertEqual(serialization, 'nt')
126+
current_head = repo.head.shorthand
119127

120128
gfMap = conf.getgraphurifilemap()
121129

@@ -132,8 +140,9 @@ def testExistingRepoConfigfile(self):
132140
content2 += '<urn:a> <urn:b> <urn:c> .'
133141
repoContent = {'http://example.org/': content1, 'http://aksw.org/': content2}
134142
with TemporaryRepositoryFactory().withGraphs(repoContent, 'configfile') as repo:
143+
current_head = repo.head.shorthand
135144
conf = QuitGraphConfiguration(repository=repo)
136-
conf.initgraphconfig('master')
145+
conf.initgraphconfig(current_head)
137146
self.assertEqual(conf.mode, 'configuration')
138147

139148
graphs = conf.getgraphs()
@@ -164,8 +173,9 @@ def testGraphConfigurationMethods(self):
164173
content2 += '<urn:a> <urn:b> <urn:c> .'
165174
repoContent = {'http://example.org/': content1, 'http://aksw.org/': content2}
166175
with TemporaryRepositoryFactory().withGraphs(repoContent, 'configfile') as repo:
176+
current_head = repo.head.shorthand
167177
conf = QuitGraphConfiguration(repository=repo)
168-
conf.initgraphconfig('master')
178+
conf.initgraphconfig(current_head)
169179

170180
conf.removegraph('http://aksw.org/')
171181

@@ -186,18 +196,20 @@ def testGraphConfigurationMethods(self):
186196

187197
def testGraphConfigurationFailing(self):
188198
with TemporaryRepositoryFactory().withBothConfigurations() as repo:
199+
current_head = repo.head.shorthand
189200
conf = QuitGraphConfiguration(repository=repo)
190-
self.assertRaises(InvalidConfigurationError, conf.initgraphconfig, 'master')
201+
self.assertRaises(InvalidConfigurationError, conf.initgraphconfig, current_head)
191202

192203
def testWrongConfigurationFile(self):
193204
with TemporaryRepositoryFactory().withBothConfigurations() as repo:
205+
current_head = repo.head.shorthand
194206
conf = QuitGraphConfiguration(repository=repo)
195-
self.assertRaises(InvalidConfigurationError, conf.initgraphconfig, 'master')
207+
self.assertRaises(InvalidConfigurationError, conf.initgraphconfig, current_head)
196208

197209
def testNoConfigInformation(self):
198210
with TemporaryRepositoryFactory().withNoConfigInformation() as repo:
199211
conf = QuitGraphConfiguration(repository=repo)
200-
conf.initgraphconfig('master')
212+
conf.initgraphconfig(DEFAULT_BRANCH)
201213
self.assertEqual(conf.mode, 'graphfiles')
202214

203215

0 commit comments

Comments
 (0)