Example #1
0
    def from_file_or_path(self, loadable: Union[Path, str,
                                                TextIO]) -> Configuration:
        """rips through a configuration and returns a configuration object."""
        logger.debug('loading configuration...')
        loaded = self._get_dict_from_anything(loadable, REPLICA_JSON_SCHEMA)
        logger.debug('Done loading.')

        # we need the source adapter first to case-correct everything else
        self._set_default(loaded, 'preserve_case', DEFAULT_PRESERVE_CASE)
        self.preserve_case = loaded['preserve_case']
        source_adapter_profile = self._build_adapter_profile('source', loaded)
        self.default_case = source_adapter_profile.adapter.DEFAULT_CASE

        def case(val: str) -> str:
            return self.case(val)

        # make sure no empty sections
        try:
            [loaded[section].keys() for section in (
                'source',
                'target',
            )]
        except TypeError as err:
            raise KeyError(
                f'missing config section or section is none: {err}.')

        # set defaults
        for attr in (
                'short_description',
                'long_description',
        ):
            self._set_default(loaded, attr)
        self._set_default(loaded, 'threads', DEFAULT_THREAD_COUNT)
        self._set_default(loaded['source'], 'include_outliers', False)
        self._set_default(loaded['source'], 'max_number_of_outliers',
                          DEFAULT_MAX_NUMBER_OF_OUTLIERS)

        try:
            replica_base = (loaded['name'], loaded['version'],
                            loaded['credpath'], loaded['short_description'],
                            loaded['long_description'], loaded['threads'],
                            self.preserve_case, source_adapter_profile,
                            self._build_target(loaded),
                            loaded['source']['include_outliers'],
                            get_sampling_from_partial(
                                loaded['source']['sampling']),
                            loaded['source']['max_number_of_outliers'])

            general_relations = MatchPattern([
                MatchPattern.DatabasePattern(case(database['pattern']), [
                    MatchPattern.SchemaPattern(case(schema['pattern']), [
                        MatchPattern.RelationPattern(case(relation))
                        for relation in schema['relations']
                    ]) for schema in database['schemas']
                ]) for database in loaded['source']['general_relations']
                ['databases']
            ])

            specified_relations = self._build_specified_relations(
Example #2
0
 def sampling_or_none(rel):
     if rel.get('sampling'):
         return get_sampling_from_partial(rel['sampling'])
     return None
def test_finds_default():
    assert isinstance(get_sampling_from_partial('default'), DefaultSampling)