예제 #1
0
def test_comparison():
    versions = [
        "1.0.0-alpha",
        "1.0.0-alpha.1",
        "1.0.0-beta.2",
        "1.0.0-beta.11",
        "1.0.0-rc.1",
        "1.0.0-rc.1+build.1",
        "1.0.0",
        "1.0.0+0.3.7",
        "1.3.7+build",
        "1.3.7+build.2.b8f12d7",
        "1.3.7+build.11.e0f985a",
        "2.0.0",
        "2.1.0",
        "2.2.0",
        "2.11.0",
        "2.11.1",
    ]

    for i in range(len(versions)):
        for j in range(len(versions)):
            a = Version.parse(versions[i])
            b = Version.parse(versions[j])

            assert (a < b) == (i < j)
            assert (a > b) == (i > j)
            assert (a <= b) == (i <= j)
            assert (a >= b) == (i >= j)
            assert (a == b) == (i == j)
            assert (a != b) == (i != j)
예제 #2
0
def test_allows_all():
    v = Version.parse("1.2.3")

    assert v.allows_all(v)
    assert not v.allows_all(Version.parse("0.0.3"))
    assert not v.allows_all(
        VersionRange(Version.parse("1.1.4"), Version.parse("1.2.4")))
    assert not v.allows_all(VersionRange())
    assert v.allows_all(EmptyConstraint())
예제 #3
0
def known_materialize_versions() -> List[Version]:
    """Returns all known Materialize versions.

    The list is returned in version order with newest versions first.
    """
    config = toml.load(ROOT / "doc" / "user" / "config.toml")
    return [Version.parse(v["name"].lstrip("v")) for v in config["params"]["versions"]]
예제 #4
0
    def __init__(self, *args, **kwargs):
        self._root_version      = Version.parse("0.0.0")
        self._root_dependencies = [ ]
        self._packages          = { }

        self.super = super(PackageSource, self)
        self.super.__init__(*args, **kwargs)
예제 #5
0
def workflow_upgrade(c: Composition, parser: WorkflowArgumentParser) -> None:
    """Test upgrades from various versions."""

    parser.add_argument(
        "--min-version",
        metavar="VERSION",
        type=Version.parse,
        default=Version.parse("0.8.0"),
        help="the minimum version to test from",
    )
    parser.add_argument(
        "--most-recent",
        metavar="N",
        type=int,
        help="limit testing to the N most recent versions",
    )
    parser.add_argument(
        "filter", nargs="?", default="*", help="limit to only the files matching filter"
    )
    args = parser.parse_args()

    tested_versions = [v for v in all_versions if v >= args.min_version]
    if args.most_recent is not None:
        tested_versions = tested_versions[: args.most_recent]
    tested_versions.reverse()

    c.start_and_wait_for_tcp(
        services=["zookeeper", "kafka", "schema-registry", "postgres"]
    )

    for version in tested_versions:
        priors = [f"v{v}" for v in all_versions if v < version]
        test_upgrade_from_version(c, f"v{version}", priors, filter=args.filter)

    test_upgrade_from_version(c, "current_source", priors=["*"], filter=args.filter)
예제 #6
0
def known_materialize_versions() -> List[Version]:
    """Returns all known Materialize versions.

    The list is returned in version order with newest versions first.
    """
    files = Path(ROOT / "doc" / "user" / "content" / "releases").glob("*.md")
    return [
        Version.parse(f.stem.lstrip("v")) for f in files
        if f.stem.startswith("v")
    ]
예제 #7
0
def test_allows():
    v = Version.parse("1.2.3")
    assert v.allows(v)
    assert not v.allows(Version.parse("2.2.3"))
    assert not v.allows(Version.parse("1.3.3"))
    assert not v.allows(Version.parse("1.2.4"))
    assert not v.allows(Version.parse("1.2.3-dev"))
    assert not v.allows(Version.parse("1.2.3+build"))
예제 #8
0
def test_intersect():
    v = Version.parse("1.2.3")

    assert v.intersect(v) == v
    assert v.intersect(Version.parse("1.1.4")).is_empty()
    assert (v.intersect(
        VersionRange(Version.parse("1.1.4"), Version.parse("1.2.4"))) == v)
    assert (Version.parse("1.1.4").intersect(
        VersionRange(v, Version.parse("1.2.4"))).is_empty())
예제 #9
0
def test_difference():
    v = Version.parse("1.2.3")

    assert v.difference(v).is_empty()
    assert v.difference(Version.parse("0.8.0")) == v
    assert v.difference(
        VersionRange(Version.parse("1.1.4"),
                     Version.parse("1.2.4"))).is_empty()
    assert (v.difference(
        VersionRange(Version.parse("1.4.0"), Version.parse("3.0.0"))) == v)
예제 #10
0
    def add(self,
            name,
            version,
            deps=None):  # type: (str, str, Optional[Dict[str, str]]) -> None
        if deps is None:
            deps = {}

        version = Version.parse(version)
        if name not in self._packages:
            self._packages[name] = {}

        if version in self._packages[name]:
            raise ValueError("{} ({}) already exists".format(name, version))

        dependencies = []
        for dep_name, spec in deps.items():
            dependencies.append(Dependency(dep_name, spec))

        self._packages[name][version] = dependencies
예제 #11
0
    def add(self, name, extras, version, deps = None):
        version = Version.parse(version)
        
        if name not in self._packages:
            self._packages[name] = { extras: {} }
        if extras not in self._packages[name]:
            self._packages[name][extras] = {}

        if version in self._packages[name][extras] and not (
            deps is None or self._packages[name][extras][version] is None
        ):
            raise ValueError("{} ({}) already exists".format(name, version))

        if deps is None:
            self._packages[name][extras][version] = None
        else:
            dependencies = []
            for dep in deps:
                dependencies.append(Dependency(dep))

            self._packages[name][extras][version] = dependencies
예제 #12
0
def v300():
    return Version.parse("3.0.0")
예제 #13
0
def v250():
    return Version.parse("2.5.0")
예제 #14
0
def v234():
    return Version.parse("2.3.4")
예제 #15
0
def v200():
    return Version.parse("2.0.0")
예제 #16
0
def v140():
    return Version.parse("1.4.0")
예제 #17
0
def test_version_info_should_throw_index_error(version, index):
    version_info = Version.parse(version)
    with pytest.raises(IndexError, match=r"Version part undefined"):
        version_info[index]
예제 #18
0
def get_latest_version(versions: Iterable[str]) -> str:
    try:
        versions = [Version.parse(version) for version in versions]
    except ValueError:
        return "couldn't determine: Not all versions are valid semver"
    return str(max(versions))
예제 #19
0
 def test_parse_should_return_tuple(self):
     for version, result in VALID_VERSIONS.items():
         self.assertIsInstance(Version.parse(version), tuple, "{} should be a tuple type.".format(version))
예제 #20
0
        ">= 2.7, != 3.0.*, != 3.1.*"
    ],
)
def test_parse_constraint_multi_wilcard(input):
    assert parse_constraint(input) == VersionUnion(
        VersionRange(Version(2, 7, 0), Version(3, 0, 0), True, False),
        VersionRange(Version(3, 2, 0), None, True, False),
    )


@pytest.mark.parametrize(
    "input,constraint",
    [
        (
            "!=v2.*",
            VersionRange(max=Version.parse("2.0")).union(
                VersionRange(Version.parse("3.0"), include_min=True)),
        ),
        (
            "!=2.*.*",
            VersionRange(max=Version.parse("2.0")).union(
                VersionRange(Version.parse("3.0"), include_min=True)),
        ),
        (
            "!=2.0.*",
            VersionRange(max=Version.parse("2.0")).union(
                VersionRange(Version.parse("2.1"), include_min=True)),
        ),
        ("!=0.*", VersionRange(Version.parse("1.0"), include_min=True)),
        ("!=0.*.*", VersionRange(Version.parse("1.0"), include_min=True)),
    ],
예제 #21
0
def v072():
    return Version.parse("0.7.2")
예제 #22
0
def v080():
    return Version.parse("0.8.0")
예제 #23
0
def v010():
    return Version.parse("0.1.0")
예제 #24
0
def test_allows_any(v003, v010, v072, v080, v114, v123, v124, v140, v200, v234,
                    v250, v300):
    # disallows an empty constraint
    assert not VersionRange(v123, v250).allows_any(EmptyConstraint())

    # allows allowed versions
    range = VersionRange(v123, v250, include_max=True)
    assert not range.allows_any(v123)
    assert range.allows_any(v124)
    assert range.allows_any(v250)
    assert not range.allows_any(v300)

    # with no min
    range = VersionRange(max=v200)
    assert range.allows_any(VersionRange(v140, v300))
    assert not range.allows_any(VersionRange(v234, v300))
    assert range.allows_any(VersionRange(v140))
    assert not range.allows_any(VersionRange(v234))
    assert range.allows_any(range)

    # with no max
    range = VersionRange(min=v072)
    assert range.allows_any(VersionRange(v003, v140))
    assert not range.allows_any(VersionRange(v003, v010))
    assert range.allows_any(VersionRange(max=v080))
    assert not range.allows_any(VersionRange(max=v003))
    assert range.allows_any(range)

    # with min and max
    range = VersionRange(v072, v200)
    assert range.allows_any(VersionRange(v003, v140))
    assert range.allows_any(VersionRange(v140, v300))
    assert not range.allows_any(VersionRange(v003, v010))
    assert not range.allows_any(VersionRange(v234, v300))
    assert not range.allows_any(VersionRange(max=v010))
    assert not range.allows_any(VersionRange(v234))
    assert range.allows_any(range)

    # allows a bordering range when both are inclusive
    assert not VersionRange(max=v250).allows_any(VersionRange(min=v250))
    assert not VersionRange(max=v250, include_max=True).allows_any(
        VersionRange(min=v250))
    assert not VersionRange(max=v250).allows_any(
        VersionRange(min=v250, include_min=True))
    assert not VersionRange(min=v250).allows_any(VersionRange(max=v250))
    assert VersionRange(max=v250, include_max=True).allows_any(
        VersionRange(min=v250, include_min=True))

    # allows unions that are partially contained'
    range = VersionRange(v114, v200)
    assert range.allows_any(VersionRange(v010, v080).union(v140))
    assert range.allows_any(VersionRange(v123, v234).union(v300))
    assert not range.allows_any(VersionRange(v234, v300).union(v010))

    # pre-release min does not allow lesser than itself
    range = VersionRange(Version.parse("1.9b1"), include_min=True)
    assert not range.allows_any(
        VersionRange(
            Version.parse("1.8.0"),
            Version.parse("1.9.0"),
            include_min=True,
            always_include_max_prerelease=True,
        ))
예제 #25
0
def v003():
    return Version.parse("0.0.3")
예제 #26
0
from materialize import util
from materialize.mzcompose import Composition, WorkflowArgumentParser
from materialize.mzcompose.services import (
    Kafka,
    Materialized,
    Postgres,
    SchemaRegistry,
    Testdrive,
    Zookeeper,
)

# All released Materialize versions, in order from most to least recent.
all_versions = util.known_materialize_versions()

# The `materialized` options that are valid only at or above a certain version.
mz_options = {Version.parse("0.9.2"): "--persistent-user-tables"}

SERVICES = [
    Zookeeper(),
    Kafka(),
    SchemaRegistry(),
    Postgres(),
    Materialized(options=" ".join(mz_options.values())),
    # N.B.: we need to use `validate_catalog=False` because testdrive uses HEAD
    # to load the catalog from disk but does *not* run migrations. There is no
    # guarantee that HEAD can load an old catalog without running migrations.
    #
    # When testdrive is targeting a HEAD materialized, we re-enable catalog
    # validation below by manually passing the `--validate-catalog` flag.
    #
    # Disabling catalog validation is preferable to using a versioned testdrive
예제 #27
0
def test_version_info_should_throw_index_error_when_negative_index(
        version, index):
    version_info = Version.parse(version)
    with pytest.raises(IndexError, match=r"Version index cannot be negative"):
        version_info[index]
예제 #28
0
 def test_successful_parse(self):
     for version, result in VALID_VERSIONS.items():
         self.assertTupleEqual(Version.parse(version), result, "{} should be equal to {}.".format(version, result))
예제 #29
0
def v123():
    return Version.parse("1.2.3")
예제 #30
0
 def test_parse_tuple_should_contain_ints(self):
     for version in VALID_VERSIONS.keys():
         for i in Version.parse(version):
             self.assertIsInstance(i, int, "{} in {} should be in integer.".format(i, version))
예제 #31
0
def v124():
    return Version.parse("1.2.4")
예제 #32
0
def v114():
    return Version.parse("1.1.4")
예제 #33
0
def v130():
    return Version.parse("1.3.0")