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

chore: use github actions for ci & fix failing tests #320

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
59 changes: 59 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: test

on:
push:
branches:
- main

pull_request:

jobs:
test:
runs-on: ${{ matrix.platform }}
strategy:
matrix:
platform: [ ubuntu-latest, macos-latest, windows-latest ]
python-version: [ '3.7', '3.8', '3.9' ]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- uses: ibnesayeed/setup-ipfs@master
with:
ipfs_version: 0.19.2

- name: install deps
run: |
python -m pip install --upgrade pip
python -m pip install tox-gh-actions

- name: tox
run: tox
env:
PYTHON_VER: ${{ matrix.python-version }}
PLATFORM: ${{ matrix.platform }}

check:
runs-on: ubuntu-latest
strategy:
matrix:
toxenv: [ styleck, typeck, py3-httpx ]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: install deps
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions

- name: tox
run: tox
env:
TOXENV: ${{ matrix.toxenv }}
2 changes: 1 addition & 1 deletion ipfshttpclient/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# for it to be considered compatible.
VERSION_MINIMUM = "0.5.0"
VERSION_BLACKLIST = []
VERSION_MAXIMUM = "0.9.0"
VERSION_MAXIMUM = "0.19.0"

from . import base
from . import bitswap
Expand Down
67 changes: 60 additions & 7 deletions test/functional/test_block.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,90 @@
import sys

import cid
import io
import pytest

import conftest

TEST1_FILEPATH = conftest.TEST_DIR / "fake_dir" / "fsdfgh"
TEST1_CID_STR = "QmPevo2B1pwvDyuZyJbWVfhwkaGPee3f1kX36wFmqx1yna"
TEST1_SIZE = 8
TEST1_FILEPATH = conftest.TEST_DIR / "fake_dir" / "fsdfgh"
TEST1_CIDV0_STR = "QmPevo2B1pwvDyuZyJbWVfhwkaGPee3f1kX36wFmqx1yna"
TEST1_CIDV1_STR = "bafkreiatrjkbyc7fz4ain4lpdv7els2cr7h55bjzrg6pg2oo2sf47hmmum"
TEST1_SIZE = 8

TEST2_CONTENT = b"Hello World!"
TEST2_CID_STR = "bafkreid7qoywk77r7rj3slobqfekdvs57qwuwh5d2z3sqsw52iabe3mqne"
TEST2_CID_OBJ = cid.make_cid(TEST2_CID_STR)
TEST2_SIZE = len(TEST2_CONTENT)


@pytest.mark.dependency()
def minversion(version):
import ipfshttpclient

try:
with ipfshttpclient.connect():
with ipfshttpclient.Client(offline=False) as ipfsclient:
max_version = tuple(map(int, version.split('-', 1)[0].split('.')))
daemon_version = tuple(map(int, ipfsclient.version().get('Version').split('-', 1)[0].split('.')))
return pytest.mark.skipif(
daemon_version < max_version, reason=f"Requires at least v{max_version}"
)
except ipfshttpclient.exceptions.Error as e:
print('\nFailed to connect to IPFS client', file=sys.stderr)
print(e, file=sys.stderr)

return False
else:
return True


def maxversion(version):
import ipfshttpclient

try:
with ipfshttpclient.connect():
with ipfshttpclient.Client(offline=False) as ipfsclient:
max_version = tuple(map(int, version.split('-', 1)[0].split('.')))
daemon_version = tuple(map(int, ipfsclient.version().get('Version').split('-', 1)[0].split('.')))
return pytest.mark.skipif(
daemon_version > max_version, reason=f"Incompatible with >= v{max_version}"
)
except ipfshttpclient.exceptions.Error as e:
print('\nFailed to connect to IPFS client', file=sys.stderr)
print(e, file=sys.stderr)

return False
else:
return True


@maxversion("0.12.9")
@pytest.mark.dependency
def test_put(client):
expected_keys = {"Key", "Size"}
res = client.block.put(TEST1_FILEPATH)
assert set(res.keys()).issuperset(expected_keys)
assert res["Key"] == TEST1_CID_STR
assert res["Key"] == TEST1_CIDV0_STR


@minversion("0.13.0")
@pytest.mark.dependency
def test_put_cidv1(client):
expected_keys = {"Key", "Size"}
res = client.block.put(TEST1_FILEPATH)
assert set(res.keys()).issuperset(expected_keys)
assert res["Key"] == TEST1_CIDV1_STR


@pytest.mark.dependency(depends=["test_put"])
def test_stat(client):
expected_keys = {"Key", "Size"}
res = client.block.stat(TEST1_CID_STR)
res = client.block.stat(TEST1_CIDV0_STR)
assert set(res.keys()).issuperset(expected_keys)


@pytest.mark.dependency(depends=["test_put"])
def test_get(client):
assert len(client.block.get(TEST1_CID_STR)) == TEST1_SIZE
assert len(client.block.get(TEST1_CIDV0_STR)) == TEST1_SIZE


@pytest.mark.dependency()
Expand Down
14 changes: 12 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[tox]
minversion = 3.3
envlist =
py3,
py{37,38,39}-{linux,macos,windows},
py3-httpx,
styleck,
typeck
Expand All @@ -24,7 +24,7 @@ deps =
py-cid

whitelist_externals = ipfs
passenv = IPFS_* PY_IPFS_HTTP_CLIENT_*
passenv = IPFS_*,PY_IPFS_HTTP_CLIENT_*
commands =
python -X utf8 "{toxinidir}/test/run-tests.py" {posargs}

Expand Down Expand Up @@ -155,3 +155,13 @@ testpaths =
ipfshttpclient
test/unit
test/functional

[gh-actions:env]
PYTHON_VER =
3.7: py37
3.8: py38
3.9: py39
PLATFORM =
ubuntu-latest: linux
macos-latest: macos
windows-latest: windows