def test_resolve_ranges(self): a_contract = RegistryPackage(package='fishtown-analytics-test/a', version='0.1.2') b_contract = RegistryPackage(package='fishtown-analytics-test/a', version='<0.1.4') a = RegistryUnpinnedPackage.from_contract(a_contract) b = RegistryUnpinnedPackage.from_contract(b_contract) c = a.incorporate(b) self.assertEqual(c.package, 'fishtown-analytics-test/a') self.assertEqual(c.versions, [ VersionSpecifier( build=None, major='0', matcher='=', minor='1', patch='2', prerelease=None, ), VersionSpecifier( build=None, major='0', matcher='<', minor='1', patch='4', prerelease=None, ), ]) c_pinned = c.resolved() self.assertEqual(c_pinned.package, 'fishtown-analytics-test/a') self.assertEqual(c_pinned.version, '0.1.2') self.assertEqual(c_pinned.source_type(), 'hub')
def test_resolve_ok(self): self.index_cached.return_value = [ 'fishtown-analytics-test/a', ] self.get_available_versions.return_value = ['0.1.2', '0.1.3'] self.package_version.return_value = { 'id': 'fishtown-analytics-test/a/0.1.2', 'name': 'a', 'version': '0.1.2', 'packages': [], '_source': { 'blahblah': 'asdfas', }, 'downloads': { 'tarball': 'https://example.com/invalid-url!', 'extra': 'field', }, 'newfield': ['another', 'value'], } a = RegistryPackage(package='fishtown-analytics-test/a', version='0.1.2') b = RegistryPackage(package='fishtown-analytics-test/a', version='0.1.2') c = a.incorporate(b) self.assertEqual(c.version, [ VersionSpecifier({ 'build': None, 'major': '0', 'matcher': '=', 'minor': '1', 'patch': '2', 'prerelease': None, }), VersionSpecifier({ 'build': None, 'major': '0', 'matcher': '=', 'minor': '1', 'patch': '2', 'prerelease': None, }) ]) c.resolve_version() self.assertEqual(c.package, 'fishtown-analytics-test/a') self.assertEqual(c.version, [ VersionSpecifier({ 'build': None, 'major': '0', 'matcher': '=', 'minor': '1', 'patch': '2', 'prerelease': None, }) ]) self.assertEqual(c.source_type(), 'hub')
def create_range(start_version_string, end_version_string): start = UnboundedVersionSpecifier() end = UnboundedVersionSpecifier() if start_version_string is not None: start = VersionSpecifier.from_version_string(start_version_string) if end_version_string is not None: end = VersionSpecifier.from_version_string(end_version_string) return VersionRange(start=start, end=end)
def _sanitize_version(cls, version): version = [ v if isinstance(v, VersionSpecifier) else VersionSpecifier.from_version_string(v) for v in cls.version_to_list(version) ] return version or [UnboundedVersionSpecifier()]
def test_defaults(self): project = dbt.config.Project.from_project_config( self.default_project_data ) self.assertEqual(project.project_name, 'my_test_project') self.assertEqual(project.version, '0.0.1') self.assertEqual(project.profile_name, 'default') self.assertEqual(project.project_root, '/invalid-root-path') self.assertEqual(project.source_paths, ['models']) self.assertEqual(project.macro_paths, ['macros']) self.assertEqual(project.data_paths, ['data']) self.assertEqual(project.test_paths, ['test']) self.assertEqual(project.analysis_paths, []) self.assertEqual(project.docs_paths, ['models']) self.assertEqual(project.target_path, 'target') self.assertEqual(project.clean_targets, ['target']) self.assertEqual(project.log_path, 'logs') self.assertEqual(project.modules_path, 'dbt_modules') self.assertEqual(project.quoting, {}) self.assertEqual(project.models, {}) self.assertEqual(project.on_run_start, []) self.assertEqual(project.on_run_end, []) self.assertEqual(project.archive, []) self.assertEqual(project.seeds, {}) self.assertEqual(project.dbt_version, [VersionSpecifier.from_version_string('>=0.0.0')]) self.assertEqual(project.packages, PackageConfig(packages=[])) # just make sure str() doesn't crash anything, that's always # embarrassing str(project)
def _parse_versions(versions): """Parse multiple versions as read from disk. The versions value may be any one of: - a single version string ('>0.12.1') - a single string specifying multiple comma-separated versions ('>0.11.1,<=0.12.2') - an array of single-version strings (['>0.11.1', '<=0.12.2']) Regardless, this will return a list of VersionSpecifiers """ if isinstance(versions, compat.basestring): versions = versions.split(',') return [VersionSpecifier.from_version_string(v) for v in versions]
def test_init(self): a = RegistryPackage(package='fishtown-analytics-test/a', version='0.1.2') self.assertEqual(a.package, 'fishtown-analytics-test/a') self.assertEqual(a.version, [ VersionSpecifier(build=None, major='0', matcher='=', minor='1', patch='2', prerelease=None) ]) self.assertEqual(a.source_type(), 'hub')
def test_init(self): a_contract = RegistryPackage( package='fishtown-analytics-test/a', version='0.1.2', ) self.assertEqual(a_contract.package, 'fishtown-analytics-test/a') self.assertEqual(a_contract.version, '0.1.2') a = RegistryUnpinnedPackage.from_contract(a_contract) self.assertEqual(a.package, 'fishtown-analytics-test/a') self.assertEqual(a.versions, [ VersionSpecifier(build=None, major='0', matcher='=', minor='1', patch='2', prerelease=None) ]) a_pinned = a.resolved() self.assertEqual(a_contract.package, 'fishtown-analytics-test/a') self.assertEqual(a_contract.version, '0.1.2') self.assertEqual(a_pinned.source_type(), 'hub')
def test_all_overrides(self): self.default_project_data.update({ 'source-paths': ['other-models'], 'macro-paths': ['other-macros'], 'data-paths': ['other-data'], 'test-paths': ['other-test'], 'analysis-paths': ['analysis'], 'docs-paths': ['docs'], 'target-path': 'other-target', 'clean-targets': ['another-target'], 'log-path': 'other-logs', 'modules-path': 'other-dbt_modules', 'quoting': {'identifier': False}, 'models': { 'pre-hook': ['{{ logging.log_model_start_event() }}'], 'post-hook': ['{{ logging.log_model_end_event() }}'], 'my_test_project': { 'first': { 'enabled': False, 'sub': { 'enabled': True, } }, 'second': { 'materialized': 'table', }, }, 'third_party': { 'third': { 'materialized': 'view', }, }, }, 'on-run-start': [ '{{ logging.log_run_start_event() }}', ], 'on-run-end': [ '{{ logging.log_run_end_event() }}', ], 'archive': [ { 'source_schema': 'my_schema', 'target_schema': 'my_other_schema', 'tables': [ { 'source_table': 'my_table', 'target_table': 'my_table_archived', 'updated_at': 'updated_at_field', 'unique_key': 'table_id', }, ], }, ], 'seeds': { 'my_test_project': { 'enabled': True, 'schema': 'seed_data', 'post-hook': 'grant select on {{ this }} to bi_user', }, }, 'require-dbt-version': '>=0.1.0', }) packages = { 'packages': [ { 'local': 'foo', }, { 'git': '[email protected]:fishtown-analytics/dbt-utils.git', 'revision': 'test-rev' }, ], } project = dbt.config.Project.from_project_config( self.default_project_data, packages ) self.assertEqual(project.project_name, 'my_test_project') self.assertEqual(project.version, '0.0.1') self.assertEqual(project.profile_name, 'default') self.assertEqual(project.project_root, '/invalid-root-path') self.assertEqual(project.source_paths, ['other-models']) self.assertEqual(project.macro_paths, ['other-macros']) self.assertEqual(project.data_paths, ['other-data']) self.assertEqual(project.test_paths, ['other-test']) self.assertEqual(project.analysis_paths, ['analysis']) self.assertEqual(project.docs_paths, ['docs']) self.assertEqual(project.target_path, 'other-target') self.assertEqual(project.clean_targets, ['another-target']) self.assertEqual(project.log_path, 'other-logs') self.assertEqual(project.modules_path, 'other-dbt_modules') self.assertEqual(project.quoting, {'identifier': False}) self.assertEqual(project.models, { 'pre-hook': ['{{ logging.log_model_start_event() }}'], 'post-hook': ['{{ logging.log_model_end_event() }}'], 'my_test_project': { 'first': { 'enabled': False, 'sub': { 'enabled': True, } }, 'second': { 'materialized': 'table', }, }, 'third_party': { 'third': { 'materialized': 'view', }, }, }) self.assertEqual(project.on_run_start, ['{{ logging.log_run_start_event() }}']) self.assertEqual(project.on_run_end, ['{{ logging.log_run_end_event() }}']) self.assertEqual(project.archive, [{ 'source_schema': 'my_schema', 'target_schema': 'my_other_schema', 'tables': [ { 'source_table': 'my_table', 'target_table': 'my_table_archived', 'updated_at': 'updated_at_field', 'unique_key': 'table_id', }, ], }]) self.assertEqual(project.seeds, { 'my_test_project': { 'enabled': True, 'schema': 'seed_data', 'post-hook': 'grant select on {{ this }} to bi_user', }, }) self.assertEqual(project.dbt_version, [VersionSpecifier.from_version_string('>=0.1.0')]) self.assertEqual(project.packages, PackageConfig(packages=[ { 'local': 'foo', }, { 'git': '[email protected]:fishtown-analytics/dbt-utils.git', 'revision': 'test-rev' }, ])) str(project) json.dumps(project.to_project_config())