-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update readme, add docs for standard tests
- Loading branch information
1 parent
6969ff7
commit 77c0441
Showing
5 changed files
with
102 additions
and
13 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 was deleted.
Oops, something went wrong.
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,6 @@ | ||
from betterproto.tests.output_betterproto.bool.bool import Test | ||
|
||
|
||
def test_value(): | ||
message = Test() | ||
assert not message.value, "Boolean is False by default" |
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,75 @@ | ||
# Standard Tests Development Guide | ||
|
||
Standard test cases are found in [betterproto/tests/inputs](inputs), where each subdirectory represents a testcase, that is verified in isolation. | ||
|
||
``` | ||
inputs/ | ||
bool/ | ||
double/ | ||
int32/ | ||
... | ||
``` | ||
|
||
## Test case directory structure | ||
|
||
Each testcase has a `<name>.proto` file with a message called `Test`, a matching `.json` file and optionally a custom test file called `test_*.py`. | ||
|
||
```bash | ||
bool/ | ||
bool.proto | ||
bool.json | ||
test_bool.py # optional | ||
``` | ||
|
||
### proto | ||
|
||
`<name>.proto` — *The protobuf message to test* | ||
|
||
```protobuf | ||
syntax = "proto3"; | ||
message Test { | ||
bool value = 1; | ||
} | ||
``` | ||
|
||
You can add multiple `.proto` files to the test case, as long as one file matches the directory name. | ||
|
||
### json | ||
|
||
`<name>.json` — *Test-data to validate the message with* | ||
|
||
```json | ||
{ | ||
"value": true | ||
} | ||
``` | ||
|
||
### pytest | ||
|
||
`test_<name>.py` — *Custom test to validate specific aspects of the generated class* | ||
|
||
```python | ||
from betterproto.tests.output_betterproto.bool.bool import Test | ||
|
||
def test_value(): | ||
message = Test() | ||
assert not message.value, "Boolean is False by default" | ||
``` | ||
|
||
## Standard tests | ||
|
||
The following tests are automatically executed for all cases: | ||
|
||
- [x] Can the generated python code imported? | ||
- [x] Can the generated message class be instantiated? | ||
- [x] Is the generated code compatible with the Google's `grpc_tools.protoc` implementation? | ||
|
||
## Running the tests | ||
|
||
- `pipenv run generate` | ||
This generates | ||
- `betterproto/tests/output_betterproto` — *the plugin generated python classes* | ||
- `betterproto/tests/output_reference` — *reference implementation classes* | ||
- `pipenv run test` | ||
|
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[pytest] | ||
python_files = test*.py | ||
python_files = test_*.py | ||
python_classes = | ||
norecursedirs = **/output_* | ||
addopts = -p no:warnings |