Consolidate pytest.ini with pyproject.toml & add test
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import streamlit as st
|
import streamlit as st
|
||||||
|
|
||||||
from streamlit import dialog
|
from streamlit import dialog
|
||||||
|
from tomlkit import key
|
||||||
|
|
||||||
from queries import crud, daily_stats, weekly_stats, monthly_stats, yearly_stats
|
from queries import crud, daily_stats, weekly_stats, monthly_stats, yearly_stats
|
||||||
from enums import CounterType
|
from enums import CounterType
|
||||||
|
|
||||||
@@ -76,13 +78,14 @@ with st.container(key="counter-table"):
|
|||||||
if counter_type is CounterType.SIMPLE.value:
|
if counter_type is CounterType.SIMPLE.value:
|
||||||
st.markdown(f"**{stats_current} {stats_current_unit}**")
|
st.markdown(f"**{stats_current} {stats_current_unit}**")
|
||||||
else:
|
else:
|
||||||
st.markdown(f"""
|
st.markdown(f"**{stats_current} {stats_current_unit}** *{stats_prev} {stats_prev_unit}*")
|
||||||
**{stats_current} {stats_current_unit}**
|
|
||||||
*{stats_prev} {stats_prev_unit}*
|
|
||||||
""")
|
|
||||||
|
|
||||||
with st.container(horizontal=True, width="stretch", horizontal_alignment="right"):
|
with st.container(horizontal=True, width="stretch", horizontal_alignment="right"):
|
||||||
st.page_link("pages/stats.py", icon=":material/bar_chart:", icon_position="right", label="", query_params={"counter_id": str(counter_id)})
|
st.page_link("pages/stats.py",
|
||||||
|
icon=":material/bar_chart:",
|
||||||
|
icon_position="right",
|
||||||
|
label="",
|
||||||
|
query_params={"counter_id": str(counter_id)})
|
||||||
|
|
||||||
st.html(f"""
|
st.html(f"""
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ dependencies = [
|
|||||||
"pytest-env (>=1.6.0,<2.0.0)"
|
"pytest-env (>=1.6.0,<2.0.0)"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["poetry-core>=1.0.0"]
|
||||||
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
|
||||||
[virtualenvs]
|
[virtualenvs]
|
||||||
in-project = true
|
in-project = true
|
||||||
create = true
|
create = true
|
||||||
@@ -35,6 +39,13 @@ pytest = ">=9.0"
|
|||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = ">=3.10,<4"
|
python = ">=3.10,<4"
|
||||||
|
|
||||||
[build-system]
|
[tool.pytest.ini_options]
|
||||||
requires = ["poetry-core>=1.0.0"]
|
log_cli = true
|
||||||
build-backend = "poetry.core.masonry.api"
|
log_cli_level = "INFO"
|
||||||
|
log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)"
|
||||||
|
log_cli_date_format="%Y-%m-%d %H:%M:%S"
|
||||||
|
pythonpath = "./app"
|
||||||
|
env = [
|
||||||
|
"DATABASE_FILE=testdb.sqlite",
|
||||||
|
"DATABASE_URL=sqlite:///testdb.sqlite?cache=shared"
|
||||||
|
]
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
[pytest]
|
|
||||||
log_cli = 1
|
|
||||||
log_cli_level = INFO
|
|
||||||
log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)
|
|
||||||
log_cli_date_format=%Y-%m-%d %H:%M:%S
|
|
||||||
pythonpath = ../app
|
|
||||||
env =
|
|
||||||
DATABASE_FILE=testdb.sqlite
|
|
||||||
DATABASE_URL=sqlite:///testdb.sqlite?cache=shared
|
|
||||||
|
|
||||||
@@ -7,6 +7,7 @@ def test_initial_state(app):
|
|||||||
assert not app.error
|
assert not app.error
|
||||||
assert len(app.header) == 0 # No counter currently present
|
assert len(app.header) == 0 # No counter currently present
|
||||||
|
|
||||||
|
|
||||||
def test_add_counter(app):
|
def test_add_counter(app):
|
||||||
app.run()
|
app.run()
|
||||||
|
|
||||||
@@ -31,6 +32,7 @@ def test_add_counter(app):
|
|||||||
assert len(app.header) == 1 # A new counter was added
|
assert len(app.header) == 1 # A new counter was added
|
||||||
assert app.header[0].value == ":material/calendar_clock: Walk"
|
assert app.header[0].value == ":material/calendar_clock: Walk"
|
||||||
|
|
||||||
|
|
||||||
def test_remove_counter(app):
|
def test_remove_counter(app):
|
||||||
|
|
||||||
# Create a counter to remove
|
# Create a counter to remove
|
||||||
@@ -57,3 +59,20 @@ def test_remove_counter(app):
|
|||||||
app.run()
|
app.run()
|
||||||
|
|
||||||
assert len(app.header) == 0 # No counter exists
|
assert len(app.header) == 0 # No counter exists
|
||||||
|
|
||||||
|
|
||||||
|
def test_increment_counter(app):
|
||||||
|
|
||||||
|
# Create a counter to increment
|
||||||
|
queries.crud.create_counter("Remove me", CounterType.SIMPLE, "020122")
|
||||||
|
|
||||||
|
app.run()
|
||||||
|
assert not app.exception
|
||||||
|
assert not app.error
|
||||||
|
|
||||||
|
assert len(app.header) == 1 # One counter exists
|
||||||
|
assert "0 times" in app.markdown[0].value # Counter is 0
|
||||||
|
|
||||||
|
app.button(key="increment_counter_1").click().run()
|
||||||
|
|
||||||
|
assert "1 times" in app.markdown[0].value # Counter is 1
|
||||||
|
|||||||
Reference in New Issue
Block a user