Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tom Niget
slapos
Commits
43e5bde0
Commit
43e5bde0
authored
May 24, 2023
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/jupyter: Extend ipython tests
parent
ded78d04
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
49 deletions
+60
-49
software/jupyter/test/test.py
software/jupyter/test/test.py
+60
-49
No files found.
software/jupyter/test/test.py
View file @
43e5bde0
...
@@ -32,6 +32,7 @@ import os
...
@@ -32,6 +32,7 @@ import os
import
requests
import
requests
import
sqlite3
import
sqlite3
import
subprocess
import
subprocess
import
tempfile
from
slapos.proxy.db_version
import
DB_VERSION
from
slapos.proxy.db_version
import
DB_VERSION
from
slapos.testing.testcase
import
makeModuleSetUpAndTestCaseClass
from
slapos.testing.testcase
import
makeModuleSetUpAndTestCaseClass
...
@@ -271,65 +272,75 @@ class TestJupyterCustomAdditional(SelectMixin, InstanceTestCase):
...
@@ -271,65 +272,75 @@ class TestJupyterCustomAdditional(SelectMixin, InstanceTestCase):
r
.
destroyed
()
r
.
destroyed
()
class
TestIPython
(
InstanceTestCase
):
class
IPythonNotebook
(
object
):
def
__init__
(
self
,
name
,
binary
):
converted_notebook
=
'test.nbconvert.ipynb'
self
.
tempdir
=
tempdir
=
tempfile
.
TemporaryDirectory
()
notebook_filename
=
'test.ipynb'
path
=
os
.
path
.
join
(
tempdir
.
name
,
name
)
test_sentence
=
'test'
self
.
path
=
path
+
'.ipynb'
# input notebook
self
.
output_path
=
path
+
'.nbconvert.ipynb'
# output notebook
self
.
binary
=
binary
def
setUp
(
self
):
def
write
(
self
,
code
):
super
().
setUp
()
content
=
{
notebook_source
=
{
"cells"
:
[
"cells"
:
[
{
{
"cell_type"
:
"code"
,
"cell_type"
:
"code"
,
"execution_count"
:
None
,
"execution_count"
:
None
,
"metadata"
:
{},
"metadata"
:
{},
"outputs"
:
[],
"outputs"
:
[],
"source"
:
[
"source"
:
code
.
splitlines
(
keepends
=
True
)
"import sys
\
n
"
,
"print('"
+
self
.
test_sentence
+
"')"
]
}
}
],
],
"metadata"
:
{},
"metadata"
:
{},
"nbformat"
:
4
,
"nbformat"
:
4
,
"nbformat_minor"
:
4
"nbformat_minor"
:
4
}
}
with
open
(
self
.
notebook_filename
,
'w'
)
as
notebook
:
with
open
(
self
.
path
,
'w'
)
as
notebook
:
notebook
.
write
(
json
.
dumps
(
notebook_source
))
notebook
.
write
(
json
.
dumps
(
content
))
def
tearDown
(
self
):
def
run
(
self
):
os
.
remove
(
self
.
notebook_filename
)
return
subprocess
.
check_output
(
if
os
.
path
.
exists
(
self
.
converted_notebook
):
(
self
.
binary
,
'--execute'
,
'--to'
,
'notebook'
,
self
.
path
),
os
.
remove
(
self
.
converted_notebook
)
stderr
=
subprocess
.
STDOUT
,
text
=
True
)
super
().
tearDown
()
def
test
(
self
):
def
readResult
(
self
):
conversion_output
=
subprocess
.
check_output
([
with
open
(
self
.
output_path
)
as
result
:
os
.
path
.
join
(
return
json
.
loads
(
result
.
read
())[
'cells'
][
0
][
'outputs'
][
0
][
'text'
][
0
]
self
.
computer_partition_root_path
,
'software_release'
,
'bin'
,
'jupyter-nbconvert'
,
),
'--execute'
,
'--to'
,
'notebook'
,
self
.
notebook_filename
,
],
stderr
=
subprocess
.
STDOUT
,
text
=
True
)
self
.
assertIn
(
'[NbConvertApp] Converting notebook %s to notebook'
%
self
.
notebook_filename
,
conversion_output
,
)
self
.
assertRegex
(
conversion_output
,
r'\
[N
bConvertApp\
] W
riting \
d+
bytes to %s'
%
self
.
converted_notebook
)
self
.
assertTrue
(
os
.
path
.
exists
(
self
.
converted_notebook
))
def
__enter__
(
self
):
with
open
(
self
.
converted_notebook
)
as
json_result
:
return
self
self
.
assertEqual
(
json
.
loads
(
json_result
.
read
())[
'cells'
][
0
][
'outputs'
][
0
][
'text'
][
0
],
def
__exit__
(
self
,
*
args
):
self
.
test_sentence
+
'
\
n
'
,
if
self
.
tempdir
:
self
.
tempdir
.
cleanup
()
del
self
.
tempdir
class
TestIPython
(
InstanceTestCase
):
message
=
'test_sys'
module
=
'sys'
def
test
(
self
):
binary
=
os
.
path
.
join
(
self
.
computer_partition_root_path
,
'software_release'
,
'bin'
,
'jupyter-nbconvert'
)
with
IPythonNotebook
(
'test'
,
binary
)
as
notebook
:
notebook
.
write
(
"import %s
\
n
print(%r)"
%
(
self
.
module
,
self
.
message
))
out
=
notebook
.
run
()
self
.
assertIn
(
"[NbConvertApp] Converting notebook %s to notebook"
%
notebook
.
path
,
out
,
)
)
self
.
assertRegex
(
out
,
r"\
[N
bConvertApp\
] W
riting \
d+
bytes to %s"
%
notebook
.
output_path
)
self
.
assertTrue
(
os
.
path
.
exists
(
notebook
.
output_path
))
self
.
assertEqual
(
notebook
.
readResult
(),
self
.
message
+
'
\
n
'
)
class
TestIPythonNumpy
(
TestIPython
):
message
=
'test_numpy'
module
=
'numpy'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment