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

Sonarqube #19

Merged
merged 12 commits into from
Oct 12, 2024
14 changes: 14 additions & 0 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ jobs:
parallel-finished: true
carryforward: "run-ubuntu-latest-3.10,run-ubuntu-latest-3.11,run-ubuntu-latest-3.12,run-windows-latest-3.10,run-windows-latest-3.11,run-windows-latest-3.12"

sonarcloud:
needs: [python-test]
if: ${{ always() }}
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

bump-version:
runs-on: ubuntu-latest
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- id: check-useless-excludes

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
exclude: ^tests/(cassettes|__snapshots__)/.+\.(yaml|ambr)$
Expand Down Expand Up @@ -43,7 +43,7 @@ repos:

# change to use yamlfix or prettier
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.13.0
rev: v2.14.0
hooks:
- id: pretty-format-yaml
args:
Expand All @@ -54,18 +54,18 @@ repos:
exclude: ^tests/cassettes/.+\.yaml$

- repo: https://github.com/commitizen-tools/commitizen
rev: v3.24.0
rev: v3.29.1
hooks:
- id: commitizen
additional_dependencies: [cz-conventional-gitmoji]

- repo: https://github.com/ljnsn/cz-conventional-gitmoji
rev: v0.3.1
rev: v0.5.2
hooks:
- id: conventional-gitmoji

- repo: https://github.com/pdm-project/pdm
rev: 2.15.1
rev: 2.19.2
hooks:
- id: pdm-lock-check

Expand Down
1,049 changes: 609 additions & 440 deletions pdm.lock

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sonar.projectKey=ljnsn_coinapi-rest
sonar.organization=ljnsn
sonar.python.version=">=3.10"
# sonar.python.coverage.reportPaths=reports/coverage.xml
sonar.sources=src/
sonar.tests=tests/
sonar.projectVersion=0.0.4

# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=coinapi-rest

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
2 changes: 1 addition & 1 deletion src/coinapi/exchange_rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_v1_specific_rate(
accept_header_override=accept_header_override,
)

def get_v1_base_rates( # noqa: PLR0913
def get_v1_base_rates(
self,
asset_id_base: str,
filter_asset_id: str | None = None,
Expand Down
4 changes: 2 additions & 2 deletions src/coinapi/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def put_v1_indexes_index_id_json(
accept_header_override,
)

def get_v1_indexes_index_id_history( # noqa: PLR0913
def get_v1_indexes_index_id_history(
self,
index_id: str,
time_start: datetime | None = None,
Expand All @@ -85,7 +85,7 @@ def get_v1_indexes_index_id_history( # noqa: PLR0913
accept_header_override,
)

def get_v1_indexes_index_id_timeseries( # noqa: PLR0913
def get_v1_indexes_index_id_timeseries(
self,
index_id: str,
time_start: datetime | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/coinapi/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def get_v1_metrics_asset_listing(
accept_header_override=accept_header_override,
)

def get_v1_metrics_asset_current( # noqa: PLR0913
def get_v1_metrics_asset_current(
self,
metric_id: str | None = None,
asset_id: str | None = None,
Expand Down
4 changes: 2 additions & 2 deletions src/coinapi/ohlcv.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_v1_ohlcv_symbol_id_history(
accept_header_override=accept_header_override,
)

def get_v1_ohlcv_exchanges_exchange_id_history( # noqa: PLR0913
def get_v1_ohlcv_exchanges_exchange_id_history(
self,
exchange_id: str,
period_id: str,
Expand Down Expand Up @@ -104,7 +104,7 @@ def get_v1_ohlcv_exchanges_exchange_id_history( # noqa: PLR0913
accept_header_override=accept_header_override,
)

def get_v1_ohlcv_symbol_id_latest( # noqa: PLR0913
def get_v1_ohlcv_symbol_id_latest(
self,
symbol_id: str,
period_id: str | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/coinapi/quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Quotes(Base):
r"""Controller for retrieving quotes data, also known as quotes or passive level 1 data."""

def get_v1_quotes_symbol_id_history( # noqa: PLR0913
def get_v1_quotes_symbol_id_history(
self,
symbol_id: str,
time_start: str | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/coinapi/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class CoinAPI:

sdk_configuration: CoinAPIConfig

def __init__( # noqa: PLR0913
def __init__(
self,
api_key: str | Callable[[], str],
server_idx: int | None = None,
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ def _session_start() -> None:
vcr_log.setLevel(logging.WARNING)


@pytest.fixture()
@pytest.fixture
def api_key() -> str:
"""Load the API key from the environment."""
load_dotenv()
return os.environ.get("COINAPI_KEY", "testing")


@pytest.fixture()
@pytest.fixture
def coinapi(api_key: str) -> CoinAPI:
"""Return a CoinAPI instance."""
return CoinAPI(api_key)
Expand Down Expand Up @@ -75,7 +75,7 @@ def vcr_config(record_mode: str) -> dict[str, Any]:
}


@pytest.fixture()
@pytest.fixture
def snapshot_json(snapshot: SnapshotAssertion) -> SnapshotAssertion:
"""Return a snapshot instance for JSON."""
return snapshot.with_defaults(extension_class=JSONSnapshotExtension)
8 changes: 4 additions & 4 deletions tests/test_exchange_rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from coinapi.models import operations


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_specific_rate(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
"""Test get_v1_specific_rate."""
response = coinapi.exchange_rates.get_v1_specific_rate(
Expand All @@ -21,7 +21,7 @@ def test_get_v1_specific_rate(coinapi: CoinAPI, snapshot: SnapshotAssertion) ->
assert response.content == snapshot


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_base_rates(
coinapi: CoinAPI,
snapshot: SnapshotAssertion,
Expand All @@ -36,7 +36,7 @@ def test_get_v1_base_rates(
assert response.content == snapshot


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_history_periods(
coinapi: CoinAPI,
snapshot: SnapshotAssertion,
Expand All @@ -49,7 +49,7 @@ def test_get_v1_history_periods(
assert response.content == snapshot


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_pair_history(
coinapi: CoinAPI,
snapshot: SnapshotAssertion,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from coinapi.models import components, operations


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_indexes(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
"""Test get_v1_indexes_listing."""
response = coinapi.indexes.get_v1_indexes()
Expand All @@ -29,7 +29,7 @@ def test_post_v1_indexes(coinapi: CoinAPI) -> None:
assert response.status_code == 201


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_indexes_index_id(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
"""Test get_v1_indexes_index_id."""
response = coinapi.indexes.get_v1_indexes_index_id("TEST_IDX14_VWAP")
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_put_v1_indexes(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
assert response.content == snapshot


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_indexes_history(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
"""Test retrieving historical index value and composition."""
response = coinapi.indexes.get_v1_indexes_index_id_history("TEST_IDX14_VWAP")
Expand All @@ -75,7 +75,7 @@ def test_get_v1_indexes_history(coinapi: CoinAPI, snapshot: SnapshotAssertion) -


@pytest.mark.skip(reason="Alpha release..")
@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_indexes_index_id_timeseries(
coinapi: CoinAPI,
snapshot: SnapshotAssertion,
Expand Down
18 changes: 9 additions & 9 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from coinapi import CoinAPI


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_assets(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
"""Test get_v1_assets."""
res = coinapi.metadata.get_v1_assets(filter_asset_id="BTC,XMR")
Expand All @@ -15,7 +15,7 @@ def test_get_v1_assets(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
assert res.content == snapshot


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_asset_id(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
"""Test get_v1_exchanges."""
res = coinapi.metadata.get_v1_assets_asset_id("BTC")
Expand All @@ -24,7 +24,7 @@ def test_get_v1_asset_id(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
assert res.content == snapshot


@pytest.mark.network()
@pytest.mark.network
def test_get_v1_assets_icons(coinapi: CoinAPI) -> None:
"""Test get_v1_asset_icons."""
# we don't want to store the whole response in the repo, so we don't use vcr here
Expand All @@ -33,7 +33,7 @@ def test_get_v1_assets_icons(coinapi: CoinAPI) -> None:
assert res.content is not None


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_exchanges(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
"""Test get_v1_exchanges."""
res = coinapi.metadata.get_v1_exchanges("KRAKEN,BINANCE")
Expand All @@ -42,7 +42,7 @@ def test_get_v1_exchanges(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None
assert res.content == snapshot


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_exchange_id(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
"""Test get_v1_exchange_id."""
res = coinapi.metadata.get_v1_exchanges_exchange_id("KRAKEN")
Expand All @@ -51,7 +51,7 @@ def test_get_v1_exchange_id(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> No
assert res.content == snapshot


@pytest.mark.network()
@pytest.mark.network
def test_get_v1_exchange_icons(coinapi: CoinAPI) -> None:
"""Test get_v1_exchange_icons."""
# we don't want to store the whole response in the repo, so we don't use vcr here
Expand All @@ -68,7 +68,7 @@ def test_get_v1_metadata(coinapi: CoinAPI) -> None:
assert res.content is not None


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_symbols(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
"""Test get_v1_symbols."""
res = coinapi.metadata.get_v1_symbols(filter_asset_id="XMR")
Expand All @@ -77,7 +77,7 @@ def test_get_v1_symbols(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
assert res.content == snapshot


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_symbols_map(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
"""Test get_v1_symbols_map."""
res = coinapi.metadata.get_v1_symbols_map_exchange_id("KRAKEN")
Expand All @@ -86,7 +86,7 @@ def test_get_v1_symbols_map(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> No
assert res.content == snapshot


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_symbols_exchange_id(
coinapi: CoinAPI,
snapshot: SnapshotAssertion,
Expand Down
12 changes: 6 additions & 6 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from coinapi.models import operations


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_metrics(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
"""Test get_v1_metrics."""
response = coinapi.metrics.get_v1_metrics_listing()
Expand All @@ -17,7 +17,7 @@ def test_get_v1_metrics(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
assert response.content == snapshot


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_metrics_exchange(coinapi: CoinAPI, snapshot: SnapshotAssertion) -> None:
"""Test get_v1_metrics_exchange_listing."""
response = coinapi.metrics.get_v1_metrics_exchange_listing(exchange_id="KRAKEN")
Expand All @@ -28,7 +28,7 @@ def test_get_v1_metrics_exchange(coinapi: CoinAPI, snapshot: SnapshotAssertion)


@pytest.mark.skip(reason="Returns 500")
@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_metrics_exchange_current(
coinapi: CoinAPI,
snapshot: SnapshotAssertion,
Expand All @@ -45,7 +45,7 @@ def test_get_v1_metrics_exchange_current(


@pytest.mark.skip(reason="What's a valid metric for an exchange?")
@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_metrics_exchange_history(
coinapi: CoinAPI,
snapshot: SnapshotAssertion,
Expand All @@ -62,7 +62,7 @@ def test_get_v1_metrics_exchange_history(
assert response.content == snapshot


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_metrics_symbol_listing(
coinapi: CoinAPI,
snapshot: SnapshotAssertion,
Expand All @@ -75,7 +75,7 @@ def test_get_v1_metrics_symbol_listing(
assert response.content == snapshot


@pytest.mark.vcr()
@pytest.mark.vcr
def test_get_v1_metrics_asset_listing(
coinapi: CoinAPI,
snapshot: SnapshotAssertion,
Expand Down
Loading
Loading