-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
236cc02
commit b442529
Showing
5 changed files
with
66 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,5 +37,4 @@ app.run() | |
|
||
## TODO | ||
|
||
1. More unit tests | ||
2. Add documentation | ||
1. Add documentation |
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 |
---|---|---|
@@ -1,23 +1,65 @@ | ||
import pathlib | ||
|
||
import pytest | ||
from faker import Faker | ||
|
||
from fast_grpc.proto import Service, compile_proto, delete_proto, render_proto, write_proto | ||
|
||
@pytest.mark.skip("Need implement test") | ||
def test_render_proto(): | ||
pass | ||
|
||
def test_render_proto(faker: Faker): | ||
name = faker.first_name() | ||
service = Service(name=name, methods={}, messages={}) | ||
|
||
proto_content = render_proto(service=service).strip() | ||
expected_proto_content = ( | ||
"syntax = \"proto3\";\n" | ||
f"package {name.lower()};\n" | ||
"\n" | ||
f'service {name} {{\n' | ||
"}" | ||
) | ||
|
||
assert proto_content == expected_proto_content | ||
|
||
|
||
@pytest.mark.skip("Need implement test") | ||
def test_write_proto(tmp_path: pathlib.Path): | ||
pass | ||
service = Service(name="Test", methods={}, messages={}) | ||
content = """ | ||
syntax = "proto3"; | ||
package test; | ||
service Test {} | ||
""" | ||
|
||
write_proto(service=service, proto_path=tmp_path, content=content) | ||
|
||
assert (tmp_path / "test.proto").read_text().strip() == content.strip() | ||
|
||
|
||
@pytest.mark.skip("Need implement test") | ||
def test_compile_proto(tmp_path: pathlib.Path): | ||
pass | ||
service = Service(name="Test", methods={}, messages={}) | ||
proto_content = """ | ||
syntax = "proto3"; | ||
package test; | ||
service Test {} | ||
""" | ||
(tmp_path / "test.proto").write_text(data=proto_content) | ||
|
||
compile_proto(service=service, proto_path=tmp_path, grpc_path=tmp_path) | ||
|
||
assert (tmp_path / "test_pb2.py").is_file() and (tmp_path / "test_pb2_grpc.py").is_file() | ||
|
||
|
||
@pytest.mark.skip("Need implement test") | ||
def test_delete_proto(tmp_path: pathlib.Path): | ||
pass | ||
service = Service(name="Test", methods={}, messages={}) | ||
proto_content = """ | ||
syntax = "proto3"; | ||
package test; | ||
service Test {} | ||
""" | ||
(tmp_path / "test.proto").write_text(data=proto_content) | ||
|
||
delete_proto(service=service, proto_path=tmp_path) | ||
|
||
assert not (tmp_path / "test.proto").is_file() |
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