Skip to content

Commit f105e39

Browse files
committed
[py] Add tests for CDP code generation script
1 parent 1283dd2 commit f105e39

File tree

2 files changed

+874
-7
lines changed

2 files changed

+874
-7
lines changed

py/generate.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222

23-
# This is a copy of https://github.com/HyperionGray/python-chrome-devtools-protocol/blob/master/generator/generate.py
23+
# This is a modified copy of:
24+
# - https://github.com/HyperionGray/python-chrome-devtools-protocol/blob/master/generator/generate.py
2425
# The license above is theirs and MUST be preserved.
2526

26-
# flake8: noqa
27+
# flake8: noqa: E501
2728

2829
import builtins
2930
from dataclasses import dataclass
@@ -389,12 +390,12 @@ def generate_enum_code(self):
389390
CDP metadata.
390391
'''
391392
def_to_json = dedent('''\
392-
def to_json(self):
393+
def to_json(self) -> str:
393394
return self.value''')
394395

395396
def_from_json = dedent('''\
396397
@classmethod
397-
def from_json(cls, json):
398+
def from_json(cls, json: str) -> AXValueSourceType:
398399
return cls(json)''')
399400

400401
code = f'class {self.id}(enum.Enum):\n'
@@ -435,8 +436,8 @@ class {self.id}:\n''')
435436
# Emit to_json() method. The properties are sorted in the same order as
436437
# above for readability.
437438
def_to_json = dedent('''\
438-
def to_json(self):
439-
json = dict()
439+
def to_json(self) -> T_JSON_DICT:
440+
json: T_JSON_DICT = dict()
440441
''')
441442
assigns = (p.generate_to_json(dict_='json') for p in props)
442443
def_to_json += indent('\n'.join(assigns), 4)
@@ -448,7 +449,7 @@ def to_json(self):
448449
# as above for readability.
449450
def_from_json = dedent('''\
450451
@classmethod
451-
def from_json(cls, json):
452+
def from_json(cls, json: T_JSON_DICT) -> AXValue:
452453
return cls(
453454
''')
454455
from_jsons = []

0 commit comments

Comments
 (0)