generator lib: Initial tests

Move existing tests into a new __tests__ module under generator/lib.
Also define a new test for `util.new_context`, to prevent regressions as
changes are made.
This commit is contained in:
Kyle Gentle
2022-08-18 21:02:57 -04:00
parent 8ba6acb88b
commit a60caa2690
5 changed files with 1376 additions and 11 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,6 @@
# Discovery document for photoslibrary, retrieved from:
# https://photoslibrary.googleapis.com/$discovery/rest?version=v1
DISCOVERY_DOC = r"""
{
"documentationLink": "https://developers.google.com/photos/",
"id": "photoslibrary:v1",
@@ -1332,3 +1335,4 @@
"kind": "discovery#restDescription",
"basePath": ""
}
"""

View File

@@ -1,20 +1,12 @@
#!/usr/bin/env python
import importlib.resources
import unittest
import json
from generator.lib.util import to_api_version, library_name, re_find_replacements, to_rust_type, new_context
import generator.lib.test_data as test_data
from generator.lib.util import to_api_version, library_name, re_find_replacements, to_rust_type
from .test_data.discovery_document import DISCOVERY_DOC
TEST_JSON_FILE = "photoslibrary-api.json"
def read_test_json_file():
data = importlib.resources.read_text(test_data, TEST_JSON_FILE)
return json.loads(data)
class UtilsTest(unittest.TestCase):
def test_to_version_ok(self):
@@ -68,7 +60,7 @@ class UtilsTest(unittest.TestCase):
self.assertEqual(ms[0], '{+project}')
def test_to_rust_type(self):
full_api_schema = read_test_json_file()
full_api_schema = json.loads(DISCOVERY_DOC)
schemas = full_api_schema['schemas']