test options, avoid side effects

This makes tests in PR#692 to pass
This commit is contained in:
J. David Ibáñez 2017-03-22 13:38:11 +01:00
parent 819cbff552
commit d622e87654

View File

@ -44,27 +44,37 @@ from . import utils
class OptionsTest(utils.NoRepoTestCase): class OptionsTest(utils.NoRepoTestCase):
def __option(self, getter, setter, value):
old_value = option(getter)
option(setter, value)
self.assertEqual(value, option(getter))
# Reset to avoid side effects in later tests
option(setter, old_value)
def __proxy(self, name, value):
old_value = getattr(pygit2.settings, name)
setattr(pygit2.settings, name, value)
self.assertEqual(value, getattr(pygit2.settings, name))
# Reset to avoid side effects in later tests
setattr(pygit2.settings, name, old_value)
def test_mwindow_size(self): def test_mwindow_size(self):
new_size = 200 * 1024 self.__option(
option(GIT_OPT_SET_MWINDOW_SIZE, new_size) GIT_OPT_GET_MWINDOW_SIZE,
self.assertEqual(new_size, option(GIT_OPT_GET_MWINDOW_SIZE)) GIT_OPT_SET_MWINDOW_SIZE,
200 * 1024)
def test_mwindow_size_proxy(self): def test_mwindow_size_proxy(self):
new_size = 300 * 1024 self.__proxy('mwindow_size', 300 * 1024)
pygit2.settings.mwindow_size = new_size
self.assertEqual(new_size, pygit2.settings.mwindow_size) def test_mwindow_mapped_limit_200(self):
self.__option(
GIT_OPT_GET_MWINDOW_MAPPED_LIMIT,
GIT_OPT_SET_MWINDOW_MAPPED_LIMIT,
200 * 1024)
def test_mwindow_mapped_limit(self): def test_mwindow_mapped_limit_300(self):
new_limit = 200 * 1024 self.__proxy('mwindow_mapped_limit', 300 * 1024)
option(GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, new_limit)
self.assertEqual(new_limit, option(GIT_OPT_GET_MWINDOW_MAPPED_LIMIT))
def test_mwindow_mapped_limit(self):
new_limit = 300 * 1024
pygit2.settings.mwindow_mapped_limit = new_limit
self.assertEqual(new_limit, pygit2.settings.mwindow_mapped_limit)
def test_cache_object_limit(self): def test_cache_object_limit(self):
new_limit = 2 * 1024 new_limit = 2 * 1024