Repository: dayyass/calculus-of-variations (language: python)

Issue:
add code coverage



Discussion / hints:

Fix patch:
diff --git a/.coveragerc b/.coveragerc
new file mode 100644
index 0000000..35e5bae
--- /dev/null
+++ b/.coveragerc
@@ -0,0 +1,11 @@
+[run]
+branch = True
+source = calculus_of_variations
+
+[report]
+exclude_lines =
+    if self.debug:
+    pragma: no cover
+    raise NotImplementedError
+    if __name__ == .__main__.:
+ignore_errors = True
\ No newline at end of file
diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml
new file mode 100644
index 0000000..ca7e851
--- /dev/null
+++ b/.github/workflows/codecov.yml
@@ -0,0 +1,31 @@
+# https://github.com/codecov/codecov-action#example-workflowyml-with-codecov-action
+
+name: codecov
+on: [push]
+jobs:
+  run:
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ubuntu-latest, macos-latest, windows-latest]
+    env:
+      OS: ${{ matrix.os }}
+      PYTHON: '3.8'
+    steps:
+    - uses: actions/checkout@master
+    - name: Setup Python
+      uses: actions/setup-python@master
+      with:
+        python-version: 3.8
+    - name: Generate coverage report
+      run: |
+        pip install --upgrade pip
+        pip install -r requirements.txt
+        pytest --cov=./ --cov-report=xml
+    - name: Upload coverage to Codecov
+      uses: codecov/codecov-action@v1
+      with:
+        flags: unittests
+        env_vars: OS,PYTHON
+        fail_ci_if_error: true
+        verbose: true
\ No newline at end of file
diff --git a/.github/workflows/lint.yml b/.github/workflows/linter.yml
similarity index 92%
rename from .github/workflows/lint.yml
rename to .github/workflows/linter.yml
index a24c6d2..ce613a2 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/linter.yml
@@ -1,13 +1,13 @@
 # This workflow will install Python dependencies, run tests and lint with a single version of Python
 # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
 
-name: lint
+name: linter
 
 on:
   push:
-    branches: [ main ]
+    branches: [ master ]
   pull_request:
-    branches: [ main ]
+    branches: [ master ]
 
 jobs:
   build:
@@ -20,7 +20,7 @@ jobs:
         python-version: 3.8
     - name: Install dependencies
       run: |
-        python -m pip install --upgrade pip
+        pip install --upgrade pip
         pip install isort black flake8 types-PyYAML mypy
     - name: Code format check with isort
       run: |
diff --git a/.gitignore b/.gitignore
index 008fa29..3f3364c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
 *.DS_Store
+*.coverage
+coverage.xml
 *__pycache__/
 /venv/
 .idea
\ No newline at end of file
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 8243f41..b00d84d 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -29,14 +29,14 @@ repos:
   rev: v0.790
   hooks:
     - id: mypy
-- repo: local
-  hooks:
-    - id: unittest
-      name: unittest
-      entry: python -m unittest discover
-      language: system
-      description: Run all unittests.
-      always_run: true
-      types: [python]
-      pass_filenames: false
-      stages: [commit]
+#- repo: local  # too long
+#  hooks:
+#    - id: unittest
+#      name: unittest
+#      entry: python -m unittest discover
+#      language: system
+#      description: Run all unittests.
+#      always_run: true
+#      types: [python]
+#      pass_filenames: false
+#      stages: [commit]
diff --git a/README.md b/README.md
index 0253c11..7d54c3a 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,6 @@
 [![tests status](https://github.com/dayyass/calculus_of_variations/workflows/tests/badge.svg)](.github/workflows/tests.yml)
-[![lint status](https://github.com/dayyass/calculus_of_variations/workflows/lint/badge.svg)](.github/workflows/lint.yml)
+[![linter status](https://github.com/dayyass/calculus_of_variations/workflows/linter/badge.svg)](.github/workflows/linter.yml)
+[![codecov](https://codecov.io/gh/dayyass/calculus_of_variations/branch/main/graph/badge.svg)](.github/workflows/codecov.yml)
 [![license](https://img.shields.io/github/license/dayyass/calculus_of_variations)](LICENSE)
 [![release (latest by date)](https://img.shields.io/github/v/release/dayyass/calculus_of_variations)](https://github.com/dayyass/calculus_of_variations/releases/latest)
 [![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
@@ -7,14 +8,12 @@
 ### About
 My bachelor project on solving the *Calculus of variations* problems using symbolic mathematics (2018).
 
-I [participated](https://it-mm.rea.ru/uploads/arhiv/2019/sertificat/299.pdf) with this project at the IX International Scientific and Practical Conference named after A.I. Kitov "Information Technologies and Mathematical Methods in Economics and Management".
+I [participated](https://it-mm.rea.ru/uploads/arhiv/2019/sertificat/299.pdf) with this project at the IX International Scientific and Practical Conference named after A.I. Kitov "Information Technologies and Mathematical Methods in Economics and Management".<br>
 More about conference [here](https://it-mm.rea.ru/eng).
 
 ### What is *Calculus of variations*
-According to Wikipedia:
-
-The **calculus of variations** is a field of mathematical analysis that uses variations, which are small changes in functions and functionals, to find maxima and minima of functionals: mappings from a set of functions to the real numbers. Functionals are often expressed as definite integrals involving functions and their derivatives. Functions that maximize or minimize functionals may be found using the Euler–Lagrange equation of the calculus of variations.
-
+According to Wikipedia:<br>
+The **calculus of variations** is a field of mathematical analysis that uses variations, which are small changes in functions and functionals, to find maxima and minima of functionals: mappings from a set of functions to the real numbers. Functionals are often expressed as definite integrals involving functions and their derivatives. Functions that maximize or minimize functionals may be found using the Euler–Lagrange equation of the calculus of variations.<br>
 More about it [here](https://en.wikipedia.org/wiki/Calculus_of_variations).
 
 ### Simplest problem
@@ -61,10 +60,11 @@ More about each task in [project wiki](https://github.com/dayyass/calculus_of_va
 ### Usage
 First, install dependencies:
 ```
-# clone repo
+# clone repo (https/ssh)
 git clone https://github.com/dayyass/calculus_of_variations.git
+# git clone git@github.com:dayyass/calculus_of_variations.git
 
-# install dependencies
+# install dependencies (preferable in venv)
 cd calculus_of_variations
 pip install -r requirements.txt
 ```
@@ -113,6 +113,16 @@ python dash/higher_derivatives_problem_dash.py
 python dash/multidimensional_problem_dash.py
 ```
 
+### Tests
+To use [**pre-commit**](https://pre-commit.com) hooks run:<br>
+`pre-commit install`
+
+To launch [*tests*](tests) run one of the following commands:<br>
+`pytest` or `python -m unittest discover`
+
+To measure **code coverage** run one of the following commands:<br>
+`coverage run -m pytest && coverage report -m` or `coverage run -m unittest discover && coverage report -m`
+
 ### Citation
 If you use **calculus_of_variations** in a scientific publication, we would appreciate references to the following BibTex entry:
 ```bibtex
diff --git a/requirements.txt b/requirements.txt
index 52bf12b..632ec7d 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,6 +3,7 @@ attrs==21.2.0
 Brotli==1.0.9
 cfgv==3.2.0
 click==7.1.2
+coverage==5.5
 dash==1.17.0
 dash-core-components==1.13.0
 dash-html-components==1.1.1
@@ -28,6 +29,7 @@ pre-commit==2.9.3
 py==1.10.0
 pyparsing==2.4.7
 pytest==6.2.4
+pytest-cov==2.12.1
 PyYAML==5.4
 retrying==1.3.3
 six==1.15.0


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 48d8099..4af979c 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -1,13 +1,13 @@
 # This workflow will install Python dependencies, run tests and lint with a variety of Python versions
 # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
 
-name: test
+name: tests
 
 on:
   push:
-    branches: [ main ]
+    branches: [ master ]
   pull_request:
-    branches: [ main ]
+    branches: [ master ]
 
 jobs:
   build:
@@ -24,7 +24,7 @@ jobs:
         python-version: ${{ matrix.python-version }}
     - name: Install dependencies
       run: |
-        python -m pip install --upgrade pip
+        pip install --upgrade pip
         pip install -r requirements.txt
     - name: Test with pytest
       run: |
diff --git a/test_all.sh b/test_all.sh
deleted file mode 100644
index 8b66f18..0000000
--- a/test_all.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-python -m unittest tests/simplest_problem_tests.py
-python -m unittest tests/boltz_problem_tests.py
-python -m unittest tests/isoperimetric_problem_test.py
-python -m unittest tests/higher_derivatives_problem_tests.py
-python -m unittest tests/multidimensional_problem_tests.py
\ No newline at end of file