Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace all tb.ref examples in docs with tb.get #130

Merged
merged 7 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ from testbook import testbook

@testbook('/path/to/notebook.ipynb', execute=True)
def test_func(tb):
func = tb.ref("func")
func = tb.get("func")

assert func(1, 2) == 3
```
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from testbook import testbook
@testbook('/path/to/notebook.ipynb', execute=True)
def test_get_details(tb):
with tb.patch('requests.get') as mock_get:
get_details = tb.ref('get_details') # get reference to function
get_details = tb.get('get_details') # get reference to function
get_details('https://my-api.com')

mock_get.assert_called_with('https://my-api.com')
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ from testbook import testbook

@testbook('notebook.ipynb', execute=True)
def test_foo(tb):
foo = tb.ref("foo")
foo = tb.get("foo")

assert foo(2) == 3
```
Expand All @@ -61,6 +61,6 @@ That's it! You can now execute the test.

1. Use `testbook.testbook` as a decorator or context manager to specify the path to the Jupyter Notebook. Passing `execute=True` will execute all the cells, and passing `execute=['cell-tag-1', 'cell-tag-2']` will only execute specific cells identified by cell tags.

2. Obtain references to objects under test using the `.ref` method.
2. Obtain references to objects under test using the `.get` method.

3. Write the test!
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ from testbook import testbook

@testbook('/path/to/notebook.ipynb', execute=True)
def test_func(tb):
func = tb.ref("func")
func = tb.get("func")

assert func(1, 2) == 3
```
Expand Down
20 changes: 10 additions & 10 deletions docs/usage/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ These patterns are interchangeable in most cases. If there are nested decorators

@testbook('/path/to/notebook.ipynb', execute=True)
def test_func(tb):
func = tb.ref("func")
func = tb.get("func")

assert func(1, 2) == 3
```
Expand All @@ -33,7 +33,7 @@ These patterns are interchangeable in most cases. If there are nested decorators

def test_func():
with testbook('/path/to/notebook.ipynb', execute=True) as tb:
func = tb.ref("func")
func = tb.get("func")

assert func(1, 2) == 3
```
Expand Down Expand Up @@ -69,13 +69,13 @@ Reference objects to functions can be called with,
```{code-block} python
@testbook.testbook('/path/to/notebook.ipynb', execute=True)
def test_foo(tb):
foo = tb.ref("foo")
foo = tb.get("foo")

# passing in explicitly
assert foo(['spam', 'eggs']) == "You passed ['spam', 'eggs']!"

# passing in reference object as arg
my_list = tb.ref("my_list")
my_list = tb.get("my_list")
assert foo(my_list) == "You passed ['list', 'from', 'notebook']!"
```

Expand All @@ -97,7 +97,7 @@ When `Foo` is instantiated from the test, the return value will be a reference o
```{code-block} python
@testbook.testbook('/path/to/notebook.ipynb', execute=True)
def test_say_hello(tb):
Foo = tb.ref("Foo")
Foo = tb.get("Foo")
bar = Foo("bar")

assert bar.say_hello() == "Hello bar!"
Expand Down Expand Up @@ -134,17 +134,17 @@ def tb():
yield tb

def test_foo(tb):
foo = tb.ref("foo")
foo = tb.get("foo")
assert foo(1, 2) == 3


def test_bar(tb):
bar = tb.ref("bar")
bar = tb.get("bar")

tb.inject("""
data = [1, 2, 3]
""")
data = tb.ref("data")
data = tb.get("data")

assert bar(data) == [2, 4, 6]
```
Expand All @@ -168,7 +168,7 @@ def foo():
@testbook('/path/to/notebook.ipynb', execute=True)
def test_method(tb):
with tb.patch('__main__.bar') as mock_bar:
foo = tb.ref("foo")
foo = tb.get("foo")
foo()

mock_bar.assert_called_once()
Expand All @@ -184,7 +184,7 @@ my_dict = {'hello': 'world'}
@testbook('/path/to/notebook.ipynb', execute=True)
def test_my_dict(tb):
with tb.patch('__main__.my_dict', {'hello' : 'new world'}) as mock_my_dict:
my_dict = tb.ref("my_dict")
my_dict = tb.get("my_dict")
assert my_dict == {'hello' : 'new world'}

```
Expand Down