Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
binary_c-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Izzard, Robert Dr (Maths & Physics)
binary_c-python
Commits
55deb252
Commit
55deb252
authored
3 years ago
by
David Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
updating test routines
parent
f45f176b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
binarycpython/tests/example.ipynb
+95
-0
95 additions, 0 deletions
binarycpython/tests/example.ipynb
binarycpython/tests/test_notebooks.py
+58
-0
58 additions, 0 deletions
binarycpython/tests/test_notebooks.py
with
153 additions
and
0 deletions
binarycpython/tests/example.ipynb
0 → 100644
+
95
−
0
View file @
55deb252
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "fd5b1a83-7212-4aca-b317-991bf289fba8",
"metadata": {},
"outputs": [],
"source": [
"def add(a, b):\n",
" return a + b"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "4d842395-3e17-48e8-b613-9856365e9796",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"add(5, 6)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f2afc967-a66a-4a47-bfc5-0d6c17826794",
"metadata": {},
"outputs": [
{
"ename": "ZeroDivisionError",
"evalue": "division by zero",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-bc757c3fda29>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m1\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero"
]
}
],
"source": [
"1 / 0"
]
},
{
"cell_type": "markdown",
"id": "8491b29d-375d-458f-8a46-fc822422d8f3",
"metadata": {},
"source": [
"hello"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "601a89e6-5ca6-4725-8834-5e975ba76726",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% Cell type:code id:fd5b1a83-7212-4aca-b317-991bf289fba8 tags:
```
python
def
add
(
a
,
b
):
return
a
+
b
```
%% Cell type:code id:4d842395-3e17-48e8-b613-9856365e9796 tags:
```
python
add
(
5
,
6
)
```
%% Output
11
%% Cell type:code id:f2afc967-a66a-4a47-bfc5-0d6c17826794 tags:
```
python
1
/
0
```
%% Output
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-3-bc757c3fda29> in <module>
----> 1 1 / 0
ZeroDivisionError: division by zero
%% Cell type:markdown id:8491b29d-375d-458f-8a46-fc822422d8f3 tags:
hello
%% Cell type:code id:601a89e6-5ca6-4725-8834-5e975ba76726 tags:
```
python
```
This diff is collapsed.
Click to expand it.
binarycpython/tests/test_notebooks.py
0 → 100644
+
58
−
0
View file @
55deb252
import
unittest
import
nbformat
import
os
from
nbconvert.preprocessors
import
ExecutePreprocessor
from
binarycpython.utils.functions
import
temp_dir
TMP_DIR
=
temp_dir
(
'
testing
'
,
'
test_notebooks
'
)
def
run_notebook
(
notebook_path
):
"""
Function to run notebooks and get the errors
"""
# https://www.blog.pythonlibrary.org/2018/10/16/testing-jupyter-notebooks/
nb_name
,
_
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
notebook_path
))
dirname
=
os
.
path
.
dirname
(
notebook_path
)
with
open
(
notebook_path
)
as
f
:
nb
=
nbformat
.
read
(
f
,
as_version
=
4
)
proc
=
ExecutePreprocessor
(
timeout
=
600
,
kernel_name
=
'
python3
'
)
proc
.
allow_errors
=
True
proc
.
preprocess
(
nb
,
{
'
metadata
'
:
{
'
path
'
:
'
/
'
}})
output_path
=
os
.
path
.
join
(
TMP_DIR
,
'
{}_all_output.ipynb
'
.
format
(
nb_name
))
with
open
(
output_path
,
mode
=
'
wt
'
)
as
f
:
nbformat
.
write
(
nb
,
f
)
errors
=
[]
for
cell
in
nb
.
cells
:
if
'
outputs
'
in
cell
:
for
output
in
cell
[
'
outputs
'
]:
if
output
.
output_type
==
'
error
'
:
errors
.
append
(
output
)
return
nb
,
errors
class
TestNotebook
(
unittest
.
TestCase
):
"""
Class that contains the notebook test calls
"""
def
test_example
(
self
):
notebook_name
=
'
example.ipynb
'
nb
,
errors
=
run_notebook
(
notebook_name
)
msg
=
"
\n
Notebook: {}
\n\n
"
.
format
(
notebook_name
)
+
"
\n
"
.
join
([
"
{}: {}
\n
{}
"
.
format
(
el
[
'
ename
'
],
el
[
'
evalue
'
],
'
\n
'
.
join
(
el
[
'
traceback
'
]))
for
el
in
errors
])
self
.
assertEqual
(
errors
,
[],
msg
=
msg
)
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment