From d2e4ec97aaef5d7e57e379b8e201a287a9160212 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 29 Aug 2022 18:15:36 +0200 Subject: [PATCH] Correct tests for decimal points --- collector/tests/test_collector.py | 4 +- flake.lock | 100 ++++++++++++++++++ flake.nix | 57 ++++++++++ .../development.txt => requirements.txt | 7 +- requirements/base.txt | 4 - requirements/production.txt | 3 - 6 files changed, 164 insertions(+), 11 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix rename requirements/development.txt => requirements.txt (50%) delete mode 100644 requirements/base.txt delete mode 100644 requirements/production.txt diff --git a/collector/tests/test_collector.py b/collector/tests/test_collector.py index 5149274..4b09353 100644 --- a/collector/tests/test_collector.py +++ b/collector/tests/test_collector.py @@ -13,7 +13,7 @@ def test_temp_collector(monkeypatch): return 25.345 monkeypatch.setattr(collector.sense, 'get_temperature', mock_temp) - assert collector.get_temperature() == 23.0 + assert collector.get_temperature() == 22.794 def test_humidity_collector(monkeypatch): @@ -51,7 +51,7 @@ def test_values_to_db(monkeypatch): temp = Temperature.objects.get(pk=1) humidity = Humidity.objects.get(pk=1) pressure = Pressure.objects.get(pk=1) - assert (temp.value == 23.0 + assert (temp.value == 22.794 and humidity.value == 45 and pressure.value == 1013) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..7d75293 --- /dev/null +++ b/flake.lock @@ -0,0 +1,100 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1642700792, + "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "mach-nix": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ], + "pypi-deps-db": [ + "pypi" + ] + }, + "locked": { + "lastModified": 1654084003, + "narHash": "sha256-j/XrVVistvM+Ua+0tNFvO5z83isL+LBgmBi9XppxuKA=", + "owner": "DavHau", + "repo": "mach-nix", + "rev": "7e14360bde07dcae32e5e24f366c83272f52923f", + "type": "github" + }, + "original": { + "id": "mach-nix", + "ref": "3.5.0", + "type": "indirect" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1659446231, + "narHash": "sha256-hekabNdTdgR/iLsgce5TGWmfIDZ86qjPhxDg/8TlzhE=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "eabc38219184cc3e04a974fe31857d8e0eac098d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-21.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "pypi": { + "flake": false, + "locked": { + "lastModified": 1661761829, + "narHash": "sha256-HmUtNTzLcbf+Tf1V0ibwzzhsvIdeK6NpaPN+JpDiR30=", + "owner": "DavHau", + "repo": "pypi-deps-db", + "rev": "645422a381528e75b7bfced7bcd3b48fd9707828", + "type": "github" + }, + "original": { + "owner": "DavHau", + "repo": "pypi-deps-db", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "mach-nix": "mach-nix", + "nixpkgs": "nixpkgs", + "pypi": "pypi" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0adac32 --- /dev/null +++ b/flake.nix @@ -0,0 +1,57 @@ +{ + description = "A Python API for various tools I use at work."; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; + flake-utils = { + url = github:numtide/flake-utils; + inputs.nixpkgs.follows = "nixpkgs"; + }; + pypi = { + url = "github:DavHau/pypi-deps-db"; + flake = false; + }; + mach-nix = { + inputs.pypi-deps-db.follows = "pypi"; + url = "mach-nix/3.5.0"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, flake-utils, mach-nix, ... }@inputs: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + machNix = mach-nix.lib."${system}"; + devEnvironment = machNix.mkPython { + requirements = builtins.readFile ./requirements.txt; + }; + in + { + devShell = pkgs.mkShell { + buildInputs = [ + devEnvironment + pkgs.gnumake + pkgs.python39Packages.autopep8 + pkgs.python39Packages.black + pkgs.python39Packages.flake8 + pkgs.python39Packages.jedi + pkgs.python39Packages.pip + pkgs.python39Packages.yapf + ]; + shellHook = '' + export DJANGO_SETTINGS_MODULE=sensors.settings.development; \ + ''; + }; + packages.venv = devEnvironment; + defaultPackage = (machNix.mkDockerImage { + packagesExtra = with pkgs; + [ pkgs.bash ]; + requirements = builtins.readFile ./requirements.txt; + _.pytest-cov.propagatedBuildInputs.mod = pySelf: self: oldVal: oldVal ++ [ pySelf.tomli ]; + }).override + (oldAttrs: { + name = "environment-sensors"; + config.Cmd = [ "run.sh" ]; + }); + }); +} diff --git a/requirements/development.txt b/requirements.txt similarity index 50% rename from requirements/development.txt rename to requirements.txt index 7d41bb8..59dd73a 100644 --- a/requirements/development.txt +++ b/requirements.txt @@ -1,10 +1,13 @@ --r base.txt - +django-background-tasks +django==2.2.13 +gunicorn mixer pep8 +plotly pylint pytest pytest-cov pytest-django rope sense_emu +sense_hat diff --git a/requirements/base.txt b/requirements/base.txt deleted file mode 100644 index 9b81e06..0000000 --- a/requirements/base.txt +++ /dev/null @@ -1,4 +0,0 @@ -django==2.2.13 -django-background-tasks -plotly -sense_hat diff --git a/requirements/production.txt b/requirements/production.txt deleted file mode 100644 index 67fbff1..0000000 --- a/requirements/production.txt +++ /dev/null @@ -1,3 +0,0 @@ --r base.txt - -gunicorn