Skip to content

Commit

Permalink
Merge pull request #100 from eoyilmaz/99-create-tox-config
Browse files Browse the repository at this point in the history
[#99] Added `tox` section to `pyproject.toml` file.
  • Loading branch information
eoyilmaz authored Nov 5, 2024
2 parents 6883132 + ecf9672 commit 72b6dfc
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 98 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:

name: Python ${{ matrix.python-version }} & PostgreSQL ${{ matrix.postgresql-version }}
env:
# PGPASSFILE: ~/.pgpass
PGPASSWORD: postgres
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -57,15 +56,6 @@ jobs:
# When "true", encrypt connections using SSL (TLS).
ssl: false

# - name: Create .pgpass file
# run: |
# echo "localhost:5432:*:postgres:postgres" > ~/.pgpass
# chmod 0600 ~/.pgpass
# echo "USER: $USER"
# echo "HOME: $HOME"
# cat ~/.pgpass
# ls -la ~

- name: Set up TaskJuggler
run: |
sudo gem install taskjuggler
Expand Down Expand Up @@ -95,7 +85,6 @@ jobs:
- name: Test with pytest
run: |
PYTHONPATH=src python -m pytest
# --verbose -n auto -W ignore --color=yes --cov=src --cov-report html --cov-report term tests/models/test_review.py
- name: Archive code coverage results
uses: actions/upload-artifact@v4
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
.cache/*
.coverage
.coverage*
.DS_Store
.env
.mypy_cache/
.pytest_cache
.tox/
.venv/
.vscode/
*.pyc
Expand Down
9 changes: 2 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ install:
clean: FORCE
@printf "\n\033[36m--- $@: Clean ---\033[0m\n"
-rm -rf .pytest_cache
-rm -f .coverage.*
-rm -rf dist
-rm -rf build
-rm -rf docs/build
Expand All @@ -49,6 +50,7 @@ clean-all: clean
-rm -f setuptools-*.egg
-rm -f use-distutils
-rm -f .coverage*
-rm -Rf .tox
-rm -Rf htmlcov
-rm -rf dist
-rm -Rf src/$(PACKAGE_NAME).egg-info
Expand Down Expand Up @@ -83,16 +85,9 @@ tests:
echo -e "\n\033[36m--- $@: Using python interpretter '`which python`' ---\033[0m\n"; \
PYTHONPATH=src pytest -v -n auto -W ignore --color=yes --cov=src --cov-report term --cov-fail-under 99 tests;


# sphinx-build \
# {tty:--color} \
# -b html \
# doc/sphinx/source doc/sphinx/build \
# {posargs}
.PHONY: docs
docs:
cd docs && $(MAKE) html


# https://www.gnu.org/software/make/manual/html_node/Force-Targets.html
FORCE:
60 changes: 38 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,6 @@
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
stalker = ["VERSION"]

[tool.setuptools.exclude-package-data]
stalker = ["alembic", "docs", "tests"]

[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }
optional-dependencies.test = { file = ["requirements-dev.txt"] }
version = { file = ["VERSION"] }

[tool.distutils.bdist_wheel]
universal = false

[project]
authors = [
{name = "Erkan Özgür Yılmaz", email = "[email protected]"},
Expand Down Expand Up @@ -68,16 +48,35 @@ name = "stalker"
readme = "README.rst"
requires-python = ">= 3.8"


[project.urls]
"Home Page" = "https://github.com/eoyilmaz/stalker"
GitHub = "https://github.com/eoyilmaz/stalker"
Documentation = "https://stalker.readthedocs.io"
Repository = "https://github.com/eoyilmaz/stalker.git"

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
stalker = ["VERSION"]

[tool.setuptools.exclude-package-data]
stalker = ["alembic", "docs", "tests"]

[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }
optional-dependencies.test = { file = ["requirements-dev.txt"] }
version = { file = ["VERSION"] }

[tool.distutils.bdist_wheel]
universal = false

[tool.pytest.ini_options]
pythonpath = ["."]
addopts = "-v -n auto -W ignore --color=yes --cov --cov-report html --cov-report term --cov-fail-under 99 tests"
addopts = "-n auto -W ignore --color=yes --cov --cov-report html tests"

[tool.black]

Expand All @@ -98,3 +97,20 @@ extend-select = ["B950"]
ignore = ["D107", "E203", "E501", "E701", "SC200", "W503"]
max-complexity = 12
max-line-length = 80

[tool.tox]
requires = ["tox>=4.23.2"]
env_list = ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

[tool.tox.env_run_base]
description = "run the tests with pytest"
package = "wheel"
wheel_build_env = ".pkg"
deps = [
"pytest>=6",
"pytest-cov",
"pytest-xdist",
]
commands = [
["pytest"],
]
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ pytest-xdist
sphinx
sphinx-autoapi
# sphinx-findthedocs
tox
twine
wheel
2 changes: 1 addition & 1 deletion src/stalker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __setitem__(self, name, value) -> None:
name (str): The name as the index.
value (Any): The value to set the item to.
"""
setattr(self, name, value)
self.config_values[name] = value

def __delitem__(self, name: str) -> None:
"""Delete the item with the given name.
Expand Down
10 changes: 5 additions & 5 deletions src/stalker/models/studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def update_defaults(self):

try:
if self.daily_working_hours:
defaults.daily_working_hours = self.daily_working_hours
defaults["daily_working_hours"] = self.daily_working_hours
logger.debug(
"updated defaults.daily_working_hours: {}".format(
defaults.daily_working_hours
Expand All @@ -204,15 +204,15 @@ def update_defaults(self):
)

if self.weekly_working_days:
defaults.weekly_working_days = self.weekly_working_days
defaults["weekly_working_days"] = self.weekly_working_days
logger.debug(
f"updated defaults.weekly_working_days: {defaults.weekly_working_days}"
)
else:
logger.debug("can not update defaults.weekly_working_days")

if self.weekly_working_hours:
defaults.weekly_working_hours = self.weekly_working_hours
defaults["weekly_working_hours"] = self.weekly_working_hours
logger.debug(
"updated defaults.weekly_working_hours: {}".format(
defaults.weekly_working_hours
Expand All @@ -222,15 +222,15 @@ def update_defaults(self):
logger.debug("can not update defaults.weekly_working_hours")

if self.yearly_working_days:
defaults.yearly_working_days = self.yearly_working_days
defaults["yearly_working_days"] = self.yearly_working_days
logger.debug(
f"updated defaults.yearly_working_days: {defaults.yearly_working_days}"
)
else:
logger.debug("can not update defaults.yearly_working_days")

if self.timing_resolution:
defaults.timing_resolution = self.timing_resolution
defaults["timing_resolution"] = self.timing_resolution
logger.debug(
f"updated defaults.timing_resolution: {defaults.timing_resolution}"
)
Expand Down
4 changes: 2 additions & 2 deletions tests/benchmarks/task_total_logged_seonds.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# regenerate the defaults
# stalker.defaults = Config()
stalker.defaults.config_values = stalker.defaults.default_config_values.copy()
stalker.defaults.timing_resolution = datetime.timedelta(minutes=10)
stalker.defaults["timing_resolution"] = datetime.timedelta(minutes=10)

# init database
stalker.db.setup.setup(config)
Expand Down Expand Up @@ -242,7 +242,7 @@
Base.metadata.drop_all(engine, checkfirst=True)
DBSession.remove()

stalker.defaults.timing_resolution = datetime.timedelta(hours=1)
stalker.defaults["timing_resolution"] = datetime.timedelta(hours=1)

close_all_sessions()
drop_db(**get_server_details_from_url(database_url))
8 changes: 8 additions & 0 deletions tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ def test_syntax_error_in_settings_file(prepare_config_file):
assert str(cm.value) == error_message


def test___setattr___cannot_set_config_values_directly(prepare_config_file):
"""config.Config.__setattr__() method cannot set config values directly."""
c = config.Config()
test_value = 1
c.daily_working_hours = test_value
assert c.config_values["daily_working_hours"] != test_value


def test___getattr___is_working_properly(prepare_config_file):
"""config.Config.__getattr__() method is working properly."""
c = config.Config()
Expand Down
5 changes: 2 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
"""Configure tests."""

import datetime
import logging
import os
Expand Down Expand Up @@ -36,7 +35,7 @@ def setup_sqlite3():

# regenerate the defaults
stalker.defaults.config_values = stalker.defaults.default_config_values.copy()
stalker.defaults.timing_resolution = datetime.timedelta(hours=1)
stalker.defaults["timing_resolution"] = datetime.timedelta(hours=1)

# Enable Debug logging
log.set_level(logging.DEBUG)
Expand Down Expand Up @@ -88,7 +87,7 @@ def setup_postgresql_db():

# regenerate the defaults
stalker.defaults.config_values = stalker.defaults.default_config_values.copy()
stalker.defaults.timing_resolution = datetime.timedelta(hours=1)
stalker.defaults["timing_resolution"] = datetime.timedelta(hours=1)

# init database
# remove anything beforehand
Expand Down
10 changes: 5 additions & 5 deletions tests/db/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,19 @@ def auto_crate_admin_on():
"""Toggle auto create admin value on."""
# set default admin creation to True
default_value = defaults.auto_create_admin
defaults.auto_create_admin = True
defaults["auto_create_admin"] = True
yield
defaults.auto_create_admin = default_value
defaults["auto_create_admin"] = default_value


@pytest.fixture(scope="function")
def auto_crate_admin_off():
"""Toggle auto create admin value on."""
# set default admin creation to True
default_value = defaults.auto_create_admin
defaults.auto_create_admin = False
defaults["auto_create_admin"] = False
yield
defaults.auto_create_admin = default_value
defaults["auto_create_admin"] = default_value


def test_default_admin_creation(setup_postgresql_db, auto_crate_admin_on):
Expand Down Expand Up @@ -191,7 +191,7 @@ def test_no_default_admin_creation(setup_postgresql_db, auto_crate_admin_off):
pass

# regenerate the defaults
stalker.defaults.timing_resolution = datetime.timedelta(hours=1)
stalker.defaults["timing_resolution"] = datetime.timedelta(hours=1)

# init the db
stalker.db.setup.setup(data["config"])
Expand Down
9 changes: 6 additions & 3 deletions tests/mixins/test_dateRangeMixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def date_range_mixin_tester():
"""
# create mock objects
stalker.defaults.config_values = stalker.defaults.default_config_values.copy()
stalker.defaults["timing_resolution"] = datetime.timedelta(hours=1)
data = dict()
data["start"] = datetime.datetime(2013, 3, 22, 15, 15, tzinfo=pytz.utc)
data["end"] = data["start"] + datetime.timedelta(days=20)
Expand All @@ -54,7 +55,9 @@ def date_range_mixin_tester():
"duration": data["duration"],
}
data["test_foo_obj"] = DateRangeMixFooMixedInClass(**data["kwargs"])
return data
yield data
stalker.defaults.config_values = stalker.defaults.default_config_values.copy()
stalker.defaults["timing_resolution"] = datetime.timedelta(hours=1)


@pytest.mark.parametrize("test_value", [1, 1.2, "str", ["a", "date"]])
Expand Down Expand Up @@ -181,7 +184,7 @@ def test_duration_argument_is_not_an_instance_of_date_if_end_argument_is_missing
):
"""defaults.timing_resolution is used if the duration arg is not a datetime and if end arg is also missing."""
data = date_range_mixin_tester
defaults.timing_resolution = datetime.timedelta(hours=1)
defaults["timing_resolution"] = datetime.timedelta(hours=1)
# some wrong values for the duration
data["kwargs"].pop("end")
data["kwargs"]["duration"] = test_value
Expand Down Expand Up @@ -425,7 +428,7 @@ def test_start_end_and_duration_values_are_rounded_to_the_default_timing_resolut
data["kwargs"]["end"] = datetime.datetime(
2013, 3, 24, 16, 46, 32, 102, tzinfo=pytz.utc
)
defaults.timing_resolution = datetime.timedelta(minutes=5)
defaults["timing_resolution"] = datetime.timedelta(minutes=5)

new_foo_obj = DateRangeMixFooMixedInClass(**data["kwargs"])
# check the start
Expand Down
Loading

0 comments on commit 72b6dfc

Please sign in to comment.