diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..a7f33c86 --- /dev/null +++ b/.github/workflows/test.yaml @@ -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 }} diff --git a/ipfshttpclient/client/__init__.py b/ipfshttpclient/client/__init__.py index ec9e525f..cc99eabc 100644 --- a/ipfshttpclient/client/__init__.py +++ b/ipfshttpclient/client/__init__.py @@ -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 diff --git a/test/functional/test_block.py b/test/functional/test_block.py index 5cc8175d..7c0a7e63 100644 --- a/test/functional/test_block.py +++ b/test/functional/test_block.py @@ -1,12 +1,15 @@ +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" @@ -14,24 +17,74 @@ 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() diff --git a/tox.ini b/tox.ini index 56584c6e..a2accd3c 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ [tox] minversion = 3.3 envlist = - py3, + py{37,38,39}-{linux,macos,windows}, py3-httpx, styleck, typeck @@ -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} @@ -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 \ No newline at end of file