-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: complete toc disambiguation (#45)
* fix: complete toc disambiguation * fix: update to increment values * chore: update names map to name_entries * test: update to use unittest * test: fix typo in ci.yaml * test: update name and test file lengths
- Loading branch information
Showing
6 changed files
with
196 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,7 @@ jobs: | |
- name: Run tests | ||
run: | | ||
tox -e docs | ||
- name: Run unittest | ||
run: | | ||
tox -e unittest | ||
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,48 @@ | ||
from docfx_yaml.extension import find_unique_name | ||
from docfx_yaml.extension import disambiguate_toc_name | ||
|
||
import unittest | ||
|
||
from yaml import load, Loader | ||
|
||
class TestGenerate(unittest.TestCase): | ||
def test_find_unique_name(self): | ||
|
||
entries = {} | ||
|
||
# Disambiguate with unique entries. | ||
entry1 = "google.cloud.aiplatform.v1.schema.predict.instance_v1.types" | ||
entry2 = "google.cloud.aiplatform.v1beta2.schema.predict.instance_v1.types" | ||
want1 = "v1.types" | ||
want2 = "v1beta2.types" | ||
|
||
for entry in [entry1, entry2]: | ||
for word in entry.split("."): | ||
if word not in entries: | ||
entries[word] = 1 | ||
else: | ||
entries[word] += 1 | ||
|
||
got1 = find_unique_name(entry1.split("."), entries) | ||
got2 = find_unique_name(entry2.split("."), entries) | ||
|
||
self.assertEqual(want1, ".".join(got1)) | ||
self.assertEqual(want2, ".".join(got2)) | ||
|
||
|
||
def test_disambiguate_toc_name(self): | ||
|
||
want_file = open('tests/yaml_post.yaml', 'r') | ||
yaml_want = load(want_file, Loader=Loader) | ||
|
||
test_file = open('tests/yaml_pre.yaml', 'r') | ||
yaml_got = load(test_file, Loader=Loader) | ||
disambiguate_toc_name(yaml_got) | ||
|
||
want_file.close() | ||
test_file.close() | ||
|
||
self.assertEqual(yaml_want, yaml_got) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,50 @@ | ||
[ | ||
{ | ||
"name":"database_admin", | ||
"uidname":"google.cloud.spanner_admin_database_v1.services.database_admin", | ||
"items":[ | ||
{ | ||
"name":"DatabaseAdminAsyncClient", | ||
"uidname":"google.cloud.spanner_admin_database_v1.services.database_admin.DatabaseAdminAsyncClient", | ||
"uid":"google.cloud.spanner_admin_database_v1.services.database_admin.DatabaseAdminAsyncClient" | ||
}, | ||
{ | ||
"name":"DatabaseAdminClient", | ||
"uidname":"google.cloud.spanner_admin_database_v1.services.database_admin.DatabaseAdminClient", | ||
"uid":"google.cloud.spanner_admin_database_v1.services.database_admin.DatabaseAdminClient" | ||
} | ||
] | ||
}, | ||
{ | ||
"name":"spanner_admin_database_v1.types", | ||
"uidname":"google.cloud.spanner_admin_database_v1.types", | ||
}, | ||
{ | ||
"name":"instance_admin", | ||
"uidname":"google.cloud.spanner_admin_instance_v1.services.instance_admin", | ||
}, | ||
{ | ||
"name":"spanner_admin_instance_v1.types", | ||
"uidname":"google.cloud.spanner_admin_instance_v1.types", | ||
}, | ||
{ | ||
"name":"batch", | ||
"uidname":"google.cloud.spanner_v1.batch", | ||
"items":[ | ||
{ | ||
"name":"Overview", | ||
"uidname":"google.cloud.spanner_v1.batch", | ||
"uid":"google.cloud.spanner_v1.batch" | ||
}, | ||
{ | ||
"name":"Batch", | ||
"uidname":"google.cloud.spanner_v1.batch.Batch", | ||
"uid":"google.cloud.spanner_v1.batch.Batch" | ||
} | ||
] | ||
}, | ||
{ | ||
"name":"spanner_v1.types", | ||
"uidname":"google.cloud.spanner_v1.types", | ||
} | ||
] |
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,50 @@ | ||
[ | ||
{ | ||
"name":"database_admin", | ||
"uidname":"google.cloud.spanner_admin_database_v1.services.database_admin", | ||
"items":[ | ||
{ | ||
"name":"DatabaseAdminAsyncClient", | ||
"uidname":"google.cloud.spanner_admin_database_v1.services.database_admin.DatabaseAdminAsyncClient", | ||
"uid":"google.cloud.spanner_admin_database_v1.services.database_admin.DatabaseAdminAsyncClient" | ||
}, | ||
{ | ||
"name":"DatabaseAdminClient", | ||
"uidname":"google.cloud.spanner_admin_database_v1.services.database_admin.DatabaseAdminClient", | ||
"uid":"google.cloud.spanner_admin_database_v1.services.database_admin.DatabaseAdminClient" | ||
} | ||
] | ||
}, | ||
{ | ||
"name":"types", | ||
"uidname":"google.cloud.spanner_admin_database_v1.types", | ||
}, | ||
{ | ||
"name":"instance_admin", | ||
"uidname":"google.cloud.spanner_admin_instance_v1.services.instance_admin", | ||
}, | ||
{ | ||
"name":"types", | ||
"uidname":"google.cloud.spanner_admin_instance_v1.types", | ||
}, | ||
{ | ||
"name":"batch", | ||
"uidname":"google.cloud.spanner_v1.batch", | ||
"items":[ | ||
{ | ||
"name":"Overview", | ||
"uidname":"google.cloud.spanner_v1.batch", | ||
"uid":"google.cloud.spanner_v1.batch" | ||
}, | ||
{ | ||
"name":"Batch", | ||
"uidname":"google.cloud.spanner_v1.batch.Batch", | ||
"uid":"google.cloud.spanner_v1.batch.Batch" | ||
} | ||
] | ||
}, | ||
{ | ||
"name":"types", | ||
"uidname":"google.cloud.spanner_v1.types", | ||
} | ||
] |
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