##// END OF EJS Templates
release: updated pip2nix output for 4.11.4
release: updated pip2nix output for 4.11.4

File last commit:

r352:b25f7b7c default
r389:6cf21b14 stable
Show More
fixture.py
71 lines | 2.5 KiB | text/x-python | PythonLexer
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 # RhodeCode VCSServer provides access to different vcs backends via network.
core: udpate copyright string to 2018
r352 # Copyright (C) 2014-2018 RhodeCode GmbH
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 #
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import os
import shutil
import tempfile
import configobj
tests: refactor TestINI to different name so it doesn't confuse pytest.
r131 class ContextINI(object):
packaging: moved tests into the main library itself. This is consistent with how our other projects do it.
r130 """
Allows to create a new test.ini file as a copy of existing one with edited
data. If existing file is not present, it creates a new one. Example usage::
with TestINI('test.ini', [{'section': {'key': 'val'}}]) as new_test_ini_path:
print 'vcsserver --config=%s' % new_test_ini
"""
def __init__(self, ini_file_path, ini_params, new_file_prefix=None,
destroy=True):
self.ini_file_path = ini_file_path
self.ini_params = ini_params
self.new_path = None
self.new_path_prefix = new_file_prefix or 'test'
self.destroy = destroy
def __enter__(self):
_, pref = tempfile.mkstemp()
loc = tempfile.gettempdir()
self.new_path = os.path.join(loc, '{}_{}_{}'.format(
pref, self.new_path_prefix, self.ini_file_path))
# copy ini file and modify according to the params, if we re-use a file
if os.path.isfile(self.ini_file_path):
shutil.copy(self.ini_file_path, self.new_path)
else:
# create new dump file for configObj to write to.
with open(self.new_path, 'wb'):
pass
config = configobj.ConfigObj(
self.new_path, file_error=True, write_empty_values=True)
for data in self.ini_params:
section, ini_params = data.items()[0]
key, val = ini_params.items()[0]
if section not in config:
config[section] = {}
config[section][key] = val
config.write()
return self.new_path
def __exit__(self, exc_type, exc_val, exc_tb):
if self.destroy:
os.remove(self.new_path)