Skip to content

Commit

Permalink
Move language tests outside parser
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam committed Dec 15, 2022
1 parent fa75328 commit a54c50d
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ htmlcov
.projectile
.venv/
.mypy_cache/
*.egg-info/
6 changes: 6 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[settings]
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
10 changes: 10 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[mypy]

[mypy-setuptools.*]
ignore_missing_imports = True

[mypy-pytest.*]
ignore_missing_imports = True

[mypy-yaml.*]
ignore_missing_imports = True
1 change: 1 addition & 0 deletions parser/hassil/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
19 changes: 19 additions & 0 deletions parser/hassil/_resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Shared access to package resources"""
import os
import typing
from pathlib import Path

try:
import importlib.resources

files = importlib.resources.files
except (ImportError, AttributeError):
# Backport for Python < 3.9
import importlib_resources # type: ignore

files = importlib_resources.files

_PACKAGE = "hassil"
_DIR = Path(typing.cast(os.PathLike, files(_PACKAGE)))

__version__ = (_DIR / "VERSION").read_text(encoding="utf-8").strip()
Empty file added parser/hassil/py.typed
Empty file.
2 changes: 1 addition & 1 deletion parser/scripts/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ this_dir="$( cd "$( dirname "$0" )" && pwd )"
base_dir="$(realpath "${this_dir}/..")"

# Path to virtual environment
: "${venv:=${this_dir}/.venv}"
: "${venv:=${base_dir}/.venv}"

if [ -d "${venv}" ]; then
# Activate virtual environment if available
Expand Down
18 changes: 18 additions & 0 deletions parser/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eo pipefail

# Directory of *this* script
this_dir="$( cd "$( dirname "$0" )" && pwd )"

# Base directory of repo
base_dir="$(realpath "${this_dir}/..")"

# Path to virtual environment
: "${venv:=${base_dir}/.venv}"

if [ -d "${venv}" ]; then
# Activate virtual environment if available
source "${venv}/bin/activate"
fi

pytest -vv "${base_dir}/tests"
61 changes: 61 additions & 0 deletions parser/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
from pathlib import Path

import setuptools
from setuptools import setup

this_dir = Path(__file__).parent
module_dir = this_dir / "hassil"

# -----------------------------------------------------------------------------

# Load README in as long description
long_description: str = ""
readme_path = this_dir / "README.md"
if readme_path.is_file():
long_description = readme_path.read_text(encoding="utf-8")

requirements = []
requirements_path = this_dir / "requirements.txt"
if requirements_path.is_file():
with open(requirements_path, "r", encoding="utf-8") as requirements_file:
requirements = requirements_file.read().splitlines()

version_path = module_dir / "VERSION"
with open(version_path, "r", encoding="utf-8") as version_file:
version = version_file.read().strip()

# -----------------------------------------------------------------------------

setup(
name="hassil",
version=version,
description="The Home Assistant Intent Language parser",
long_description=long_description,
url="http://github.com/rhasspy/hassil",
author="Michael Hansen",
author_email="[email protected]",
license="Apache-2.0",
packages=setuptools.find_packages(),
package_data={
"hassil": ["VERSION", "py.typed"],
},
install_requires=requirements,
extras_require={':python_version<"3.9"': ["importlib_resources"]},
entry_points={
"console_scripts": [
"hassil = hassil.__main__:main",
]
},
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Topic :: Text Processing :: Linguistic",
"License :: OSI Approved :: License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
keywords="home assistant intent recognition",
)
40 changes: 40 additions & 0 deletions pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[MESSAGES CONTROL]
disable=
format,
abstract-class-little-used,
abstract-method,
cyclic-import,
duplicate-code,
global-statement,
import-outside-toplevel,
inconsistent-return-statements,
locally-disabled,
not-context-manager,
redefined-variable-type,
too-few-public-methods,
too-many-arguments,
too-many-branches,
too-many-instance-attributes,
too-many-lines,
too-many-locals,
too-many-public-methods,
too-many-return-statements,
too-many-statements,
too-many-boolean-expressions,
unnecessary-pass,
unused-argument,
broad-except,
too-many-nested-blocks,
invalid-name,
unused-import,
no-self-use,
fixme,
useless-super-delegation,
missing-module-docstring,
missing-class-docstring,
missing-function-docstring,
import-error,
consider-using-with

[FORMAT]
expected-line-ending-format=LF
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
hassil~=0.0.1
PyYAML==6.0

black==22.3.0
flake8==3.7.9
mypy==0.910
pylint==2.10.2
pytest==5.4.1
27 changes: 27 additions & 0 deletions scripts/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -eo pipefail

# Directory of *this* script
this_dir="$( cd "$( dirname "$0" )" && pwd )"

base_dir="$(realpath "${this_dir}/..")"

# Path to virtual environment
: "${venv:=${base_dir}/.venv}"

if [ -d "${venv}" ]; then
# Activate virtual environment if available
source "${venv}/bin/activate"
fi

python_files=()
python_files+=("${base_dir}/tests"/*.py)

# Format code
black "${python_files[@]}"
isort "${python_files[@]}"

# Check
flake8 "${python_files[@]}"
pylint "${python_files[@]}"
mypy "${python_files[@]}"
38 changes: 38 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -eo pipefail

# Directory of *this* script
this_dir="$( cd "$( dirname "$0" )" && pwd )"

# Base directory of repo
base_dir="$(realpath "${this_dir}/..")"

# Path to virtual environment
: "${venv:=${base_dir}/.venv}"

# Python binary to use
: "${PYTHON=python3}"

python_version="$(${PYTHON} --version)"

# Create virtual environment
echo "Creating virtual environment at ${venv} (${python_version})"
rm -rf "${venv}"
"${PYTHON}" -m venv "${venv}"
source "${venv}/bin/activate"

# Install Python dependencies
echo 'Installing Python dependencies'
pip3 install --upgrade pip
pip3 install --upgrade wheel setuptools

# Install HassIL parser
pushd "${base_dir}/parser" 2>/dev/null
pip3 install -e '.'
popd 2>/dev/null

pip3 install -r "${base_dir}/requirements.txt"

# -----------------------------------------------------------------------------

echo "OK"
18 changes: 18 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -eo pipefail

# Directory of *this* script
this_dir="$( cd "$( dirname "$0" )" && pwd )"

# Base directory of repo
base_dir="$(realpath "${this_dir}/..")"

# Path to virtual environment
: "${venv:=${base_dir}/.venv}"

if [ -d "${venv}" ]; then
# Activate virtual environment if available
source "${venv}/bin/activate"
fi

pytest -vv "${base_dir}/tests"
22 changes: 22 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[flake8]
# To work with Black
max-line-length = 88
# E501: line too long
# W503: Line break occurred before a binary operator
# E203: Whitespace before ':'
# D202 No blank lines allowed after function docstring
# W504 line break after binary operator
ignore =
E501,
W503,
E203,
D202,
W504

[isort]
multi_line_output = 3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
indent = " "
3 changes: 1 addition & 2 deletions parser/tests/test_languages.py → tests/test_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

import pytest
import yaml

from hassil import Intents, recognize
from hassil.expression import Expression, ListReference, RuleReference, Sequence
from hassil.intents import SlotList, TextSlotList
from hassil.util import merge_dict

_DIR = Path(__file__).parent
_BASE_DIR = _DIR.parent.parent
_BASE_DIR = _DIR.parent
_USER_SENTENCES_DIR = _BASE_DIR / "sentences"
_TEST_SENTENCES_DIR = _BASE_DIR / "tests"

Expand Down

0 comments on commit a54c50d

Please sign in to comment.