Skip to content

Commit

Permalink
Coverage, clean and create/recreate scenarios added, tests refactored…
Browse files Browse the repository at this point in the history
… and fixed, workflows updated. (#65)

* Makefile updated.

* Base integration test marked with pytest.mark.integtest.

* Tox scenario added, GH workflow updated.

* Init and clean scenarios added.

* Recreate commands added.

* Mypy ignore updated.

* Pylint check import pytest disabled.

* Test folders renamed.

* Test modules and classes names refactored.

* MacOS and Windows added to GH workflow.

* Windows temporarily removed from GH workflow.

* Some lines excluded from coverage report.

* Reformatted with black.

* Comments in PR resolved.

* Setup Docker on GH workflow.

* Install Docker macOS option 2

* Docker setup fixed.

* Install Docker updated.

* Docker launch updated.

* Docker launch updated.

* Docker launch on CI updated.

* Docker run updated.

* GH workflow updated.

* New workflow for a release PR added, ordinary workflow changed.

* Workflow updated.

* GH workflow fixed.

* Resolved comments in the PR.

* Windows added to GH workflow.

* Disable protected-access runle for Pylint.

* Pylintrc updated.

* Pylintrc updated.

* Pylintrc fixed.

* Check copywrite script fixed.

* No longer needed pylint option removed.

* Debug CI code.

* Debug action removed.

* Tests with integration enabled for Linux only.

* Another debug GH action added.

* Check docker moved to a correct workflow.

* Debug action removed.

* Debug action added.

* Debug workflow fixed.

* Workflow statement fixed.

* Try to fix Windows integration tests.

* Try to fix integration tests for Windows 2.

* Integration tests disabled for Windows release workflow.

* Non working fixes removed.

* Release workflow fixed.

* Try to fix Windows tests.

* Reformatted with black.

* Try to fix tests on windows v2

* Workflows updated.

* Tests fixed.

* Try to fix Windows tests.

* Missing import fixed.

* Changes reverted.

* Try to fix Windows tests.

* Try to fix Windows tests.

* Try to fix Windows tests.

* Try to fix Windows tests.

* Coverage ignore updated.

* Coverage increased to 100%
  • Loading branch information
panasevychol authored Sep 24, 2021
1 parent 594c205 commit 64456f5
Show file tree
Hide file tree
Showing 32 changed files with 266 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ omit =
tests/*
# omit Tox
.tox/*
# omit protos
cosmpy/protos/*

[html]
directory = coverage_report
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Pre-release checks and tests

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
run:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [macos-latest]
python-version: [3.7, 3.8, 3.9]

timeout-minutes: 30

steps:
- uses: actions/checkout@master
- uses: actions/setup-python@master
with:
python-version: ${{ matrix.python-version }}
- uses: docker-practice/actions-setup-docker@master
- name: Install dependencies
run: pip install tox==3.24.1
- name: Integration tests for macOS
# Currently ordinary workflow runs full set of tests (with integration) for Linux
# and unit tests for other platforms
# In pre-release check we run also integration tests for macOS
# Windows integration tests are currently disabled
run: |
if [ "$RUNNER_OS" == "macOS" ]; then
tox -e test-integration
fi
shell: bash
14 changes: 12 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Checks and Tests
on:
push:
branches:
- develop
- master
pull_request:

Expand All @@ -12,7 +13,7 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.7, 3.8, 3.9]

timeout-minutes: 30
Expand Down Expand Up @@ -47,4 +48,13 @@ jobs:
- name: Manifest check
run: tox -e check-manifest
- name: Tests and coverage
run: tox -e test
# Run full set of tests for Linux and unit tests only for other platforms
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
tox -e test
else
tox -e test-unit
fi
shell: bash
- name: Show coverage report
run: tox -e coverage-report
3 changes: 3 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ max-attributes=38

[REFACTORING]
max-nested-blocks=6

[MASTER]
ignore=protos
81 changes: 79 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ mypy:

.PHONY: pylint
pylint:
pylint $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py --ignore-paths "cosmpy/protos/"
pylint $(PYCOSM_SRC_DIR) $(PYCOSM_TESTS_DIR) $(PYCOSM_EXAMPLES_DIR) setup.py

####################
### Tests
Expand All @@ -126,7 +126,19 @@ pylint:
.PHONY: test
test:
coverage run -m pytest $(PYCOSM_TESTS_DIR) --doctest-modules --ignore $(PYCOSM_TESTS_DIR)/vulture_whitelist.py
coverage report
make coverage-report

.PHONY: unit-test
unit-test:
coverage run -m pytest $(PYCOSM_TESTS_DIR) --doctest-modules --ignore $(PYCOSM_TESTS_DIR)/vulture_whitelist.py -m "not integtest"

.PHONY: integration-test
integration-test:
coverage run -m pytest $(PYCOSM_TESTS_DIR) --doctest-modules --ignore $(PYCOSM_TESTS_DIR)/vulture_whitelist.py -m "integtest"

.PHONY: coverage-report
coverage-report:
coverage report -m
coverage html

####################
Expand All @@ -141,6 +153,71 @@ liccheck:
copyright-check:
python scripts/check_copyright.py

####################
### Clean and init commands
####################

.PHONY: clean
clean: clean-build clean-pyc clean-test clean-docs

.PHONY: clean-build
clean-build:
rm -fr build/
rm -fr dist/
rm -fr .eggs/
rm -fr pip-wheel-metadata
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -fr {} +

.PHONY: clean-docs
clean-docs:
# Update when docs PR is merged to avoid conflicts
# rm -fr docs/build/

.PHONY: clean-pyc
clean-pyc:
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
find . -name '.DS_Store' -exec rm -fr {} +

.PHONY: clean-test
clean-test:
rm -fr .tox/
rm -f .coverage
find . -name ".coverage*" -not -name ".coveragerc" -exec rm -fr "{}" \;
rm -fr coverage_report/
rm -fr .hypothesis
rm -fr .pytest_cache
rm -fr .mypy_cache/
find . -name 'log.txt' -exec rm -fr {} +
find . -name 'log.*.txt' -exec rm -fr {} +

v := $(shell pip -V | grep virtualenvs)

.PHONY: new_env
new_env: clean
if [ -z "$v" ];\
then\
pipenv --rm;\
pipenv install;\
echo "Enter virtual environment with all development dependencies now: 'pipenv shell'.";\
else\
echo "In a virtual environment! Exit first: 'exit'.";\
fi

.PHONY: new_env_dev
new_env_dev: clean
if [ -z "$v" ];\
then\
pipenv --rm;\
pipenv install --dev;\
echo "Enter virtual environment with all development dependencies now: 'pipenv shell'.";\
else\
echo "In a virtual environment! Exit first: 'exit'.";\
fi

####################
### Combinations
####################
Expand Down
6 changes: 4 additions & 2 deletions cosmpy/clients/cosmwasm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def __init__(self, channel: Union[Channel, RestClient]):
self.auth_client = AuthRestClient(channel)
self.wasm_client = CosmWasmRestClient(channel)
else:
raise RuntimeError(f"Unsupported channel type {type(channel)}")
raise RuntimeError(
f"Unsupported channel type {type(channel)}"
) # pragma: no cover

def get_balance(self, address: Address, denom: str) -> QueryBalanceResponse:
"""
Expand Down Expand Up @@ -103,7 +105,7 @@ def query_account_data(self, address: Address) -> BaseAccount:
if account_response.account.Is(BaseAccount.DESCRIPTOR):
account_response.account.Unpack(account)
else:
raise TypeError("Unexpected account type")
raise TypeError("Unexpected account type") # pragma: no cover
return account

def query_contract_state(self, contract_address: str, msg: JSONLike) -> JSONLike:
Expand Down
4 changes: 3 additions & 1 deletion cosmpy/clients/signing_cosmwasm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def __init__(
elif isinstance(channel, RestClient):
self.tx_client = TxRestClient(channel)
else:
raise RuntimeError(f"Unsupported channel type {type(channel)}")
raise RuntimeError(
f"Unsupported channel type {type(channel)}"
) # pragma: no cover

self.private_key = private_key

Expand Down
6 changes: 3 additions & 3 deletions cosmpy/crypto/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
def _to_bech32(prefix: str, data: bytes) -> str:
data_base5 = bech32.convertbits(data, 8, 5, True)
if data_base5 is None:
raise RuntimeError("Unable to parse address")
raise RuntimeError("Unable to parse address") # pragma: no cover
return bech32.bech32_encode(prefix, data_base5)


Expand All @@ -55,7 +55,7 @@ def __init__(

data_base8 = bech32.convertbits(data_base5, 5, 8, False)
if data_base8 is None:
raise RuntimeError("Unable to parse address")
raise RuntimeError("Unable to parse address") # pragma: no cover

self._address = bytes(data_base8)
self._display = value
Expand All @@ -75,7 +75,7 @@ def __init__(
self._address = value._address
self._display = value._display
else:
raise TypeError("Unexpected type of `value` parameter")
raise TypeError("Unexpected type of `value` parameter") # pragma: no cover

def __str__(self):
return self._display
Expand Down
2 changes: 1 addition & 1 deletion cosmpy/crypto/keypairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def verify_digest(self, digest: bytes, signature: bytes) -> bool:
try:
success = self._verifying_key.verify_digest(signature, digest)

except ecdsa.keys.BadSignatureError:
except ecdsa.keys.BadSignatureError: # pragma: no cover
...

return success
Expand Down
5 changes: 4 additions & 1 deletion scripts/check_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"""

import itertools
import os
import re
import sys
from pathlib import Path
Expand Down Expand Up @@ -82,7 +83,9 @@ def check_copyright(file: Path) -> bool:

# filter out protobuf files (*_pb2.py) and all files under cosmpy/protos
python_files_filtered = filter(
lambda x: not str(x).endswith("_pb2.py") and str(x).find("cosmpy/protos/") == -1, python_files
lambda x: not str(x).endswith("_pb2.py")
and str(x).find(os.path.join("cosmpy", "protos")) == -1,
python_files,
)

bad_files = [
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ ignore_missing_imports = True
[mypy-cosmpy.protos.*]
ignore_errors = True

[mypy-pytest.*]
ignore_missing_imports = True

[darglint]
docstring_style=sphinx
strictness=short
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/generic/fetchd_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _create(self):
with tempfile.TemporaryDirectory() as tmpdir:
self._make_entrypoint(tmpdir)
volumes = {tmpdir: {"bind": self.MOUNT_PATH, "mode": "rw"}}
entrypoint = os.path.join(self.MOUNT_PATH, self.ENTRYPOINT_FILENAME)
entrypoint = f"{self.MOUNT_PATH}/{self.ENTRYPOINT_FILENAME}"
self.container = self.client.containers.run(
self.IMG_TAG,
detach=True,
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/generic/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@

from unittest import TestCase

import pytest # pylint: disable=import-error
from docker.errors import NotFound # pylint: disable=import-error

from tests.integration.generic.fetchd_client import FetchdDockerImage


@pytest.mark.integtest
class FetchdTestCase(TestCase):
"""Base test case for Fetchd node."""

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from tests.helpers import MockRestClient


class AuthTests(unittest.TestCase):
class AuthRestClientTestCase(unittest.TestCase):
"""Test case for Auth module."""

@staticmethod
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from tests.helpers import MockRestClient


class BankTests(unittest.TestCase):
class BankRestClientTestCase(unittest.TestCase):
"""Test case of Bank module."""

@staticmethod
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from tests.helpers import MockRestClient


class CosmWasmClientTests(unittest.TestCase):
class CosmWasmClientTestCase(unittest.TestCase):
"""Test case of CosmWasm client module."""

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import base64
import gzip
import json
import os
import tempfile
import unittest
from typing import Optional
Expand Down Expand Up @@ -172,7 +173,7 @@ def mock_get_contract_address(response: GetTxResponse) -> str:
return CONTRACT_ADDRESS


class CosmWasmClientTests(unittest.TestCase):
class CosmWasmClientTestCase(unittest.TestCase):
"""Test case of CosmWasm client module."""

@classmethod
Expand Down Expand Up @@ -246,10 +247,11 @@ def test_get_packed_exec_msg(self):

def test_get_packed_store_msg(self):
"""Test correct generation of packed store msg."""
with tempfile.NamedTemporaryFile(suffix=CONTRACT_FILENAME) as tmp:
with tempfile.NamedTemporaryFile(suffix=CONTRACT_FILENAME, delete=False) as tmp:
tmp.write(CONTRACT_BYTECODE)
tmp.flush()
msg = self.signing_wasm_client.get_packed_store_msg(ADDRESS_PK, tmp.name)
msg = self.signing_wasm_client.get_packed_store_msg(ADDRESS_PK, tmp.name)
os.unlink(tmp.name)

msg_dict = MessageToDict(msg)
assert len(msg_dict) == 3
Expand Down Expand Up @@ -396,10 +398,13 @@ def test_deploy_contract(self):
self.signing_wasm_client.tx_client = mock_tx_client

with patch.object(self.signing_wasm_client, "get_code_id", mock_get_code_id):
with tempfile.NamedTemporaryFile(suffix=CONTRACT_FILENAME) as tmp:
with tempfile.NamedTemporaryFile(
suffix=CONTRACT_FILENAME, delete=False
) as tmp:
tmp.write(CONTRACT_BYTECODE)
tmp.flush()
result = self.signing_wasm_client.deploy_contract(tmp.name)
result = self.signing_wasm_client.deploy_contract(tmp.name)
os.unlink(tmp.name)

assert result == CODE_ID

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from cosmpy.common.rest_client import RestClient


class QueryTests(TestCase):
class QueryRestClientTestCase(TestCase):
"""Test case of REST client module."""

@staticmethod
Expand Down
File renamed without changes.
Loading

0 comments on commit 64456f5

Please sign in to comment.