From e6b25ae117e312177d39adcfa8a687ea6307c14a Mon Sep 17 00:00:00 2001 From: Alexey Snigir Date: Thu, 2 Nov 2023 16:36:25 +0100 Subject: [PATCH 1/3] fix path --- .../workflows/test-integration-vizro-ai.yml | 112 +++++++++--------- ...lexey_snigir_vizro_ai_integration_tests.md | 48 ++++++++ vizro-ai/hatch.toml | 5 +- vizro-ai/tests/integration/test_example.py | 51 ++++++++ 4 files changed, 159 insertions(+), 57 deletions(-) create mode 100644 vizro-ai/changelog.d/20231102_163517_alexey_snigir_vizro_ai_integration_tests.md create mode 100644 vizro-ai/tests/integration/test_example.py diff --git a/.github/workflows/test-integration-vizro-ai.yml b/.github/workflows/test-integration-vizro-ai.yml index 4671d1d37..9f814676c 100644 --- a/.github/workflows/test-integration-vizro-ai.yml +++ b/.github/workflows/test-integration-vizro-ai.yml @@ -1,55 +1,57 @@ -#name: test-integration-vizro-ai -# -#defaults: -# run: -# working-directory: vizro-core -# -##### TODO: adjust below according to other scripts -#on: -# # push: -# # branches: [main] -# pull_request: -# # branches: -# # - "main" -# -#concurrency: -# group: test-integration-${{ github.head_ref }} -# cancel-in-progress: true -# -#env: -# PYTHONUNBUFFERED: "1" -# FORCE_COLOR: "1" -# -#jobs: -# run: -# name: Python ${{ matrix.python-version }} on ${{ matrix.os }} -# runs-on: ${{ matrix.os }} -# strategy: -# fail-fast: false -# matrix: -# os: [ubuntu-latest, windows-latest] -# python-version: ["3.9", "3.10", "3.11"] -# -# steps: -# - uses: actions/checkout@v4 -# - name: Get branch name -# id: branch-name -# uses: tj-actions/branch-names@v7 -# -# - name: Set up Python ${{ matrix.python-version }} -# uses: actions/setup-python@v4 -# with: -# python-version: ${{ matrix.python-version }} -# -# - uses: actions/cache@v3 -# with: -# path: ${{ env.pythonLocation }} -# key: ${{ matrix.os }}-${{ matrix.python-version }}-${{ steps.branch-name.outputs.current_branch }}-pip-${{ hashFiles('hatch.toml') }}-${{ hashFiles('pyproject.toml') }} -# restore-keys: | -# ${{ matrix.os }}-${{ matrix.python-version }}-${{ steps.branch-name.outputs.current_branch }}-pip- -# -# - name: Run ubuntu integration tests -# if: ${{ matrix.os == 'ubuntu-latest' }} -# run: | -# pip install --upgrade hatch -# hatch run all.py${{ matrix.python-version }}:test-integration +name: test-integration-vizro-ai + +defaults: + run: + working-directory: vizro-ai + +on: + # push: + # branches: [main] + pull_request: + # branches: + # - "main" + +concurrency: + group: test-integration-${{ github.head_ref }} + cancel-in-progress: true + +env: + PYTHONUNBUFFERED: "1" + FORCE_COLOR: "1" + +jobs: + run: + name: Python ${{ matrix.python-version }} on Linux + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }} + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Hatch + run: pip install --upgrade hatch + + - name: Run vizro-ai integration tests with pypi vizro + run: | + export OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} + export OPENAI_API_BASE=${{ secrets.OPENAI_API_BASE }} + hatch run all.py${{ matrix.python-version }}:test-integration + + - name: Run vizro-ai integration tests with local vizro + run: | + export OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} + export OPENAI_API_BASE=${{ secrets.OPENAI_API_BASE }} + cd ../vizro-core + hatch build + cd ../vizro-ai + hatch run all.py${{ matrix.python-version }}:pip install ../vizro-core/dist/vizro*.tar.gz + hatch run all.py${{ matrix.python-version }}:test-integration diff --git a/vizro-ai/changelog.d/20231102_163517_alexey_snigir_vizro_ai_integration_tests.md b/vizro-ai/changelog.d/20231102_163517_alexey_snigir_vizro_ai_integration_tests.md new file mode 100644 index 000000000..f1f65e73c --- /dev/null +++ b/vizro-ai/changelog.d/20231102_163517_alexey_snigir_vizro_ai_integration_tests.md @@ -0,0 +1,48 @@ + + + + + + + + + diff --git a/vizro-ai/hatch.toml b/vizro-ai/hatch.toml index 65a6479ff..1adbb5978 100644 --- a/vizro-ai/hatch.toml +++ b/vizro-ai/hatch.toml @@ -15,7 +15,8 @@ dependencies = [ "coverage[toml]>=6.5", "pytest", "toml", - "nbformat>=4.2.0" + "nbformat>=4.2.0", + "pyhamcrest" ] [envs.default.env-vars] @@ -46,7 +47,7 @@ test = [ ] test-cov = "coverage run -m pytest tests/unit {args}" test-integration = [ - "pytest tests/integration {args}" + "pytest -v tests/integration" ] test-unit = "pytest tests/unit {args}" update-snyk-requirements = "python ../tools/generate_snyk_requirements.py {args}" diff --git a/vizro-ai/tests/integration/test_example.py b/vizro-ai/tests/integration/test_example.py new file mode 100644 index 000000000..585bacff0 --- /dev/null +++ b/vizro-ai/tests/integration/test_example.py @@ -0,0 +1,51 @@ +import plotly.express as px +from hamcrest import all_of, any_of, assert_that, contains_string, equal_to +from vizro_ai import VizroAI + +vizro_ai = VizroAI() +df = px.data.gapminder() + + +def test_chart(): + vizro_ai._return_all_text = True + resp = vizro_ai.plot(df, "describe the composition of scatter chart with gdp in continent") + assert_that( + resp["code_string"], + all_of( + contains_string("px.scatter"), + contains_string("x='continent'"), + contains_string("y='gdpPercap'"), + ), + ) + assert_that(resp["business_insights"], equal_to(None)) + assert_that(resp["code_explanation"], equal_to(None)) + + +def test_chart_with_explanation(): + vizro_ai._return_all_text = True + resp = vizro_ai.plot( + df, + "describe the composition of gdp in US", + explain=True, + ) + assert_that( + resp["code_string"], + all_of( + contains_string("px.bar"), + contains_string("x='year'"), + contains_string("y='gdpPercap'"), + ), + ) + assert_that( + resp["business_insights"], + any_of( + contains_string("GDP in the United States"), + contains_string("GDP in the US"), + ), + ) + assert_that( + resp["code_explanation"], + all_of( + contains_string("https://vizro.readthedocs.io/en/stable/pages/user_guides/custom_charts/"), + ), + ) From 87beff666839865ac7c5f090991b283e1fdbeba1 Mon Sep 17 00:00:00 2001 From: Alexey Snigir Date: Fri, 3 Nov 2023 16:08:30 +0100 Subject: [PATCH 2/3] updated version to 0.1.0.dev2 --- vizro-ai/src/vizro_ai/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vizro-ai/src/vizro_ai/__init__.py b/vizro-ai/src/vizro_ai/__init__.py index 3aa85e51e..12f83fd32 100644 --- a/vizro-ai/src/vizro_ai/__init__.py +++ b/vizro-ai/src/vizro_ai/__init__.py @@ -5,6 +5,6 @@ __all__ = ["VizroAI"] -__version__ = "0.1.0.dev0" +__version__ = "0.1.0.dev2" logging.basicConfig(level=os.getenv("VIZRO_AI_LOG_LEVEL", "INFO")) From 9fff8136053cc282abea63b9f833ae975f43fe92 Mon Sep 17 00:00:00 2001 From: Alexey Snigir Date: Mon, 6 Nov 2023 12:31:52 +0100 Subject: [PATCH 3/3] uncomment running conditions --- .github/workflows/test-integration-vizro-ai.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-integration-vizro-ai.yml b/.github/workflows/test-integration-vizro-ai.yml index 9f814676c..7095db15f 100644 --- a/.github/workflows/test-integration-vizro-ai.yml +++ b/.github/workflows/test-integration-vizro-ai.yml @@ -5,11 +5,11 @@ defaults: working-directory: vizro-ai on: - # push: - # branches: [main] + push: + branches: [main] pull_request: - # branches: - # - "main" + branches: + - "main" concurrency: group: test-integration-${{ github.head_ref }}