Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to run tests #215

Merged
merged 7 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Release 1.6

- Added [run-test.sh](run-tests.sh) script that runs all checks on code
- Added support for Python 3.12 and 3.13 by upgrading Pylint and disabling/fixing Pylint errors
- Corrected and improved language consistency in [readme](README.md) and `CHANGELOG.md`

Expand Down
2 changes: 1 addition & 1 deletion DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
For every release, the following process is used.

### Before Release
1. From the project directory, run `./run-tests.sh` to insure unit tests pass (on python 2 and 3),
1. From the project directory, run [./run-tests.sh](run-tests.sh) to insure unit tests pass (on python 2 and 3),
and that pylint succeeds
2. Push commit which is the candidate release to Github master
3. Wait for tests to pass on [TravisCI](https://travis-ci.org/EntilZha/PyFunctional)
Expand Down
3 changes: 2 additions & 1 deletion functional/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
from collections.abc import Iterable

# pylint: disable=deprecated-class
from typing import Callable, Any, Iterator, NoReturn, Hashable
from typing import Callable, Any, NoReturn
from collections.abc import Iterator, Hashable
from _typeshed import SupportsRichComparison
from _typeshed import SupportsRichComparisonT
from typing_extensions import TypeGuard
Expand Down
4 changes: 2 additions & 2 deletions functional/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import builtins

from itertools import chain
from typing import Any, Iterable, Iterator, SupportsIndex
from typing import TypeVar, overload
from typing import Any, SupportsIndex, TypeVar, overload
from collections.abc import Iterable, Iterator
import typing

from functional.execution import ExecutionEngine, ParallelExecutionEngine
Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ pandas = { version = ">=1.0.3", optional = true }
[tool.poetry.extras]
all = ["pandas"]

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
black = "^23.1"
pytest = "^7.3.1"
pylint = "^3.3.3"
pytest-cov = "^4.0.0"
coverage = "^7.2.5"

[tool.poetry.group.dev.dependencies]
mypy = "^1.1.1"
types-tabulate = "^0.9.0.3"
pandas-stubs = "^2.0.3.230814"
Expand Down
112 changes: 112 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

# campare_versions(v1, v2)
# Compares two 3-part sematic versions, returning -1 if v1 is less than v2, 1 if v1 is greater than v2 or 0 if v1 and v2 are equal.
compare_versions() {
local v1=(${1//./ })
local v2=(${2//./ })

for i in {0..2}; do
if [[ ${v1[i]} -lt ${v2[i]} ]]; then
# Version $1 is less than $2
echo -1
return
elif [[ ${v1[i]} -gt ${v2[i]} ]]; then
# Version $1 is greater than $2"
echo 1
return
fi
done
# "Version $1 is equal to $2"
echo 0
}

# get_version_in_pipx(package_name)
# Gets the standard semantic version of a package installed in Pipx if installed.
get_version_in_pipx() {
local package_name=$1
local version
version=$(pipx list | grep -oP "$package_name"\\s+\\K\[0-9\]+\.\[0-9\]+\.\[0-9\]+)
echo "$version"
}

# capitalise(word)
# Capitalizes a word.
capitalize() {
local word=$1
echo "$(tr '[:lower:]' '[:upper:]' <<< "${word:0:1}")${word:1}"
}

# print_version(name, version, capitalize, width)
# Prints the version of the software with option to capitalize name and change left-aligned padding.
print_version() {
local name=$1
local version=$2
local capitalize=${3:-true}
local width=${4:-19}
name=$([[ $capitalize == 'true' ]] && capitalize "$name" || echo "$name")
printf "%-${width}s %s\n" "$name version:" "$version"
}

# install_package(package_name)
# Installs specified package with Pipx or displays the its version if it's already installed.
install_package() {
local package_name=$1
local capitalize=${2:-true}

local version
version=$(get_version_in_pipx "$package_name")
if [[ -n $version ]]; then
print_version "$package_name" "$version" "$capitalize"
else
pipx install "$package_name"
pipx ensurepath
fi
}

main() {
local python_version
python_version=$(python --version | awk '{print $2}')
print_version "Python" "$python_version"

local pipx_version
pipx_version=$(pipx --version)
if [[ -z "$pipx_version" ]]; then
echo "Please install Pipx before running this script."
exit 1
else
print_version "Pipx" "$pipx_version"
fi

install_package "poetry"

install_package "pre-commit" false

echo

if ! poetry install; then
poetry lock
poetry install
fi

echo

poetry run pylint functional

echo

poetry run ruff check functional

echo

poetry run black --diff --color --check functional

echo

poetry run mypy functional

echo

poetry run pytest
}

main "$@"