From a816d72b8f19b5ef6f3a4ca87eae668d7e77ab2a Mon Sep 17 00:00:00 2001 From: Rebot <96078724+reboot-dev-bot@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:12:21 +0000 Subject: [PATCH] [Release] Update the examples --- .github/workflows/test.yml | 2 +- everything_test.sh => .tests/all_pytests.sh | 4 ++++ readme_test.sh => .tests/readme_test.sh | 0 README.md | 22 ++++++++++----------- bank/backend/tests/account_servicer_test.py | 19 +++++++++++++++++- 5 files changed, 34 insertions(+), 13 deletions(-) rename everything_test.sh => .tests/all_pytests.sh (95%) rename readme_test.sh => .tests/readme_test.sh (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 687f892..6dc275c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/everything_test.sh b/.tests/all_pytests.sh similarity index 95% rename from everything_test.sh rename to .tests/all_pytests.sh index d6f7f9a..34bf7fb 100755 --- a/everything_test.sh +++ b/.tests/all_pytests.sh @@ -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 diff --git a/readme_test.sh b/.tests/readme_test.sh similarity index 100% rename from readme_test.sh rename to .tests/readme_test.sh diff --git a/README.md b/README.md index 743a6b4..70f83fc 100644 --- a/README.md +++ b/README.md @@ -128,8 +128,8 @@ cd resemble-examples/ Create a new Python virtual environment in which to install Resemble requirements and run an application: - - + + ```sh python -m venv ./.resemble-examples-venv source ./.resemble-examples-venv/bin/activate @@ -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`. - - + + ```sh pip install reboot-resemble-cli ``` @@ -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. - - + + ```sh pip install -r hello-constructors/backend/src/requirements.txt ``` @@ -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. - - + + ```sh rsm protoc ``` @@ -196,8 +196,8 @@ repository. The example code comes with example tests. To run the example tests, use `pytest`, for example: - - + + ```sh pytest hello-constructors/backend/ ``` @@ -209,7 +209,7 @@ To start an application, use the `rsm` CLI. The following command starts the `hello-constructors` example. ```shell diff --git a/bank/backend/tests/account_servicer_test.py b/bank/backend/tests/account_servicer_test.py index 201663b..96e072b 100644 --- a/bank/backend/tests/account_servicer_test.py +++ b/bank/backend/tests/account_servicer_test.py @@ -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: @@ -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.