Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/deploy doc #24

Merged
merged 9 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ public/*

### Python execution ###
scripts/__pycache__/
tests/output/
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# From here: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/use-conda-with-travis-ci.html
language: python
python:
# We don't actually use the Travis Python, but this keeps it organized.
- "3.7"
- "3.8"
install:
# Install phase of our CI pipeline
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
- bash miniconda.sh -b -p $HOME/miniconda
- source "$HOME/miniconda/etc/profile.d/conda.sh"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda info -a
- conda create -q -n project python=$TRAVIS_PYTHON_VERSION -c plotly --file requirements.txt
- conda activate project

script:
# Run phase of our CI pipeline
- make unitTests
- make doc

deploy:
- provider: pages:git
verbose: true
edge: true
token: $GITHUB_TOKEN
local_dir: ./public/
on:
branch: master
condition: $TRAVIS_PYTHON_VERSION = 3.8
1 change: 1 addition & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ html: gendocs
mkdir -p $(OUTPUTDIR)/html/
cp -R $(BUILDDIR)/html/* $(OUTPUTDIR)
@echo "html files copied; the html files are in $(OUTPUTDIR)."
touch $(OUTPUTDIR)/.nojekyll


2 changes: 1 addition & 1 deletion docs/source/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ scripts
analysis
database
download_data
test
paper
6 changes: 3 additions & 3 deletions docs/source/test.rst → docs/source/paper.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test module
===========
paper module
============

.. automodule:: test
.. automodule:: paper
:members:
:undoc-members:
:show-inheritance:
22 changes: 22 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
TESTDIR = tests
SCRIPTDIR = scripts

default:
echo "Welcome to M05 mini project"

.PHONY: loadData
loadData:
# todo

.PHONY: unitTests
unitTests: cleanTests
nosetests --nocapture -v "$(TESTDIR)/test.py"

.PHONY: cleanTests
cleanTests:
rm -rf "$(TESTDIR)/output"

.PHONY: doc
doc:
$(MAKE) -C docs clean
$(MAKE) -C docs html
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
requests
sklearn
plotly.express
scikit-learn
plotly_express==0.4.1
sphinx
sphinx_rtd_theme
sphinx_rtd_theme
nose
51 changes: 0 additions & 51 deletions scripts/test.py

This file was deleted.

Empty file added tests/inputs/not_a_zip.txt
Empty file.
Binary file added tests/inputs/simpleZip.zip
Binary file not shown.
57 changes: 57 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + "/../scripts/")

import download_data
import zipfile
import requests

import algorithm
import analysis
import numpy as np

import nose.tools

# Get the path of this file to easily build relative path
base_path = os.path.dirname(os.path.realpath(__file__))

def test_unzip_file_not_a_zip():
path_to_zip_file = base_path + "/inputs/not_a_zip.txt" # not a zip
directory_to_extract_to = base_path # extract here
nose.tools.assert_raises(zipfile.BadZipFile, download_data.unzip_file, path_to_zip_file, directory_to_extract_to)

def test_unzip_file_invalid_zip_path():
path_to_zip_file = base_path + "/simpleZip.zip" # Invalid path
directory_to_extract_to = base_path # extract here
nose.tools.assert_raises(FileNotFoundError, download_data.unzip_file, path_to_zip_file, directory_to_extract_to)

def test_unzip_file():
path_to_zip_file = base_path + "/inputs/simpleZip.zip"
directory_to_extract_to = base_path + "/output/" # extract here
download_data.unzip_file(path_to_zip_file, directory_to_extract_to)
nose.tools.ok_(os.path.isfile(base_path + "/output/f1.txt"), msg="SimpleZip not correctly unzipped")

def test_download_url_invalid_url():
url = "https://invalid_url.zip"
save_path = base_path + "/output/invalid_dl.zip"
nose.tools.assert_raises(requests.exceptions.ConnectionError, download_data.download_url, url, save_path)

def test_download_url():
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/00405/Postures.zip" # Smaller zip to test
save_path = base_path + "/output/test_dl.zip"
download_data.download_url(url, save_path)
nose.tools.ok_(os.path.isfile(save_path), msg="Dataset not correctly downloaded")

def test_make_labels():
X = [np.array([0, 1, 0]), np.array([2, 3]), np.array([7, 4, 6, 9])]
labels = algorithm.make_labels(X)
ref = np.array([0,0,0,1,1,2,2,2,2])
nose.tools.ok_((labels==ref).all(), msg="{} != {}".format(labels,ref))

def test_get_confusion_matrix():
prediction = [1,2,3,1,2,2,3]
true_val = [1,2,3,1,2,3,2]
cm = analysis.get_confusion_matrix(prediction, true_val)
ref = np.array([[2, 0, 0],[0, 2, 1],[0, 1, 1]])
nose.tools.ok_((cm==ref).all(), msg="{} != {}".format(cm,ref))