Browse Source

Replaced Makefile with shellscript; better default project settings

Basti Tee 5 years ago
parent
commit
d957c36e2c
5 changed files with 77 additions and 27 deletions
  1. 1 1
      .coveragerc
  2. 20 1
      .vscode/settings.json
  3. 0 24
      Makefile
  4. 46 0
      make
  5. 10 1
      tests/test_utils.py

+ 1 - 1
.coveragerc

@@ -1,2 +1,2 @@
 [run]
-omit = requests/packages/*
+omit = acme/scripts/*

+ 20 - 1
.vscode/settings.json

@@ -1,7 +1,26 @@
 {
     "python.pythonPath": "${workspaceFolder}/.venv",
+    // PEP8 settings (https://www.python.org/dev/peps/pep-0008/)
+    "editor.tabSize": 4,
+    "editor.insertSpaces": true,
+    "editor.wordWrapColumn": 80,
+    "editor.wordWrap": "wordWrapColumn",
+    // Single newline at end of file
+    "files.trimTrailingWhitespace": true,
+    "files.insertFinalNewline": true,
+    "files.trimFinalNewlines": true,
+    // Always format on save
+    "editor.formatOnSave": true,
+    // Linting and code qualiy
     "python.linting.enabled": true,
     "python.linting.lintOnSave": true,
     "python.linting.flake8Enabled": true,
-    "python.linting.flake8Args": ["--verbose"]
+    "python.linting.flake8Args": [
+        "--verbose"
+    ],
+    // Unit testing (only one framework can be active)
+    "python.unitTest.unittestEnabled": false,
+    "python.unitTest.nosetestsEnabled": false,
+    "python.unitTest.pyTestEnabled": true,
+    "python.unitTest.pyTestArgs": [],
 }

+ 0 - 24
Makefile

@@ -1,24 +0,0 @@
-.PHONY: init
-init:
-	pip3 install pipenv --upgrade
-	PIPENV_VENV_IN_PROJECT=1 pipenv install --dev --skip-lock
-
-run:
-	FLASK_APP=acme FLASK_DEBUG=1 pipenv run flask run
-
-shell: init
-	pipenv shell
-
-test:
-	pipenv run py.test
-
-flake8:
-	pipenv run flake8 acme
-
-coverage:
-	pipenv run py.test -c .coveragerc --verbose tests
-
-publish:
-	pipenv run python setup.py sdist bdist_wheel
-	# publish somewhere... 
-	rm -fr build dist .egg acme.egg-info

+ 46 - 0
make

@@ -0,0 +1,46 @@
+#!/bin/bash
+cd "$( cd "$( dirname "$0" )"; pwd )"
+
+PROJECT_NAME="acme"
+export PIPENV_VERBOSITY=-1  # suppress warning if pipenv is starting inside venv
+
+function init {
+	pip3 install pipenv --upgrade
+	PIPENV_VENV_IN_PROJECT=1 pipenv install --dev --skip-lock
+}
+
+function run {
+	FLASK_APP=$PROJECT_NAME FLASK_DEBUG=1 pipenv run flask run
+}
+
+function shell {
+    init
+    pipenv shell
+}
+
+function test {
+    pipenv run py.test
+}
+
+function lint {
+    pipenv run flake8 $PROJECT_NAME
+}
+
+function coverage {
+    pipenv run py.test -c .coveragerc --verbose tests
+}
+
+function publish {
+    pipenv run python setup.py sdist bdist_wheel
+	# publish somewhere...
+	rm -fr build dist .egg $PROJECT_NAME.egg-info
+}
+
+# -----------------------------------------------------------------------------
+
+coms=$( cat $0 | egrep "^function" | awk '{print $2}' | tr "\n" " " )
+if [ -z "$1" ]; then
+    echo "Select command: $coms"
+    exit
+fi
+$1

+ 10 - 1
tests/test_utils.py

@@ -8,4 +8,13 @@ class Test:
 
     def test_add(self):
         """Ensure that adding yields correct results."""
-        assert add(1,2) == 3
+        assert add(1, 2) == 3
+        assert add(2, 1) == 3
+
+    @pytest.mark.parametrize('var1, var2', [
+        (None, 1), (1, None), (None, None)
+    ])
+    def test_add_None(self, var1, var2):
+        """Ensure that adding None values raises ValueError."""
+        with pytest.raises(ValueError):
+            add(var1, var2)