-
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.
Unit test for generated init file (#61)
- Loading branch information
Showing
5 changed files
with
60 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
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,13 @@ | ||
"""Functions to render __init__.py from a list of filenames usng a jinja2 template.""" | ||
from pypechain.utilities.file import write_string_to_file | ||
from pypechain.utilities.format import apply_black_formatting | ||
from pypechain.utilities.templates import get_jinja_env | ||
|
||
|
||
def render_init_file(output_dir: str, file_names: list[str], line_length): | ||
"""Creates an __init__.py file that imports all other files.""" | ||
env = get_jinja_env() | ||
init_template = env.get_template("init.py.jinja2") | ||
init_code = init_template.render(file_names=file_names) | ||
formatted_init_code = apply_black_formatting(init_code, line_length) | ||
write_string_to_file(f"{output_dir}/__init__.py", formatted_init_code) |
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,35 @@ | ||
"""Tests for rendering the init file.""" | ||
import os | ||
|
||
from pypechain.utilities.templates import get_jinja_env | ||
|
||
# using pytest fixtures necessitates this. | ||
# pylint: disable=redefined-outer-name | ||
|
||
current_path = os.path.abspath(os.path.dirname(__file__)) | ||
project_root = os.path.dirname(os.path.dirname(current_path)) | ||
|
||
|
||
class TestRenderInit: | ||
"""Tests rendering for the init file using snapshots""" | ||
|
||
def test_render_init(self, snapshot): | ||
""" | ||
Tests the code gen init file using snapshots | ||
""" | ||
|
||
env = get_jinja_env() | ||
init_template = env.get_template("init.py.jinja2") | ||
|
||
# TODO: add return types to function calls | ||
|
||
file_names = [ | ||
"ContractFile1", | ||
"ContractFile2", | ||
"ContractFile3", | ||
] | ||
|
||
init_code = init_template.render(file_names=file_names) | ||
|
||
snapshot.snapshot_dir = "snapshots" # This line is optional. | ||
snapshot.assert_match(init_code, "expected_init.py") |
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,8 @@ | ||
"""Export all types from generated files. | ||
DO NOT EDIT. This file was generated by pypechain. See documentation at | ||
https://github.com/delvtech/pypechain""" | ||
|
||
from .ContractFile1 import * | ||
from .ContractFile2 import * | ||
from .ContractFile3 import * |