Exemple #1
0
    def setUp(self):
        flags.reset()
        self.adapter_type = 'postgres'

        # create a dbt_project.yml

        base_project_config = {
            'name': 'test',
            'version': '1.0',
            'test-paths': [],
            'source-paths': [self.models],
            'profile': 'test'
        }

        project_config = {}
        project_config.update(base_project_config)
        project_config.update(self.project_config)

        with open("dbt_project.yml", 'w') as f:
            yaml.safe_dump(project_config, f, default_flow_style=True)

        # create profiles

        profile_config = {}
        default_profile_config = self.postgres_profile()
        profile_config.update(default_profile_config)
        profile_config.update(self.profile_config)

        if not os.path.exists(DBT_CONFIG_DIR):
            os.makedirs(DBT_CONFIG_DIR)

        with open(DBT_PROFILES, 'w') as f:
            yaml.safe_dump(profile_config, f, default_flow_style=True)

        target = profile_config.get('test').get('target')

        if target is None:
            target = profile_config.get('test').get('run-target')

        profile = profile_config.get('test').get('outputs').get(target)

        project = Project(project_config, profile_config, DBT_CONFIG_DIR)

        adapter = get_adapter(profile)

        # it's important to use a different connection handle here so
        # we don't look into an incomplete transaction
        adapter.cleanup_connections()
        connection = adapter.acquire_connection(profile, '__test')
        self.handle = connection.get('handle')
        self.adapter_type = profile.get('type')
        self.adapter = adapter
        self._profile = profile
        self._profile_config = profile_config
        self.project = project

        self._drop_schema()
        self._create_schema()
Exemple #2
0
    def setUp(self):
        flags.reset()
        # disable capturing warnings
        logging.captureWarnings(False)
        self._clean_files()

        self.use_profile(self._pick_profile())
        self.use_default_project()
        self.set_packages()
        self.load_config()
Exemple #3
0
    def setUp(self):
        self._created_schemas = set()
        flags.reset()
        template_cache.clear()
        # disable capturing warnings
        logging.captureWarnings(False)
        self._clean_files()

        self.use_profile(self._pick_profile())
        self.use_default_project()
        self.set_packages()
        self.load_config()
Exemple #4
0
    def setUp(self):
        self._created_schemas = set()
        flags.reset()
        template_cache.clear()
        # disable capturing warnings
        logging.captureWarnings(False)
        self._clean_files()

        self.use_profile(self._pick_profile())
        self.use_default_project()
        self.set_packages()
        self.load_config()
Exemple #5
0
    def setUp(self):
        self.dbt_core_install_root = os.path.dirname(dbt.__file__)
        log_manager.reset_handlers()
        self.initial_dir = INITIAL_ROOT
        os.chdir(self.initial_dir)
        # before we go anywhere, collect the initial path info
        self._logs_dir = os.path.join(self.initial_dir, 'logs', self.prefix)
        _really_makedirs(self._logs_dir)
        self.test_original_source_path = _pytest_get_test_root()
        self.test_root_dir = self._generate_test_root_dir()

        os.chdir(self.test_root_dir)
        try:
            self._symlink_test_folders()
        except Exception as exc:
            msg = '\n\t'.join((
                'Failed to symlink test folders!',
                'initial_dir={0.initial_dir}',
                'test_original_source_path={0.test_original_source_path}',
                'test_root_dir={0.test_root_dir}'
            )).format(self)
            logger.exception(msg)

            # if logging isn't set up, I still really want this message.
            print(msg)
            traceback.print_exc()

            raise

        self._created_schemas = set()
        reset_deprecations()
        flags.reset()
        template_cache.clear()

        self.use_profile(self._pick_profile())
        self.use_default_project()
        self.set_packages()
        self.set_selectors()
        self.load_config()
Exemple #6
0
    def setUp(self):
        self.initial_dir = INITIAL_ROOT
        os.chdir(self.initial_dir)
        # before we go anywhere, collect the initial path info
        self._logs_dir = os.path.join(self.initial_dir, 'logs', self.prefix)
        print('initial_dir={}'.format(self.initial_dir))
        _really_makedirs(self._logs_dir)
        self.test_original_source_path = _pytest_get_test_root()
        print('test_original_source_path={}'.format(
            self.test_original_source_path))
        self.test_root_dir = tempfile.mkdtemp(prefix='dbt-int-test-')
        print('test_root_dir={}'.format(self.test_root_dir))
        os.chdir(self.test_root_dir)
        try:
            self._symlink_test_folders()
        except Exception as exc:
            msg = '\n\t'.join(
                ('Failed to symlink test folders!',
                 'initial_dir={0.initial_dir}',
                 'test_original_source_path={0.test_original_source_path}',
                 'test_root_dir={0.test_root_dir}')).format(self)
            logger.exception(msg)

            # if logging isn't set up, I still really want this message.
            print(msg)
            traceback.print_exc()

            raise

        self._created_schemas = set()
        flags.reset()
        template_cache.clear()
        # disable capturing warnings
        logging.captureWarnings(False)

        self.use_profile(self._pick_profile())
        self.use_default_project()
        self.set_packages()
        self.load_config()