コード例 #1
0
def test_load_file_error(filename, file_type):
    current_dir = os.path.abspath(os.path.dirname(__file__))
    full_path = os.path.join(current_dir, 'files', filename)
    with pytest.raises(ValueError):
        yapconf.load_file(full_path,
                          file_type=file_type,
                          klazz=ValueError)
コード例 #2
0
ファイル: sources.py プロジェクト: loganasherjones/yapconf
 def get_data(self):
     return yapconf.load_file(
         self.filename,
         file_type="yaml",
         klazz=YapconfSourceError,
         open_kwargs={"encoding": self._encoding},
     )
コード例 #3
0
    def get_data(self):
        if self.data is not None:
            return json.loads(self.data, **self._load_kwargs)

        return yapconf.load_file(self.filename,
                                 file_type='json',
                                 klazz=YapconfSourceError,
                                 load_kwargs=self._load_kwargs)
コード例 #4
0
ファイル: conftest.py プロジェクト: loganasherjones/yapconf
def default_previous_config():
    current_dir = os.path.abspath(os.path.dirname(__file__))
    filename = os.path.join(
        current_dir,
        'files',
        'real_world',
        'default_previous_config.yaml'
    )
    return yapconf.load_file(filename, 'yaml')
コード例 #5
0
ファイル: spec.py プロジェクト: f3n1Xx/yapconf
    def _get_config_if_exists(self, config_file_path, create, file_type):
        if not os.path.isfile(config_file_path) and create:
            return {}
        elif not os.path.isfile(config_file_path):
            raise YapconfLoadError("Error migrating config file {0}. "
                                   "File does not exist. If you would like "
                                   "to create the file, you need to pass "
                                   "the create flag.".format(config_file_path))

        return yapconf.load_file(config_file_path,
                                 file_type=file_type,
                                 klazz=YapconfLoadError)
コード例 #6
0
    def _load_specification(self, specification):
        if isinstance(specification, six.string_types):
            specification = yapconf.load_file(
                specification, file_type=self._file_type, klazz=YapconfSpecError,
            )

        if not isinstance(specification, dict):
            raise YapconfSpecError(
                "Specification must be a dictionary or a filename which "
                "contains a loadable dictionary. Supported file types are "
                "{0}".format(yapconf.FILE_TYPES)
            )

        self._validate_specification(specification)
        return specification
コード例 #7
0
 def _load_config(self, filename):
     return yapconf.load_file(filename,
                              file_type=self._file_type,
                              klazz=YapconfLoadError)
コード例 #8
0
def test_load_file(filename, file_type, expected):
    current_dir = os.path.abspath(os.path.dirname(__file__))
    full_path = os.path.join(current_dir, 'files', filename)
    data = yapconf.load_file(full_path, file_type=file_type)
    assert data == expected
コード例 #9
0
def test_dump_data(tmpdir, data, file_type):
    path = tmpdir.join('test.%s' % file_type)
    filename = os.path.join(path.dirname, path.basename)
    yapconf.dump_data(data, filename, file_type)
    assert data == yapconf.load_file(filename, file_type)
コード例 #10
0
 def get_data(self):
     return yapconf.load_file(self.filename,
                              file_type='yaml',
                              klazz=YapconfSourceError,
                              open_kwargs={'encoding': self._encoding})