Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tests): include tests in pypi package #44

Merged
merged 4 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ matrix:
python: 3.7
before_install:
- nvm install 12
- nvm use 12
- nvm use 12
before_script:
- npm install && npx ts-node tools/ci-set-build-version.ts
- sh tools/setup.sh
Expand All @@ -21,5 +21,6 @@ cache:
notifications:
email: false
branches:
except:
- /^v\d+\.\d+\.\d+$/
only:
- master
- develop
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ include README.md
include LICENSE
include pathy/py.typed
include requirements.txt
include pathy/tests/fixtures/*
File renamed without changes.
25 changes: 14 additions & 11 deletions tests/conftest.py → pathy/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import tempfile
from pathlib import Path
from typing import Any, Generator, Optional

import pytest

Expand All @@ -18,29 +19,29 @@

@pytest.fixture()
def bucket() -> str:
return "pathy-tests-bucket"
return os.environ.get("PATHY_TEST_BUCKET", "pathy-tests-bucket")


@pytest.fixture()
def other_bucket() -> str:
return "pathy-tests-bucket-other"
return os.environ.get("PATHY_TEST_BUCKET_OTHER", "pathy-tests-bucket-other")


@pytest.fixture()
def temp_folder():
def temp_folder() -> Generator[Path, None, None]:
tmp_dir = tempfile.mkdtemp()
yield Path(tmp_dir)
shutil.rmtree(tmp_dir)


@pytest.fixture()
def with_fs(temp_folder):
def with_fs(temp_folder: Path) -> Generator[Path, None, None]:
yield temp_folder
# Turn off FS adapter
use_fs(False)


def credentials_from_env():
def gcs_credentials_from_env() -> Optional[Any]:
"""Extract a credentials instance from the GCS_CREDENTIALS env variable.

You can specify the contents of a credentials JSON file or a file path
Expand All @@ -62,28 +63,30 @@ def credentials_from_env():
except json.decoder.JSONDecodeError:
pass

# If not a file path, assume it's JSON content
if json_creds is None:
credentials = service_account.Credentials.from_service_account_file(creds)
else:
if json_creds is not None:
fd, path = tempfile.mkstemp()
try:
with os.fdopen(fd, "w") as tmp:
tmp.write(json.dumps(json_creds))
credentials = service_account.Credentials.from_service_account_file(path)
finally:
os.remove(path)
else:
# If not a JSON string, assume it's a JSON file path
credentials = service_account.Credentials.from_service_account_file(creds)
return credentials


@pytest.fixture()
def with_adapter(adapter: str, bucket: str, other_bucket: str):
def with_adapter(
adapter: str, bucket: str, other_bucket: str
) -> Generator[str, None, None]:
tmp_dir = None
scheme = "gs"
if adapter == "gcs":
# Use GCS
use_fs(False)
credentials = credentials_from_env()
credentials = gcs_credentials_from_env()
if credentials is not None:
set_client_params("gs", credentials=credentials)
elif adapter == "fs":
Expand Down
Loading