Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_valid_ordering(self, monkeypatch):
# disable schema validation for this test:
monkeypatch.setattr(includehandler, 'CONFIGSCHEMA', {})
header = self.__class__.header
data = {'x.yml':
header.format(''' includes: ["y.yml", "z.yml"]
v: {v1: x, v2: x}'''),
os.path.abspath('y.yml'):
header.format(''' includes: ["z.yml"]
v: {v2: y, v3: y, v5: y}'''),
os.path.abspath('z.yml'): header.format('''
v: {v3: z, v4: z}''')}
with patch_open(includehandler, dictionary=data):
ginc = includehandler.IncludeHandler(['x.yml'])
config, _ = ginc.get_config()
keys = list(config['v'].keys())
index = {keys[i]: i for i in range(len(keys))}
# Check for vars in z.yml:
assert index['v3'] < index['v1']
assert index['v3'] < index['v2']
assert index['v3'] < index['v5']
assert index['v4'] < index['v1']
assert index['v4'] < index['v2']
assert index['v4'] < index['v5']
# Check for vars in y.yml:
assert index['v2'] < index['v1']
assert index['v3'] < index['v1']
assert index['v5'] < index['v1']
def util_include_content(self, testvector, monkeypatch):
# disable schema validation for these tests:
monkeypatch.setattr(includehandler, 'CONFIGSCHEMA', {})
for test in testvector:
with patch_open(includehandler, dictionary=test['fdict']):
ginc = includehandler.IncludeHandler(['x.yml'])
config, missing = ginc.get_config(repos=test['rdict'])
# Remove header, because we dont want to compare it:
config.pop('header')
assert test['conf'] == config
assert test['rmiss'] == missing
self._config = {}
self.filenames = []
for configfile in filename.split(':'):
configfile = os.path.abspath(configfile)
repo_path = Repo.get_root_path(os.path.dirname(configfile),
fallback=False)
if self.filenames == []:
common_path = repo_path
elif repo_path != common_path:
raise IncludeException('All concatenated config files must '
'belong to the same repository or all '
'must be outside of versioning control')
self.filenames.append(configfile)
self.handler = IncludeHandler(self.filenames)
self.repo_dict = self._get_repo_dict()