diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..e492f5f2 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,33 @@ +name: CI/CD Test + + +# Controls when the workflow will run +on: + push: + branches: + - CI-CD-test + # Triggers the workflow on push or pull request events but only for the develop branch + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: +jobs: + build: + strategy: + fail-fast: false + matrix: + os: [Linux, Windows, macOS] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install dependencies + if: matrix.os != 'Windows' + run: | + cd causalbench-asu/tests/ + bash -l test.sh + + - name: Install dependencies for Windows + if: matrix.os == 'Windows' + run: | + cd causalbench-asu/tests/ + .\test.bat diff --git a/causalbench-asu/tests/test-auth.py b/causalbench-asu/tests/test-auth.py new file mode 100644 index 00000000..8985250c --- /dev/null +++ b/causalbench-asu/tests/test-auth.py @@ -0,0 +1,30 @@ +import pytest +from causalbench.services.auth import init_auth +import jwt + +def is_jwt(token): + + # Split the token into parts + parts = token.split('.') + + # A valid JWT should have exactly 3 parts + if len(parts) != 3: + return False + + try: + header = jwt.get_unverified_header(token) + + return True + except Exception as e: + print(f"Invalid JWT token: {e}") + return False + + + + +# Take some config yaml file, and copy to its location. +## can be ignored for now as ertugrul's creds are already there. +response = init_auth() + +assert is_jwt(response), "Response is not in JWT format. Access token could not received" +print("Response is in JWT format and it is an access token.") \ No newline at end of file diff --git a/causalbench-asu/tests/test-data.py b/causalbench-asu/tests/test-data.py new file mode 100644 index 00000000..e8c5937f --- /dev/null +++ b/causalbench-asu/tests/test-data.py @@ -0,0 +1,17 @@ +from causalbench.modules import Dataset +import pytest +import pandas as pd + +dataset_web = Dataset(module_id=2, version=1) +fetched_web = dataset_web.fetch() +data_web = Dataset(zip_file=fetched_web) +files_web = data_web.load() +assert isinstance(files_web["file1"].data, pd.DataFrame), "Dataset from causalbench could not be fetched." + + +dataset = Dataset(zip_file='data/abalone.zip') +files = dataset.load() +assert isinstance(files["file1"].data, pd.DataFrame), "Local data could not be extracted." + + +#dataset1.publish(public=False) diff --git a/causalbench-asu/tests/test-execute.py b/causalbench-asu/tests/test-execute.py new file mode 100644 index 00000000..16419c70 --- /dev/null +++ b/causalbench-asu/tests/test-execute.py @@ -0,0 +1,19 @@ +from causalbench.modules import Run +from causalbench.modules.context import Context + +def main(): + + # Select and fetch the Context + context1: Context = Context(module_id=1, version=1) + + # Run selected Context + run: Run = context1.execute() + + # Print Run execution results + print(run) + + # Publish the Run + run.publish() + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/causalbench-asu/tests/test-metric.py b/causalbench-asu/tests/test-metric.py new file mode 100644 index 00000000..75fe91b6 --- /dev/null +++ b/causalbench-asu/tests/test-metric.py @@ -0,0 +1,10 @@ +from causalbench.modules import Metric + +metric_web = Metric(module_id=1, version=1) +metric_path = metric_web.fetch() +metric_web = Metric(zip_file=metric_path) +assert metric_web.type=="metric", "Metric could not be fetched from web." + +metric_local = Metric(zip_file='metric/accuracy_static.zip') +assert metric_local.type=="metric", "Metric could not be fetched from web." +#metric_local.publish(public=True) \ No newline at end of file diff --git a/causalbench-asu/tests/test-model.py b/causalbench-asu/tests/test-model.py new file mode 100644 index 00000000..13271cc4 --- /dev/null +++ b/causalbench-asu/tests/test-model.py @@ -0,0 +1,12 @@ +from causalbench.modules import Model + + +model_web = Model(module_id=4, version=1) +model_path = model_web.fetch() +model1 = Model(zip_file=model_path) +#model1.publish(public=True) +assert model1.type=="model", "Model could not be fetched from web." + +model2 = Model(zip_file='model/ges.zip') +#model2.publish(public=True) +assert model2.type=="model", "Local model could not be extracted." diff --git a/causalbench-asu/tests/test-task.py b/causalbench-asu/tests/test-task.py new file mode 100644 index 00000000..c61b47c5 --- /dev/null +++ b/causalbench-asu/tests/test-task.py @@ -0,0 +1,5 @@ +from causalbench.modules.task import Task + +task: Task = Task(module_id='discovery.temporal') +task.load() +assert task.type=="task", "Task could not be fetched from web." diff --git a/causalbench-asu/tests/test.bat b/causalbench-asu/tests/test.bat new file mode 100644 index 00000000..25f06f96 --- /dev/null +++ b/causalbench-asu/tests/test.bat @@ -0,0 +1,32 @@ +@echo off +echo Creating conda environment... +call conda create -n causal-test python=3.10 -y +echo Conda environment is created +call conda activate causal-test +echo Conda environment is activated +cd ../.. +echo Building package... + +# Model dependicies are not installed automatically so needs to be installed manually until fix +pip install gcastle +pip install torch + +pip install build +python -m build +for /f "delims=" %%f in ('dir /b /o-d dist\*.whl') do pip install dist\%%f & goto :end +:end +pip install PyJWT +pip install pytest +cd causalbench-asu\tests +echo "Test system" +python test-execute.py +echo "Test login function" +python test-auth.py +echo "Test dataset functions" +python test-data.py +echo "Test model functions" +python test-model.py +echo "Test metric functions" +python test-metric.py +echo "Test task functions" +python test-task.py diff --git a/causalbench-asu/tests/test.sh b/causalbench-asu/tests/test.sh new file mode 100644 index 00000000..d874f8ee --- /dev/null +++ b/causalbench-asu/tests/test.sh @@ -0,0 +1,30 @@ +echo "Creating conda environment..." +conda create -n causal-test python=3.10 -y +echo Conda environment is created +conda activate causal-test +echo Conda environment is activated +cd ../.. +echo "Building package..." + +# Model dependicies are not installed automatically so needs to be installed manually until fix +pip install gcastle +pip install torch + +pip install build +python -m build +pip install $(ls dist/*.whl | sort | tail -n 1) +pip install pytest +pip install PyJWT +cd causalbench-asu/tests +echo "Test system" +python test-execute.py +echo "Test login function" +python test-auth.py +echo "Test dataset functions" +python test-data.py +echo "Test model functions" +python test-model.py +echo "Test metric functions" +python test-metric.py +echo "Test task functions" +python test-task.py diff --git a/pyproject.toml b/pyproject.toml index d690fda3..43888f46 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "causalbench-asu" -version = "0.1rc1" +version = "0.1rc3" authors = [ { name="CausalBench Team", email="support@causalbench.org"} ] @@ -26,7 +26,6 @@ classifiers = [ ] dependencies = [ - "gputil", "requests", "pyyaml", "bunch_py3", @@ -36,9 +35,8 @@ dependencies = [ "psutil", "py-cpuinfo", "pip-system-certs", - "pyadl", - "gcastle", - "torch~=2.3.0" + "gputil", + "pyadl" ] [project.urls] @@ -51,4 +49,4 @@ Issues = "https://github.com/EmitLab/CausalBench/issues" only-include = ["causalbench-asu"] [tool.hatch.build.targets.wheel] -packages = ["causalbench-asu/causalbench"] \ No newline at end of file +packages = ["causalbench-asu/causalbench"]