##// END OF EJS Templates
core: dropped usage of configobj entirely
super-admin -
r4975:0b11b7dc default
parent child Browse files
Show More
@@ -26,8 +26,7 b' import os'
26 import time
26 import time
27 import tempfile
27 import tempfile
28 import shutil
28 import shutil
29
29 import configparser
30 import configobj
31
30
32 from rhodecode.model.settings import SettingsModel
31 from rhodecode.model.settings import SettingsModel
33 from rhodecode.tests import *
32 from rhodecode.tests import *
@@ -76,17 +75,20 b' class TestINI(object):'
76 self.destroy()
75 self.destroy()
77
76
78 def create(self):
77 def create(self):
79 config = configobj.ConfigObj(
78 parser = configparser.ConfigParser()
80 self.ini_file_path, file_error=True, write_empty_values=True)
79 parser.read(self.ini_file_path)
81
80
82 for data in self.ini_params:
81 for data in self.ini_params:
83 section, ini_params = data.items()[0]
82 section, ini_params = list(data.items())[0]
83
84 for key, val in ini_params.items():
84 for key, val in ini_params.items():
85 config[section][key] = val
85 parser[section][key] = str(val)
86
86 with tempfile.NamedTemporaryFile(
87 with tempfile.NamedTemporaryFile(
88 mode='w',
87 prefix=self.new_path_prefix, suffix='.ini', dir=self._dir,
89 prefix=self.new_path_prefix, suffix='.ini', dir=self._dir,
88 delete=False) as new_ini_file:
90 delete=False) as new_ini_file:
89 config.write(new_ini_file)
91 parser.write(new_ini_file)
90 self.new_path = new_ini_file.name
92 self.new_path = new_ini_file.name
91
93
92 return self.new_path
94 return self.new_path
@@ -24,7 +24,6 b' import time'
24 import tempfile
24 import tempfile
25 import pytest
25 import pytest
26 import subprocess
26 import subprocess
27 import configobj
28 import logging
27 import logging
29 from urllib.request import urlopen
28 from urllib.request import urlopen
30 from urllib.error import URLError
29 from urllib.error import URLError
@@ -45,15 +44,15 b' def get_port(pyramid_config):'
45
44
46 def get_host_url(pyramid_config):
45 def get_host_url(pyramid_config):
47 """Construct the host url using the port in the test configuration."""
46 """Construct the host url using the port in the test configuration."""
48 return '127.0.0.1:%s' % get_port(pyramid_config)
47 port = get_port(pyramid_config)
48 return f'127.0.0.1:{port}'
49
49
50
50
51 def assert_no_running_instance(url):
51 def assert_no_running_instance(url):
52 if is_url_reachable(url):
52 if is_url_reachable(url):
53 print("Hint: Usually this means another instance of server "
53 print(f"Hint: Usually this means another instance of server "
54 "is running in the background at %s." % url)
54 f"is running in the background at {url}.")
55 pytest.fail(
55 pytest.fail(f"Port is not free at {url}, cannot start server at")
56 "Port is not free at %s, cannot start server at" % url)
57
56
58
57
59 class ServerBase(object):
58 class ServerBase(object):
@@ -63,8 +62,10 b' class ServerBase(object):'
63
62
64 def __init__(self, config_file, log_file):
63 def __init__(self, config_file, log_file):
65 self.config_file = config_file
64 self.config_file = config_file
66 config_data = configobj.ConfigObj(config_file)
65 config = configparser.ConfigParser()
67 self._config = config_data['server:main']
66 config.read(config_file)
67
68 self._config = {k: v for k, v in config['server:main'].items()}
68
69
69 self._args = []
70 self._args = []
70 self.log_file = log_file or os.path.join(
71 self.log_file = log_file or os.path.join(
@@ -75,7 +76,7 b' class ServerBase(object):'
75 self.__class__.__name__, config_file))
76 self.__class__.__name__, config_file))
76
77
77 if not os.path.isfile(config_file):
78 if not os.path.isfile(config_file):
78 raise RuntimeError('Failed to get config at {}'.format(config_file))
79 raise RuntimeError(f'Failed to get config at {config_file}')
79
80
80 @property
81 @property
81 def command(self):
82 def command(self):
@@ -102,7 +102,7 b" setup_requirements = ['PasteScript']"
102 install_requirements = _get_requirements(
102 install_requirements = _get_requirements(
103 'requirements.txt', exclude=['setuptools', 'entrypoints'])
103 'requirements.txt', exclude=['setuptools', 'entrypoints'])
104 test_requirements = _get_requirements(
104 test_requirements = _get_requirements(
105 'requirements_test.txt', extras=['configobj'])
105 'requirements_test.txt')
106
106
107
107
108 def get_version():
108 def get_version():
General Comments 0
You need to be logged in to leave comments. Login now