2021-12-16 23:07:38 -05:00
|
|
|
from pathlib import Path
|
|
|
|
from typing import List, Optional
|
|
|
|
|
|
|
|
from click.testing import CliRunner, Result
|
|
|
|
|
|
|
|
from datahub.entrypoints import datahub
|
2022-01-12 00:25:42 -08:00
|
|
|
from datahub.telemetry.telemetry import telemetry_instance
|
2021-12-16 23:07:38 -05:00
|
|
|
from tests.test_helpers import fs_helpers
|
2021-07-30 17:41:03 -07:00
|
|
|
|
2022-01-12 00:25:42 -08:00
|
|
|
# disable telemetry for tests under this instance
|
|
|
|
telemetry_instance.enabled = False
|
|
|
|
|
2021-07-30 17:41:03 -07:00
|
|
|
|
|
|
|
def assert_result_ok(result: Result) -> None:
|
|
|
|
if result.exception:
|
|
|
|
raise result.exception
|
|
|
|
assert result.exit_code == 0
|
2021-12-16 23:07:38 -05:00
|
|
|
|
|
|
|
|
|
|
|
def run_datahub_cmd(
|
|
|
|
command: List[str], tmp_path: Optional[Path] = None, check_result: bool = True
|
|
|
|
) -> Result:
|
|
|
|
runner = CliRunner()
|
|
|
|
|
|
|
|
if tmp_path is None:
|
|
|
|
result = runner.invoke(datahub, command)
|
|
|
|
else:
|
|
|
|
with fs_helpers.isolated_filesystem(tmp_path):
|
|
|
|
result = runner.invoke(datahub, command)
|
|
|
|
|
|
|
|
if check_result:
|
|
|
|
assert_result_ok(result)
|
|
|
|
return result
|