-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fix e2e test with pytest-playwright, use ruff, use pre-commit,
- Loading branch information
Showing
29 changed files
with
661 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Lint | ||
on: [push, pull_request] | ||
jobs: | ||
ruff: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: chartboost/ruff-action@v1 | ||
with: | ||
args: 'format --check' | ||
sonarcloud: | ||
name: SonarCloud | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
- name: SonarCloud Scan | ||
uses: SonarSource/sonarcloud-github-action@master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
build-and-publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.10 | ||
|
||
- name: Install Poetry | ||
run: | | ||
pip install poetry | ||
poetry install | ||
- name: Build and Publish | ||
env: | ||
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }} | ||
run: | | ||
poetry publish --build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Pytest with Playwright | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.10, 3.11] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
pip install poetry | ||
poetry install | ||
- name: Install Playwright browsers | ||
run: | | ||
poetry run playwright install | ||
- name: Run pytest with Playwright | ||
run: | | ||
poetry run pytest e2e/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
repos: | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.5.4 | ||
hooks: | ||
# Run the linter. | ||
- id: ruff | ||
args: [ --fix ] | ||
# Run the formatter. | ||
- id: ruff-format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import json | ||
from pathlib import Path | ||
|
||
import pytest | ||
from e2e_utils import StreamlitRunner | ||
from playwright.sync_api import Page, expect | ||
|
||
ROOT_DIRECTORY = Path(__file__).parent.parent.absolute() | ||
BASIC_EXAMPLE_FILE = ROOT_DIRECTORY / "textcomplete" / "example.py" | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="module") | ||
def streamlit_app(): | ||
with StreamlitRunner(BASIC_EXAMPLE_FILE, 8502) as runner: | ||
yield runner | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="function") | ||
def go_to_app(page: Page, streamlit_app: StreamlitRunner): | ||
page.goto(streamlit_app.server_url) | ||
# Wait for app to load | ||
page.get_by_role("img", name="Running...").is_hidden() | ||
|
||
|
||
def test_should_render_textcomplete(page: Page): | ||
st_text_area = page.get_by_label("Streamlit Autocomplete") | ||
expect(st_text_area).to_be_visible() | ||
# Retrieve the value of the "data-textcomplete" attribute | ||
data_textcomplete_value = st_text_area.get_attribute("data-textcomplete") | ||
|
||
# Parse the JSON value | ||
assert isinstance( | ||
json.loads(data_textcomplete_value), dict | ||
), "'data-textcomplete' is not a valid JSON object" | ||
|
||
# Append "s" to the textarea to trigger the dropdown | ||
st_text_area.focus() | ||
st_text_area.evaluate("e => e.setSelectionRange(-1, -1)") | ||
st_text_area.type("s") | ||
# Wait for the dropdown to become visible | ||
dropdown = page.query_selector("ul.textcomplete-dropdown") | ||
dropdown.wait_for_element_state("visible") | ||
# Find li element in dropdown | ||
dropdown_li = dropdown.query_selector("li.textcomplete-item") | ||
assert dropdown_li.inner_text() == "🧑🏻 Mrs. Dennis Schulist" | ||
dropdown_li.press("Enter") | ||
dropdown.wait_for_element_state("hidden") | ||
assert st_text_area.input_value() == "Hello, this is textcomplete demo Mrs. Dennis Schulist" | ||
# Append space to the textarea to make original react component state updated | ||
st_text_area.type(" ") | ||
st_text_area.blur() | ||
assert st_text_area.input_value() == "Hello, this is textcomplete demo Mrs. Dennis Schulist " |
Oops, something went wrong.