Beispiel #1
0
        return value
    else:
        raise InternalException(
            f'Got an invalid merge_behavior: {merge_behavior}')


def insensitive_patterns(*patterns: str):
    lowercased = []
    for pattern in patterns:
        lowercased.append(''.join('[{}{}]'.format(s.upper(), s.lower())
                                  for s in pattern))
    return '^({})$'.format('|'.join(lowercased))


Severity = NewType('Severity', str)
register_pattern(Severity, insensitive_patterns('warn', 'error'))


class SnapshotStrategy(StrEnum):
    Timestamp = 'timestamp'
    Check = 'check'


class All(StrEnum):
    All = 'all'


@dataclass
class Hook(JsonSchemaMixin, Replaceable):
    sql: str
    transaction: bool = True
Beispiel #2
0
import pytest

from dataclasses import dataclass
from typing import NewType

from hologram import ValidationError, JsonSchemaMixin
from hologram.helpers import register_pattern

Uppercase = NewType("Uppercase", str)
register_pattern(Uppercase, r"[A-Z]+")


@dataclass
class Loud(JsonSchemaMixin):
    shouting: Uppercase
    normal: str


@pytest.fixture
def loud():
    return Loud(shouting="SHOUTING", normal="Normal")


@pytest.fixture
def loud_dict():
    return {"shouting": "SHOUTING", "normal": "Normal"}


@pytest.fixture
def too_quiet():
    return {"shouting": "shhhhh", "normal": "Normal"}
Beispiel #3
0
from dbt.ui import printer
from dbt.helper_types import NoValue

from hologram import JsonSchemaMixin, ValidationError
from hologram.helpers import HyphenatedJsonSchemaMixin, register_pattern, \
    ExtensibleJsonSchemaMixin

from dataclasses import dataclass, field
from typing import Optional, List, Dict, Union, Any, NewType

PIN_PACKAGE_URL = 'https://docs.getdbt.com/docs/package-management#section-specifying-package-versions'  # noqa
DEFAULT_SEND_ANONYMOUS_USAGE_STATS = True
DEFAULT_USE_COLORS = True

Name = NewType('Name', str)
register_pattern(Name, r'^[^\d\W]\w*$')

# this does not support the full semver (does not allow a trailing -fooXYZ) and
# is not restrictive enough for full semver, (allows '1.0'). But it's like
# 'semver lite'.
SemverString = NewType('SemverString', str)
register_pattern(
    SemverString,
    r'^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(\.(?:0|[1-9]\d*))?$',
)


@dataclass
class Quoting(JsonSchemaMixin, Mergeable):
    identifier: Optional[bool]
    schema: Optional[bool]
Beispiel #4
0
import itertools
from dataclasses import dataclass, field
from typing import (Any, ClassVar, Dict, Tuple, Iterable, Optional, NewType,
                    List, Type)
from typing_extensions import Protocol

from hologram import JsonSchemaMixin
from hologram.helpers import (StrEnum, register_pattern,
                              ExtensibleJsonSchemaMixin)

from dbt.contracts.util import Replaceable
from dbt.exceptions import InternalException
from dbt.utils import translate_aliases

Identifier = NewType('Identifier', str)
register_pattern(Identifier, r'^[A-Za-z_][A-Za-z0-9_]+$')


class ConnectionState(StrEnum):
    INIT = 'init'
    OPEN = 'open'
    CLOSED = 'closed'
    FAIL = 'fail'


class ConnectionOpenerProtocol(Protocol):
    @classmethod
    def open(cls, connection: 'Connection') -> Any:
        raise NotImplementedError(f'open() not implemented for {cls.__name__}')