Ejemplo n.º 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)
Ejemplo n.º 2
0
 def get_data(self):
     return yapconf.load_file(
         self.filename,
         file_type="yaml",
         klazz=YapconfSourceError,
         open_kwargs={"encoding": self._encoding},
     )
Ejemplo n.º 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)
Ejemplo n.º 4
0
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')
Ejemplo n.º 5
0
    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)
Ejemplo n.º 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
Ejemplo n.º 7
0
 def _load_config(self, filename):
     return yapconf.load_file(filename,
                              file_type=self._file_type,
                              klazz=YapconfLoadError)
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 10
0
 def get_data(self):
     return yapconf.load_file(self.filename,
                              file_type='yaml',
                              klazz=YapconfSourceError,
                              open_kwargs={'encoding': self._encoding})