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

[Release] Update the examples #24

Merged
merged 1 commit into from
Oct 17, 2023
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 .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ jobs:
# Run the readme_test.sh script from the root of the repository.
# This script is used to validate the README.md file.
runCmd: |
./readme_test.sh
./.tests/readme_test.sh
4 changes: 4 additions & 0 deletions everything_test.sh → .tests/all_pytests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ function runPyTest () {

# Test.
pytest $pytest_folder

# We're done with this virtual environment. Deactivate it. It will get deleted
# when we start the next one.
deactivate
}

for pytest_folder in "${all_pytest_folders[@]}"; do
Expand Down
File renamed without changes.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ cd resemble-examples/
Create a new Python virtual environment in which to install Resemble
requirements and run an application:

<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./readme_test.sh&lines=35-36) -->
<!-- The below code snippet is automatically added from ./readme_test.sh -->
<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./.tests/readme_test.sh&lines=35-36) -->
<!-- The below code snippet is automatically added from ./.tests/readme_test.sh -->
```sh
python -m venv ./.resemble-examples-venv
source ./.resemble-examples-venv/bin/activate
Expand All @@ -148,8 +148,8 @@ Install the Resemble command line tool (`rsm`) via `pip`. This package includes
the `rsm` CLI, the Resemble `protoc` plugin, the proto dependencies required for
Resemble definitions, and the `grpcio-tools` package that provides `protoc`.

<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./readme_test.sh&lines=42-42) -->
<!-- The below code snippet is automatically added from ./readme_test.sh -->
<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./.tests/readme_test.sh&lines=42-42) -->
<!-- The below code snippet is automatically added from ./.tests/readme_test.sh -->
```sh
pip install reboot-resemble-cli
```
Expand All @@ -166,8 +166,8 @@ requirements include the Resemble backend library, `reboot-resemble`.
Requirements are specific to a particular example application. The following
command will install requirements for the `hello-constructors` application.

<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./readme_test.sh&lines=55-55) -->
<!-- The below code snippet is automatically added from ./readme_test.sh -->
<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./.tests/readme_test.sh&lines=55-55) -->
<!-- The below code snippet is automatically added from ./.tests/readme_test.sh -->
```sh
pip install -r hello-constructors/backend/src/requirements.txt
```
Expand All @@ -178,8 +178,8 @@ pip install -r hello-constructors/backend/src/requirements.txt
Run the Resemble `protoc` plugin to generate Resemble code based on the protobuf
definition of a service.

<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./readme_test.sh&lines=58-58) -->
<!-- The below code snippet is automatically added from ./readme_test.sh -->
<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./.tests/readme_test.sh&lines=58-58) -->
<!-- The below code snippet is automatically added from ./.tests/readme_test.sh -->
```sh
rsm protoc
```
Expand All @@ -196,8 +196,8 @@ repository.
The example code comes with example tests. To run the example tests,
use `pytest`, for example:

<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./readme_test.sh&lines=61-61) -->
<!-- The below code snippet is automatically added from ./readme_test.sh -->
<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./.tests/readme_test.sh&lines=61-61) -->
<!-- The below code snippet is automatically added from ./.tests/readme_test.sh -->
```sh
pytest hello-constructors/backend/
```
Expand All @@ -209,7 +209,7 @@ To start an application, use the `rsm` CLI. The following command starts the
`hello-constructors` example.

<!--
TODO: include this command in readme_test.sh.
TODO: include this command in .tests/.tests/readme_test.sh.
-->

```shell
Expand Down
19 changes: 18 additions & 1 deletion bank/backend/tests/account_servicer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from unittest.mock import patch


def report_error_to_user(error_message: str) -> None:
# This is a dummy function for use in documentation code snippets.
pass


class TestAccount(unittest.IsolatedAsyncioTestCase):

async def asyncSetUp(self) -> None:
Expand Down Expand Up @@ -44,8 +49,20 @@ async def test_basics(self) -> None:
self.assertEqual(response.balance, 40)

# When we withdraw too much money, we should get an error.
# Use a try/catch here to get a code snippet for use in docs.
with self.assertRaises(Account.WithdrawError) as e:
await account.Withdraw(workflow, amount=65)
try:
await account.Withdraw(workflow, amount=65)
except Account.WithdrawError as error:
if isinstance(error.detail, OverdraftError):
report_error_to_user(
'Your withdrawal could not be processed due to '
'insufficient funds. Your account balance is less '
'than the requested amount by '
f'{error.detail.amount} dollars.'
)
raise

self.assertTrue(isinstance(e.exception.detail, OverdraftError))
self.assertEqual(e.exception.detail.amount, 25)
# ... and the balance shouldn't have changed.
Expand Down
Loading