|
| 1 | +# Copyright (c) 2024 Airbyte, Inc., all rights reserved. |
| 2 | +"""Run acceptance tests in PyTest. |
| 3 | +
|
| 4 | +These tests leverage the same `acceptance-test-config.yml` configuration files as the |
| 5 | +acceptance tests in CAT, but they run in PyTest instead of CAT. This allows us to run |
| 6 | +the acceptance tests in the same local environment as we are developing in, speeding |
| 7 | +up iteration cycles. |
| 8 | +""" |
| 9 | + |
| 10 | +from __future__ import annotations |
| 11 | + |
| 12 | +from enum import Enum, auto |
| 13 | + |
| 14 | + |
| 15 | +class ExpectedOutcome(Enum): |
| 16 | + """Enum to represent the expected outcome of a test scenario. |
| 17 | +
|
| 18 | + Class supports comparisons to a boolean or None. |
| 19 | + """ |
| 20 | + |
| 21 | + EXPECT_EXCEPTION = auto() |
| 22 | + EXPECT_SUCCESS = auto() |
| 23 | + ALLOW_ANY = auto() |
| 24 | + |
| 25 | + @classmethod |
| 26 | + def from_status_str(cls, status: str | None) -> ExpectedOutcome: |
| 27 | + """Convert a status string to an ExpectedOutcome.""" |
| 28 | + if status is None: |
| 29 | + return ExpectedOutcome.ALLOW_ANY |
| 30 | + |
| 31 | + try: |
| 32 | + return { |
| 33 | + "succeed": ExpectedOutcome.EXPECT_SUCCESS, |
| 34 | + "failed": ExpectedOutcome.EXPECT_EXCEPTION, |
| 35 | + }[status] |
| 36 | + except KeyError as ex: |
| 37 | + raise ValueError(f"Invalid status '{status}'. Expected 'succeed' or 'failed'.") from ex |
| 38 | + |
| 39 | + def expect_exception(self) -> bool: |
| 40 | + """Return whether the expectation is that an exception should be raised.""" |
| 41 | + return self == ExpectedOutcome.EXPECT_EXCEPTION |
| 42 | + |
| 43 | + def expect_success(self) -> bool: |
| 44 | + """Return whether the expectation is that the test should succeed without exceptions.""" |
| 45 | + return self == ExpectedOutcome.EXPECT_SUCCESS |
0 commit comments