mirror of
https://github.com/tcsenpai/Zundler.git
synced 2025-06-06 03:25:28 +00:00
Add test cases
This commit is contained in:
parent
68991a56d6
commit
4f41fbf64e
6
noxfile.py
Normal file
6
noxfile.py
Normal file
@ -0,0 +1,6 @@
|
||||
import nox
|
||||
|
||||
@nox.session()
|
||||
def tests(session):
|
||||
session.install(".[tests]")
|
||||
session.run("pytest", '--driver=firefox', *session.posargs)
|
@ -55,3 +55,17 @@ follow_imports = "skip"
|
||||
incremental = true
|
||||
check_untyped_defs = true
|
||||
warn_unused_ignores = true
|
||||
|
||||
[project.optional-dependencies]
|
||||
tests = [
|
||||
'pytest>=8',
|
||||
'selenium',
|
||||
'pytest-selenium',
|
||||
]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
minversion = "6.0"
|
||||
addopts = "-ra -q"
|
||||
testpaths = [
|
||||
"tests",
|
||||
]
|
||||
|
33
tests/conftest.py
Normal file
33
tests/conftest.py
Normal file
@ -0,0 +1,33 @@
|
||||
import pytest
|
||||
import subprocess
|
||||
from selenium import webdriver
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def firefox_driver():
|
||||
_driver = webdriver.Firefox()
|
||||
yield _driver
|
||||
_driver.quit()
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def chrome_driver():
|
||||
_driver = webdriver.Chrome()
|
||||
yield _driver
|
||||
_driver.quit()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def run_make_commands(request):
|
||||
# Get the directory of the current test file
|
||||
test_dir = request.fspath.dirname
|
||||
cmd = """
|
||||
uv venv && \\
|
||||
. .venv/bin/activate && \\
|
||||
uv pip install -r requirements.txt && \\
|
||||
.venv/bin/sphinx-build -M zundler . _build
|
||||
"""
|
||||
|
||||
for d in ["copy-button", "mermaid", "multi-page"]:
|
||||
subprocess.run(cmd.strip(), shell=True, check=True, cwd=Path(test_dir) / d)
|
12
tests/copy-button/conf.py
Normal file
12
tests/copy-button/conf.py
Normal file
@ -0,0 +1,12 @@
|
||||
from sphinx.application import Sphinx
|
||||
|
||||
project = 'copy-button'
|
||||
copyright = '2024, Adrian Vollmer'
|
||||
author = 'Adrian Vollmer'
|
||||
version = '0.0.1'
|
||||
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
extensions = [
|
||||
"sphinx_copybutton",
|
||||
]
|
3
tests/copy-button/index.rst
Normal file
3
tests/copy-button/index.rst
Normal file
@ -0,0 +1,3 @@
|
||||
.. code:: python
|
||||
|
||||
Copy me
|
3
tests/copy-button/requirements.txt
Normal file
3
tests/copy-button/requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
sphinx
|
||||
sphinx-copybutton
|
||||
../..
|
12
tests/mermaid/conf.py
Normal file
12
tests/mermaid/conf.py
Normal file
@ -0,0 +1,12 @@
|
||||
from sphinx.application import Sphinx
|
||||
|
||||
project = 'mermaid'
|
||||
copyright = '2024, Adrian Vollmer'
|
||||
author = 'Adrian Vollmer'
|
||||
version = '0.0.1'
|
||||
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
||||
|
||||
extensions = [
|
||||
'sphinxcontrib.mermaid'
|
||||
]
|
17
tests/mermaid/index.rst
Normal file
17
tests/mermaid/index.rst
Normal file
@ -0,0 +1,17 @@
|
||||
.. mermaid::
|
||||
|
||||
sequenceDiagram
|
||||
participant Alice
|
||||
participant Bob
|
||||
Alice->John: Hello John, how are you?
|
||||
loop Healthcheck
|
||||
John->John: Fight against hypochondria
|
||||
end
|
||||
Note right of John: Rational thoughts <br/>prevail...
|
||||
John-->Alice: Great!
|
||||
John->Bob: How about you?
|
||||
Bob-->John: Jolly good!
|
||||
|
||||
|
||||
Section
|
||||
=======
|
3
tests/mermaid/requirements.txt
Normal file
3
tests/mermaid/requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
sphinx
|
||||
sphinxcontrib-mermaid
|
||||
../..
|
8
tests/multi-page/conf.py
Normal file
8
tests/multi-page/conf.py
Normal file
@ -0,0 +1,8 @@
|
||||
from sphinx.application import Sphinx
|
||||
|
||||
project = 'multi-page'
|
||||
copyright = '2024, Adrian Vollmer'
|
||||
author = 'Adrian Vollmer'
|
||||
version = '0.0.1'
|
||||
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
6
tests/multi-page/first.rst
Normal file
6
tests/multi-page/first.rst
Normal file
@ -0,0 +1,6 @@
|
||||
.. _first:
|
||||
|
||||
First
|
||||
=====
|
||||
|
||||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
|
18
tests/multi-page/index.rst
Normal file
18
tests/multi-page/index.rst
Normal file
@ -0,0 +1,18 @@
|
||||
Welcome
|
||||
=======
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: Contents:
|
||||
|
||||
first
|
||||
second
|
||||
third
|
||||
|
||||
|
||||
Chapters
|
||||
========
|
||||
|
||||
* :ref:`first`
|
||||
* :ref:`second`
|
||||
* :ref:`third`
|
2
tests/multi-page/requirements.txt
Normal file
2
tests/multi-page/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
sphinx
|
||||
../..
|
6
tests/multi-page/second.rst
Normal file
6
tests/multi-page/second.rst
Normal file
@ -0,0 +1,6 @@
|
||||
.. _second:
|
||||
|
||||
Second
|
||||
======
|
||||
|
||||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
|
6
tests/multi-page/third.rst
Normal file
6
tests/multi-page/third.rst
Normal file
@ -0,0 +1,6 @@
|
||||
.. _third:
|
||||
|
||||
Third
|
||||
=====
|
||||
|
||||
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
|
96
tests/test_zundler.py
Normal file
96
tests/test_zundler.py
Normal file
@ -0,0 +1,96 @@
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
|
||||
|
||||
TEST_DIR = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
def test_copy_button(selenium):
|
||||
path = TEST_DIR / "copy-button//_build//zundler//index.html"
|
||||
selenium.get(path.as_uri())
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
assert "copy-button documentation" in selenium.title
|
||||
|
||||
selenium.switch_to.frame("main")
|
||||
# Not sure why there are two buttons, but we need the second one.
|
||||
# The first cannot be clicked by selenium because it's obscured.
|
||||
|
||||
button = selenium.find_element(By.CSS_SELECTOR, "button.copybtn + button.copybtn")
|
||||
|
||||
assert button.get_attribute("data-tooltip") == "Copy"
|
||||
assert "success" not in button.get_attribute("class")
|
||||
|
||||
button.click()
|
||||
|
||||
assert button.get_attribute("data-tooltip") == "Copied!"
|
||||
assert "success" in button.get_attribute("class")
|
||||
|
||||
# Check layout
|
||||
assert button.location["y"] < 55
|
||||
assert button.location["y"] > 45
|
||||
|
||||
|
||||
def test_mermaid(selenium):
|
||||
path = TEST_DIR / "mermaid//_build//zundler//index.html"
|
||||
selenium.get(path.as_uri())
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
assert "mermaid documentation" in selenium.title
|
||||
|
||||
selenium.switch_to.frame("main")
|
||||
|
||||
section = selenium.find_element(By.CSS_SELECTOR, "#section")
|
||||
svg = selenium.find_element(By.CSS_SELECTOR, "div.mermaid")
|
||||
|
||||
# Check layout
|
||||
assert svg.size["height"] > 500
|
||||
assert section.location["y"] > 500
|
||||
|
||||
|
||||
def test_multi_page(selenium):
|
||||
path = TEST_DIR / "multi-page//_build//zundler//index.html"
|
||||
selenium.get(path.as_uri())
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
assert "multi-page documentation" in selenium.title
|
||||
|
||||
selenium.switch_to.frame("main")
|
||||
|
||||
second_link = selenium.find_element(By.XPATH, "//a[text() = 'Second' and @class = 'reference internal']")
|
||||
|
||||
second_link.click()
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
assert selenium.title.startswith("Second")
|
||||
|
||||
|
||||
def test_multi_page_search(selenium):
|
||||
path = TEST_DIR / "multi-page//_build//zundler//index.html"
|
||||
selenium.get(path.as_uri())
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
assert "multi-page documentation" in selenium.title
|
||||
|
||||
selenium.switch_to.frame("main")
|
||||
|
||||
searchbox = selenium.find_element(By.CSS_SELECTOR, "#searchbox input[type='text']")
|
||||
|
||||
searchbox.send_keys("Lorem" + Keys.ENTER)
|
||||
selenium.switch_to.parent_frame()
|
||||
time.sleep(2)
|
||||
selenium.switch_to.frame("main")
|
||||
|
||||
assert selenium.title.startswith("Search")
|
||||
|
||||
span = selenium.find_element(By.CSS_SELECTOR, "span.highlighted")
|
||||
|
||||
assert span.text == "Lorem"
|
Loading…
x
Reference in New Issue
Block a user