Skip to content

Commit

Permalink
Extend Unit Tests (#10)
Browse files Browse the repository at this point in the history
* Add more unit tests

* Remodel test classes

* Restructured package directory

* Modify unit test cases

* Fix import errors and structure

* Updated MQTT Classes unit tests

* Added decode message tests

* Complete MQTT Classes unit tests

* Update other unit tests

* Completed logger tests

* Ran formatter over code

* Update scripts
  • Loading branch information
WibblyGhost authored Oct 30, 2022
1 parent ea90e75 commit 7e9adc7
Show file tree
Hide file tree
Showing 38 changed files with 1,759 additions and 742 deletions.
12 changes: 10 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ __pycache__/
.pytest_cache/
.idea/
.vscode/
venv/
*.venv/
*.py[cod]

# Secret files
Expand All @@ -20,4 +20,12 @@ htmlcov/

# Docker Mappings
docker-solar-logger/
docker-influxdb/
docker-influxdb/

# Build Files
*.egg-info/
build
dist

# Backup FIles
backups/
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ __pycache__/
.pytest_cache/
.idea/
.vscode/
venv/
*.venv/
*.py[cod]

Expand All @@ -26,4 +25,7 @@ docker-influxdb/
# Build Files
*.egg-info/
build
dist
dist

# Backup FIles
backups/
158 changes: 0 additions & 158 deletions classes/py_logger.py

This file was deleted.

6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ services:
dockerfile: solar-logger.dockerfile
target: solar-logger
volumes:
- ./docker-solar-logger/output:/app/output:rw
- ./docker-solar-logger/config:/app/config:rw
- ./output:/solarlogger/output:rw
- ./config:/solarlogger/config:rw
env_file:
- .env

Expand All @@ -30,7 +30,7 @@ services:
dockerfile: solar-logger.dockerfile
target: influx-query
volumes:
- ./docker-influx-query/output:/app/output:rw
- ./output:/solarlogger/output:rw
env_file:
- .env

Expand Down
16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
[tool.pytest.ini_options]
minversion = "6.0"
addopts = "--cov-report=xml --cov-report=term --cov"
addopts = "-ra --cov-report=xml:coverage.xml --cov-report=term --cov-report=html --cov"
testpaths = ["tests"]

[tool.coverage.run]
source = ["app", "classes"]
source = ["src"]
omit = [
"tests",
"config",
"*/py_logger.py",
"*/tests/*",
"*/config/*",
# "*/py_logger.py",
"*/__init__.py",
]

[tool.isort]
profile = "black"
src_paths = ["classes", "app", "tests"]
src_paths = ["src", "tests"]
skip_glob = ["*.venv/*"]
skip_gitignore = true
multi_line_output = 5
overwrite_in_place = true

[tool.pylint.master]
init-hook='import sys; sys.path.append("src")'
# init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"
ignore=[
".pytest_cache",
".venv",
".github",
]
# init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"

[tool.pylint.main]
# Specify a score threshold under which the program will exit with error.
Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ pylint
black
isort

gitpython
faker
pytest
pytest-coverage
pytest-mock

-r requirements.txt
21 changes: 12 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
import setuptools

PACKAGE_NAME = "solar_logger"
PACKAGE_DIR = "."
PACKAGE_DIR = "src"
EXCLUDED_PACKAGES = ["*tests*"]
VERSION = "0.0.0"

with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
with open("README.md", "r", encoding="utf-8") as open_readme_file:
long_description = open_readme_file.read()

with open("__version__.py", "r") as fh:
version = fh.read()
version = version.strip().split(" = ")[1]
version = re.sub("[\"']", "", version)
VERSION = re.sub("[-*]", "_", version)

def get_version():
with open("src/__version__.py", "r") as open_version_file:
version = open_version_file.read()
version = version.strip().split(" = ")[1]
version = re.sub("[\"']", "", version)
return re.sub("[-*]", "_", version)


VERSION = get_version()

setuptools.setup(
name=PACKAGE_NAME.lower(),
Expand Down
24 changes: 11 additions & 13 deletions solar-logger-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# $(pwd) - Expands to working directory on Linux or Mac
# ${pwd} - Expands to working directory on Windows IN POWERSHELL

$Development = $FALSE
$IsFromDockerHub = $TRUE

$CurrentDir = ${pwd}
Expand All @@ -13,34 +12,33 @@ $RestartMode = "unless-stopped"

if (!${IsFromDockerHub} -and !$Development) {
# Start by building an image of SolarLogger locally
docker build . -f solar.dockerfile -t solar-logger-local
docker build . -f solar-logger.dockerfile -t solar-logger-local
}

# Before running the Docker images I would suggest creating the config and output volumes first
# Otherwise the config.ini won't get copied across
if (!(Test-Path -Path "${CurrentDir}/docker-solar-logger/output")) {
mkdir -p "${CurrentDir}/docker-solar-logger/output"
if (!(Test-Path -Path "${CurrentDir}/output")) {
mkdir -p "${CurrentDir}/output"
}
if (!(Test-Path -Path "${CurrentDir}/docker-solar-logger/config")) {
mkdir -p "${CurrentDir}/docker-solar-logger/config"
if (!(Test-Path -Path "${CurrentDir}/config")) {
mkdir -p "${CurrentDir}/config"
}


# CONFIG VOLUMES
# docker volume create \
docker volume create --driver local --opt type=none --opt device="${CurrentDir}/docker-solar-logger/config" --opt o=bind SolarLogger-Config
docker volume create --driver local --opt type=none --opt device="${CurrentDir}/config" --opt o=bind SolarLogger-Config

# OUTPUT VOLUMES
docker volume create --driver local --opt type=none --opt device="${CurrentDir}/docker-solar-logger/output" --opt o=bind SolarLogger-Output
docker volume create --driver local --opt type=none --opt device="${CurrentDir}/output" --opt o=bind SolarLogger-Output


# Run the Docker image with an environment file, output folder and config folder
if ($Development) {
docker build . -f solar.dockerfile -t wibblyghost/solar-logger --target solar-logger
} elseif (${IsFromDockerHub}) {
if (${IsFromDockerHub}) {
# If the image is built from Docker hub
docker run -d --name solar-logger --restart="${RestartMode}" --env-file "${EnvFile}" --volume "SolarLogger-Config:/app/config" --volume "SolarLogger-Output:/app/output" wibblyghost/solar-logger:"${VersionTag}"
docker run -d --name solar-logger --restart="${RestartMode}" --env-file "${EnvFile}" --volume "SolarLogger-Config:/solarlogger/config" --volume "SolarLogger-Output:/solarlogger/output" wibblyghost/solar-logger:"${VersionTag}"
} else {
# If the image is built locally
docker run -d --name solar-logger --restart="$RestartMode" --env-file "${EnvFile}" --volume "SolarLogger-Config:/app/config" --volume "SolarLogger-Output:/app/output" solar-logger-local
docker build . -f solar-logger.dockerfile -t wibblyghost/solar-logger --target solar-logger -t solar-logger-local
docker run -d --name solar-logger --restart="$RestartMode" --env-file "${EnvFile}" --volume "SolarLogger-Config:/solarlogger/config" --volume "SolarLogger-Output:/solarlogger/output" --network host solar-logger-local
}
Loading

0 comments on commit 7e9adc7

Please sign in to comment.