Skip to content

Commit

Permalink
Init pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
Croydon committed May 18, 2024
1 parent 706737f commit 661ff5d
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 8 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/remote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
python-version: ${{ matrix.python_version }}
- name: Install package
run: |
pip install .
pip install .[dev]
- name: Start Local Server
run: |
bincrafters-conan-remote run & disown
Expand All @@ -55,7 +55,7 @@ jobs:
conan remote remove conancenter
conan remote add inexorgame "http://127.0.0.1:8042/r/github+bincrafters_remote+testing_v-998+inexorgame/"
conan remote list
- name: Tests
- name: Direct Tests
run: |
# conan download latest revision
conan download -r inexorgame --recipe InexorGlueGen/0.6.11@inexorgame/stable
Expand All @@ -67,6 +67,10 @@ jobs:
conan remote remove inexorgame
conan remote add inexorgame "http://127.0.0.1:8042/"
conan download --recipe Protobuf/3.5.1@inexorgame/stable#0
- name: Pytest
run: |
pytest bincrafters_conan_remote/test -vv -s
deploy:
name: Deploy to PyPi
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ dist/
env/
venv
.pytest_cache/
__test_c/
__test_conan_home/
3 changes: 2 additions & 1 deletion bincrafters_conan_remote/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async def get_external_site(request: Request, url_path: str):

def _shell(command: str, check: bool=True) -> str:
logger.info(f"Run: {command}")
process = subprocess.run(command, shell=True, check=check, stdout=subprocess.PIPE, universal_newlines=True)
process = subprocess.run(command, shell=True, check=check, stdout=subprocess.PIPE, text=True)
logger.info(f"Out: {process.stdout}")
return process.stdout

Expand All @@ -137,6 +137,7 @@ def run_generate(args):
remote_url_quoted = "{" + args.remote_url + "}"

server_thread = threading.Thread(target=_run_uvicorn, args=(_PORT,))
server_thread.daemon = True
server_thread.start()

# uvicorn.run(app, host="0.0.0.0", port=_PORT, log_level="info")
Expand Down
6 changes: 6 additions & 0 deletions bincrafters_conan_remote/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import os
import tarfile
import threading
import uvicorn

from fastapi import FastAPI, Request
Expand Down Expand Up @@ -177,3 +178,8 @@ async def get_external_site(request: Request, url_path: str):

def run_remote(args):
uvicorn.run(app, host="0.0.0.0", port=args.port)

def run_remote_in_thread(args):
t = threading.Thread(target=run_remote, args=(args,))
t.daemon = True
t.start()
1 change: 1 addition & 0 deletions bincrafters_conan_remote/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
conan==1.*
pytest>=7, <9.0.0
Empty file.
22 changes: 22 additions & 0 deletions bincrafters_conan_remote/test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
import shutil
import time

from types import SimpleNamespace

from bincrafters_conan_remote.remote import run_remote_in_thread
from bincrafters_conan_remote.test.helpers import cli_command, env_vars


@pytest.fixture(scope="session", autouse=True)
def setup_module():
run_remote_in_thread(SimpleNamespace(port=8042))
print("Sleeping for 10 seconds...")
time.sleep(10)
print("Done sleeping")
shutil.rmtree(env_vars["CONAN_HOME"], ignore_errors=True)
cli_command(["conan", "user"]) # TODO: Switch ConanV1 / ConanV2
cli_command(["conan", "config", "set", "general.revisions_enabled=1"]) # TODO: Switch ConanV1 / ConanV2
cli_command(["conan", "remote", "remove", "conancenter"])
cli_command(["conan", "remote", "add", "inexorgame", "http://127.0.0.1:8042/r/github+bincrafters_remote+testing_v-998+inexorgame/", "False"])
cli_command(["conan", "remote", "list"], expected_outputs=["inexorgame",])
24 changes: 24 additions & 0 deletions bincrafters_conan_remote/test/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import List

import os
import subprocess

_test_dir = os.path.dirname(os.path.abspath(__file__))
env_vars = {
"CONAN_HOME": os.path.join(_test_dir, "__test_conan_home"), # ConanV2
"CONAN_USER_HOME": os.path.join(_test_dir, "__test_conan_home"), # ConanV1
"CONAN_USER_HOME_SHORT": os.path.join(_test_dir, "__test_c"), # ConanV1
"CONAN_LOGGING_LEVEL": "10",
}

def _run_command(command:List[str]):
return subprocess.run(command, capture_output=True, text=True, env=env_vars)

def cli_command(command:List[str], expected_returncode:int=0, expected_outputs:List[str]=[]):
result = _run_command(command)

print(f"{result.returncode} == {expected_returncode}: {result.stdout}")
assert result.returncode == expected_returncode

for expected_output in expected_outputs:
assert expected_output in result.stdout
15 changes: 15 additions & 0 deletions bincrafters_conan_remote/test/test_download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from bincrafters_conan_remote.test.helpers import cli_command

import pytest
import time

def test_download_revision_latest():
print("Sleeping for 25 seconds...")
time.sleep(25)
cli_command(
["conan", "download", "-r", "inexorgame", "--recipe", "InexorGlueGen/0.6.11@inexorgame/stable"],
expected_outputs=[
"Downloading conanmanifest.txt",
"Downloading conanfile.py",
"Downloading conan_sources.tgz"]
)
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ This tool is something like a locally run proxy server to provide the Conan clie
* Features that are covered by both v1 and v2 of the REST API will only be supported via the v2 API
* Only Conan 1.* is explicitly supported for now, altough the REST API does not seem to be Conan 1/2 specific. So Conan v2 might just work
* Only Python >= 3.8 is supported. Conan itself supports >= 3.6
* From the point-of-view of the Conan client this remote is ready-only by design. No upload, no deletion etc.
* Currently not planned to support:
* conan remove


## TODO
Expand All @@ -31,6 +32,8 @@ This tool is something like a locally run proxy server to provide the Conan clie
* conan search
* conan download
* conan install
* conan user
* conan upload
* get overview conan command / patch / server request that we want to support
* Write tests for all conan cli command that we want to cover
* Figure out if the Conan client supports download package downloads from an absolut URL or only relatives one
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_requires(filename):


project_requirements = get_requires(os.path.join("bincrafters_conan_remote", "requirements.txt"))
# dev_requirements = get_requires(os.path.join("bincrafters_conan_remote", "requirements_dev.txt"))
dev_requirements = get_requires(os.path.join("bincrafters_conan_remote", "requirements_dev.txt"))


setup(
Expand Down Expand Up @@ -91,10 +91,10 @@ def get_requires(filename):
# dependencies). You can install these using the following syntax,
# for example:
# $ pip install -e .[dev,test]
# extras_require={
# 'dev': dev_requirements,
extras_require={
"dev": dev_requirements,
# 'test': dev_requirements,
#},
},

# If there are data files included in your packages that need to be
# installed, specify them here.
Expand Down

0 comments on commit 661ff5d

Please sign in to comment.