From 48f74a78b1218e8a880fbc4f6837f4426d410026 Mon Sep 17 00:00:00 2001 From: supunkamburugamuve Date: Wed, 17 Feb 2021 13:56:00 -0500 Subject: [PATCH 1/7] adding unit testing --- .travis.yml | 5 +- bin/npshape-frontend.ipynb | 348 ++++++++---------------------------- bin/test.sh | 18 ++ bin/test/npshape_test.py | 30 ++++ bin/test/resources/test.png | Bin 0 -> 325 bytes bin/test/resources/test.svg | 2 + 6 files changed, 131 insertions(+), 272 deletions(-) create mode 100755 bin/test.sh create mode 100644 bin/test/npshape_test.py create mode 100644 bin/test/resources/test.png create mode 100644 bin/test/resources/test.svg diff --git a/.travis.yml b/.travis.yml index 865f048..b45a4c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ 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/ @@ -23,5 +23,6 @@ jobs: include: - stage: "Build Stages" script: - - make + - make all + - cd bin && ./test.sh name: "Build Project" \ No newline at end of file diff --git a/bin/npshape-frontend.ipynb b/bin/npshape-frontend.ipynb index 37c5b58..a64a0d5 100755 --- a/bin/npshape-frontend.ipynb +++ b/bin/npshape-frontend.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": { "extensions": { "jupyter_dashboards": { @@ -43,172 +43,17 @@ }, "outputs": [ { - "data": { - "application/javascript": [ - "\n", - "requirejs.undef('filepicker');\n", - "\n", - "define('filepicker', [\"@jupyter-widgets/base\"], function(widgets) {\n", - "\n", - " var FilePickerView = widgets.DOMWidgetView.extend({\n", - " render: function(){\n", - " this.file = document.createElement('input');\n", - " this.file.setAttribute('class', 'fileinput');\n", - " this.file.setAttribute('id', this.cid);\n", - " this.file.multiple = this.model.get('multiple');\n", - " this.file.required = true;\n", - " this.file.setAttribute('type', 'file');\n", - " this.file.setAttribute('style', 'display:none');\n", - "\n", - " this.label = document.createElement('label');\n", - " this.label.setAttribute('for', this.cid);\n", - " this.label.setAttribute('style', 'border: 1px solid; border-radius: 5px; display: inline-block; padding: 6px 12px');\n", - "\n", - " this.icon = document.createElement('i');\n", - " this.icon.setAttribute(\"class\", \"fa fa-upload\");\n", - "\n", - " if (this.file.multiple) {\n", - " this.labelstr = \" Upload Files\";\n", - " } else {\n", - " this.labelstr = \" Upload File\";\n", - " }\n", - " this.label.innerHTML = this.labelstr;\n", - " this.label.prepend(this.icon);\n", - " this.el.appendChild(this.label);\n", - " this.el.appendChild(this.file);\n", - " this.listenTo(this.model, 'change:send', this._send_changed, this);\n", - " this.listenTo(this.model, 'change:reset', this._reset, this);\n", - " this.update();\n", - " },\n", - "\n", - " events: {\n", - " // List of events and their handlers.\n", - " 'change': 'handle_file_change'\n", - " },\n", - "\n", - " _reset: function() {\n", - " this.label.innerHTML = this.labelstr;\n", - " this.label.prepend(this.icon);\n", - " this.file.removeAttribute(\"disabled\");\n", - " },\n", - "\n", - " _send_changed: function() {\n", - " var that = this;\n", - " var send = this.model.get('send');\n", - " var fnum = send[0];\n", - " var offset = send[1];\n", - " var chunk_size=64*1024;\n", - " var reader;\n", - "\n", - " if (fnum == -1) {\n", - " // ignore\n", - " return\n", - " }\n", - "\n", - " if (offset == 0) {\n", - " this.model.set('sent', -1);\n", - " this.touch();\n", - " }\n", - "\n", - " // console.log('send: ' + fnum + ' ' + offset);\n", - " function tob64( buffer ) {\n", - " var binary = '';\n", - " var bytes = new Uint8Array( buffer );\n", - " var len = bytes.byteLength;\n", - " for (var i = 0; i < len; i++) {\n", - " binary += String.fromCharCode( bytes[ i ] );\n", - " }\n", - " return window.btoa( binary );\n", - " }\n", - "\n", - " var reader_done = function (event) {\n", - " // chunk is finished. Send to python\n", - " if (event.target.error == null) {\n", - " var b64 = tob64(event.target.result);\n", - " that.model.set('data', b64);\n", - " that.model.set('sent', offset);\n", - " that.touch();\n", - " } else {\n", - " console.log(\"Read error: \" + event.target.error);\n", - " that.model.set('data', '');\n", - " that.model.set('sent', -2);\n", - " that.touch();\n", - " }\n", - " that.touch();\n", - " }\n", - " \n", - " var chunk_reader = function (_offset, _f) {\n", - " // console.log('CR' + ' ' + _f + ' ' + _offset);\n", - " reader = new FileReader();\n", - " var chunk = _f.slice(_offset, chunk_size + _offset); \n", - " reader.readAsArrayBuffer(chunk);\n", - " reader.onload = reader_done;\n", - " }\n", - " \n", - " // OK. request next chunk\n", - " chunk_reader(offset, this.files[fnum]);\n", - " },\n", - " \n", - " \n", - " handle_file_change: function(evt) {\n", - "\n", - " var _files = evt.target.files;\n", - " var filenames = [];\n", - " var file_readers = [];\n", - " this.files = [];\n", - "\n", - " for (var i = 0; i < _files.length; i++) {\n", - " var file = _files[i];\n", - " console.log(\"Filename: \" + file.name);\n", - " console.log(\"Type: \" + file.type);\n", - " console.log(\"Size: \" + file.size + \" bytes\");\n", - " this.files.push(file);\n", - " filenames.push([file.name, file.size]);\n", - " };\n", - " \n", - " // Set the filenames of the files.\n", - " this.model.set('filenames', filenames);\n", - " this.touch();\n", - "\n", - " // update the label\n", - " if (filenames.length == 0) {\n", - " this.label.innerHTML = this.labelstr;\n", - " this.file.removeAttribute(\"disabled\");\n", - " } else if (filenames.length == 1) {\n", - " this.label.innerHTML = \" \" + filenames[0][0];\n", - " this.file.setAttribute('disabled', 'true');\n", - " } else {\n", - " this.label.innerHTML = \" \" + filenames.length + \" files selected\";\n", - " this.file.setAttribute('disabled', 'true'); \n", - " };\n", - " this.label.prepend(this.icon);\n", - " },\n", - " });\n", - "\n", - " // Register the FilePickerView with the widget manager.\n", - " return {\n", - " FilePickerView: FilePickerView\n", - " };\n", - "});\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" + "ename": "KeyError", + "evalue": "'ENVIRON_CONFIG_DIRS'", + "output_type": "error", + "traceback": [ + "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", + "\u001B[0;31mKeyError\u001B[0m Traceback (most recent call last)", + "\u001B[0;32m\u001B[0m in \u001B[0;36m\u001B[0;34m\u001B[0m\n\u001B[1;32m 8\u001B[0m \u001B[0;32mfrom\u001B[0m \u001B[0mhublib\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mui\u001B[0m \u001B[0;32mimport\u001B[0m \u001B[0mSubmit\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 9\u001B[0m \u001B[0;32mfrom\u001B[0m \u001B[0mhublib\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mui\u001B[0m \u001B[0;32mimport\u001B[0m \u001B[0mRunCommand\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 10\u001B[0;31m \u001B[0;32mimport\u001B[0m \u001B[0mhublib\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0muse\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 11\u001B[0m \u001B[0;31m#%use boost-1.62.0-mpich2-1.3-gnu-4.7.2\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 12\u001B[0m \u001B[0;31m#%use lammps-31Mar17\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;32m~/projects/nanobio/supun-shape/bin/env/lib/python3.8/site-packages/hublib/use/__init__.py\u001B[0m in \u001B[0;36m\u001B[0;34m\u001B[0m\n\u001B[1;32m 12\u001B[0m \u001B[0;32mfrom\u001B[0m \u001B[0mIPython\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mcore\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mmagic\u001B[0m \u001B[0;32mimport\u001B[0m \u001B[0mregister_line_magic\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 13\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 14\u001B[0;31m \u001B[0mEPATH\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mos\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0menviron\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0;34m'ENVIRON_CONFIG_DIRS'\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0msplit\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 15\u001B[0m \u001B[0md\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;34m{\u001B[0m\u001B[0;34m}\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 16\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;32m/usr/lib/python3.8/os.py\u001B[0m in \u001B[0;36m__getitem__\u001B[0;34m(self, key)\u001B[0m\n\u001B[1;32m 673\u001B[0m \u001B[0;32mexcept\u001B[0m \u001B[0mKeyError\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 674\u001B[0m \u001B[0;31m# raise KeyError with the original key value\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 675\u001B[0;31m \u001B[0;32mraise\u001B[0m \u001B[0mKeyError\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mkey\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;32mfrom\u001B[0m \u001B[0;32mNone\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 676\u001B[0m \u001B[0;32mreturn\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mdecodevalue\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mvalue\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 677\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;31mKeyError\u001B[0m: 'ENVIRON_CONFIG_DIRS'" + ] } ], "source": [ @@ -221,7 +66,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", @@ -354,25 +199,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "'''\n", "CSS = \"\"\"\n", @@ -401,7 +230,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -412,7 +241,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "extensions": { "jupyter_dashboards": { @@ -430,24 +259,7 @@ } } }, - "outputs": [ - { - "data": { - "text/html": [ - "" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "%%html\n", "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "%matplotlib notebook\n", "from mpl_toolkits.mplot3d import Axes3D\n", @@ -52,7 +221,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", @@ -185,9 +354,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "'''\n", "CSS = \"\"\"\n", @@ -216,7 +401,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -227,7 +412,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "extensions": { "jupyter_dashboards": { @@ -245,7 +430,24 @@ } } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "%%html\n", "" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "%matplotlib notebook\n", "from mpl_toolkits.mplot3d import Axes3D\n", @@ -354,25 +185,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "'''\n", "CSS = \"\"\"\n", @@ -401,7 +216,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -412,7 +227,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "extensions": { "jupyter_dashboards": { @@ -430,24 +245,7 @@ } } }, - "outputs": [ - { - "data": { - "text/html": [ - "\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "%%html\n", "