Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implemented container methods * changed relative to absolute imports * fix flake8 * revert absolute import change
- Loading branch information
Showing
6 changed files
with
182 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "political-plaintiff", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"mylist = [1, 2, 3, 4, 5]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "postal-contemporary", | ||
"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.8.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import pytest | ||
|
||
from ..testbook import testbook | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def notebook(): | ||
with testbook('testbook/tests/resources/datamodel.ipynb', execute=True) as tb: | ||
yield tb | ||
|
||
|
||
def test_len(notebook): | ||
mylist = notebook.ref("mylist") | ||
|
||
assert len(mylist) == 5 | ||
|
||
|
||
def test_iter(notebook): | ||
mylist = notebook.ref("mylist") | ||
|
||
expected = [] | ||
for x in mylist: | ||
expected.append(x) | ||
|
||
assert mylist == expected | ||
|
||
|
||
def test_getitem(notebook): | ||
mylist = notebook.ref("mylist") | ||
mylist.append(6) | ||
|
||
assert mylist[-1] == 6 | ||
assert mylist.__getitem__(-1) == 6 | ||
|
||
|
||
def test_getitem_raisesIndexError(notebook): | ||
mylist = notebook.ref("mylist") | ||
|
||
with pytest.raises(IndexError): | ||
mylist[100] | ||
|
||
|
||
def test_getitem_raisesTypeError(notebook): | ||
mylist = notebook.ref("mylist") | ||
|
||
with pytest.raises(TypeError): | ||
mylist['hello'] | ||
|
||
|
||
def test_setitem(notebook): | ||
notebook.inject("mydict = {'key1': 'value1', 'key2': 'value1'}") | ||
mydict = notebook.ref("mydict") | ||
|
||
mydict['key3'] = 'value3' | ||
assert mydict['key3'] == 'value3' | ||
|
||
mylist = notebook.ref("mylist") | ||
mylist[2] = 10 | ||
assert mylist[2] == 10 | ||
|
||
|
||
def test_setitem_raisesIndexError(notebook): | ||
mylist = notebook.ref("mylist") | ||
|
||
with pytest.raises(IndexError): | ||
mylist.__setitem__(10, 100) | ||
|
||
|
||
def test_setitem_raisesTypeError(notebook): | ||
mylist = notebook.ref("mylist") | ||
|
||
with pytest.raises(TypeError): | ||
mylist.__setitem__('key', 10) | ||
|
||
|
||
def test_contains(notebook): | ||
notebook.inject("mydict = {'key1': 'value1', 'key2': 'value1'}") | ||
mydict = notebook.ref("mydict") | ||
|
||
assert 'key1' in mydict | ||
assert 'key2' in mydict | ||
assert mydict.__contains__('key1') | ||
assert mydict.__contains__('key2') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters