Skip to content

Commit

Permalink
Merge pull request #68 from supunkamburugamuve/master
Browse files Browse the repository at this point in the history
Initial structure for unit testing
  • Loading branch information
jadhao authored Mar 8, 2021
2 parents 05a429c + b09c21a commit 8070d0d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ cache:
before_install:
- echo "Installing C++ and Python"
- sudo apt-get update && sudo apt-get install -y --no-install-recommends --no-install-suggests g++ python-dev python3-dev python3-pip maven libnuma-dev libc-dev python3-venv openmpi-bin libopenmpi-dev flex bison libomp-dev
- sudo apt-get install gsl-bin libgsl0-dev libboost-all-dev
- sudo apt-get install gsl-bin libgsl0-dev libboost-all-dev imagemagick-6.q16 inkscape
- cp /var/cache/apt/archives/*.deb $HOME/.cache/apt/
- export BOOST_LIBDIR=/usr/lib/x86_64-linux-gnu/

jobs:
include:
- stage: "Build Stages"
script:
- make
- make all
- cd bin && ./test.sh
name: "Build Project"
4 changes: 2 additions & 2 deletions bin/npshape-frontend.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"from hublib.ui import Submit\n",
"from hublib.ui import RunCommand\n",
"import hublib.use\n",
"%use boost-1.62.0-mpich2-1.3-gnu-4.7.2\n",
"#%use boost-1.62.0-mpich2-1.3-gnu-4.7.2\n",
"#%use lammps-31Mar17\n",
"import numpy as np\n",
"import re\n",
Expand Down Expand Up @@ -2021,7 +2021,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.8.5"
},
"tool": false,
"widgets": {
Expand Down
20 changes: 20 additions & 0 deletions bin/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

python3 -m venv ENV

source ENV/bin/activate

pip install hublib
pip install jupyterlab
pip install testbook
pip install widgetsnbextension
pip install svgwrite
pip install pypng
pip install pytest
pip install matplotlib
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension

export ENVIRON_CONFIG_DIRS=","
pytest test || exit 1

34 changes: 34 additions & 0 deletions bin/test/npshape_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import testbook
import os
import svgwrite
import png

@testbook.testbook('npshape-frontend.ipynb', execute=True)
def test_combine_4_PNGs(tb):
f = open('test/resources/test.png', 'wb') # binary mode is important
w = png.Writer(256, 1, greyscale=True)
w.write(f, [range(256)])
f.close()
if not os.path.exists('snapshot_png'):
os.mkdir("snapshot_png")

func = tb.ref("combine_4_PNGs")
func("test/resources/test.png", "test/resources/test.png", "test/resources/test.png", "test/resources/test.png", "test/resources/output.png")
assert os.path.exists("test/resources/output.png") == 1
os.remove("test/resources/output.png")

@testbook.testbook('npshape-frontend.ipynb', execute=True)
def test_convert_SVG_PNG(tb):
func = tb.ref("convert_SVG_PNG")

dwg = svgwrite.Drawing('test/resources/test.svg', profile='tiny', size=(270, 270))
dwg.add(dwg.line((0, 0), (10, 0), stroke=svgwrite.rgb(10, 10, 16, '%')))
dwg.add(dwg.text('Test', insert=(0, 0.2), fill='red'))
dwg.save()
if not os.path.exists('snapshot_png'):
os.mkdir("snapshot_png")

func("test/resources/test.svg", "test/resources/output.png")
assert os.path.exists("test/resources/output.png") == 1
os.remove("test/resources/output.png")

Binary file added bin/test/resources/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions bin/test/resources/test.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8070d0d

Please sign in to comment.