Skip to content

Commit

Permalink
fix: handle entries that cannot be disambiguated (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
dandhlee authored Jun 25, 2021
1 parent e6fa9a6 commit 7678b24
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docfx_yaml/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,9 @@ def find_unique_name(package_name, entries):
if name != "google" and name != "cloud" and entries[name] == 1:
return [name, package_name[-1]]

# If there is no way to disambiguate, return the identifier name
return [package_name[-1]]

# Used to disambiguate names that have same entries.
def disambiguate_toc_name(toc_yaml):
name_entries = {}
Expand Down
15 changes: 15 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ def test_disambiguate_toc_name(self):
self.assertEqual(yaml_want, yaml_got)


def test_disambiguate_toc_name_duplicate(self):

want_file = open('tests/yaml_post_duplicate.yaml', 'r')
yaml_want = load(want_file, Loader=Loader)

test_file = open('tests/yaml_pre_duplicate.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)


def test_reference_in_summary(self):
lines_got = """
If a ``stream`` is attached to this download, then the downloaded
Expand Down
34 changes: 34 additions & 0 deletions tests/yaml_post_duplicate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"name":"client_info",
"uidname":"google.api_core.client_info",
"items":[
{
"name":"Overview",
"uidname":"google.api_core.client_info",
"uid":"google.api_core.client_info"
},
{
"name":"ClientInfo",
"uidname":"google.api_core.client_info.ClientInfo",
"uid":"google.api_core.client_info.ClientInfo"
}
]
},
{
"name":"gapic_v1.client_info",
"uidname":"google.api_core.gapic_v1.client_info",
"items":[
{
"name":"Overview",
"uidname":"google.api_core.gapic_v1.client_info",
"uid":"google.api_core.gapic_v1.client_info"
},
{
"name":"ClientInfo",
"uidname":"google.api_core.gapic_v1.client_info.ClientInfo",
"uid":"google.api_core.gapic_v1.client_info.ClientInfo"
}
]
},
]
34 changes: 34 additions & 0 deletions tests/yaml_pre_duplicate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"name":"client_info",
"uidname":"google.api_core.client_info",
"items":[
{
"name":"Overview",
"uidname":"google.api_core.client_info",
"uid":"google.api_core.client_info"
},
{
"name":"ClientInfo",
"uidname":"google.api_core.client_info.ClientInfo",
"uid":"google.api_core.client_info.ClientInfo"
}
]
},
{
"name":"client_info",
"uidname":"google.api_core.gapic_v1.client_info",
"items":[
{
"name":"Overview",
"uidname":"google.api_core.gapic_v1.client_info",
"uid":"google.api_core.gapic_v1.client_info"
},
{
"name":"ClientInfo",
"uidname":"google.api_core.gapic_v1.client_info.ClientInfo",
"uid":"google.api_core.gapic_v1.client_info.ClientInfo"
}
]
},
]

0 comments on commit 7678b24

Please sign in to comment.