未验证 提交 21dc044a 编写于 作者: R Ren Wei (任卫) 提交者: GitHub

update `get_api_md5`, using the real api name as the map's key (#32224)

* get_api_md5 should prefer use the real name rather than the alias names

* case for ArgSpec style. update the unittests

test=document_fix
上级 2c182583
...@@ -609,12 +609,16 @@ def get_api_md5(path): ...@@ -609,12 +609,16 @@ def get_api_md5(path):
api_md5 = {} api_md5 = {}
API_spec = '%s/%s' % (os.path.abspath(os.path.join(os.getcwd(), "..")), API_spec = '%s/%s' % (os.path.abspath(os.path.join(os.getcwd(), "..")),
path) path)
pat = re.compile(r'\((paddle[^,]+)\W*document\W*([0-9a-z]{32})')
patArgSpec = re.compile(
r'^(paddle[^,]+)\s+\(ArgSpec.*document\W*([0-9a-z]{32})')
with open(API_spec) as f: with open(API_spec) as f:
for line in f.readlines(): for line in f.readlines():
api = line.split(' ', 1)[0] mo = pat.search(line)
md5 = line.split("'document', ")[1].replace(')', '').replace('\n', if not mo:
'') mo = patArgSpec.search(line)
api_md5[api] = md5 if mo:
api_md5[mo.group(1)] = mo.group(2)
return api_md5 return api_md5
...@@ -629,9 +633,12 @@ def get_incrementapi(): ...@@ -629,9 +633,12 @@ def get_incrementapi():
for key in pr_api: for key in pr_api:
if key in dev_api: if key in dev_api:
if dev_api[key] != pr_api[key]: if dev_api[key] != pr_api[key]:
logger.debug("%s in dev is %s, different from pr's %s", key,
dev_api[key], pr_api[key])
f.write(key) f.write(key)
f.write('\n') f.write('\n')
else: else:
logger.debug("%s is not in dev", key)
f.write(key) f.write(key)
f.write('\n') f.write('\n')
......
...@@ -162,10 +162,10 @@ class Test_get_api_md5(unittest.TestCase): ...@@ -162,10 +162,10 @@ class Test_get_api_md5(unittest.TestCase):
os.path.join(os.getcwd(), "..", 'paddle/fluid/API_PR.spec')) os.path.join(os.getcwd(), "..", 'paddle/fluid/API_PR.spec'))
with open(self.api_pr_spec_filename, 'w') as f: with open(self.api_pr_spec_filename, 'w') as f:
f.write("\n".join([ f.write("\n".join([
"""one_plus_one (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'md5sum of one_plus_one'))""", """paddle.one_plus_one (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'ff0f188c95030158cc6398d2a6c55one'))""",
"""two_plus_two (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'md5sum of two_plus_two'))""", """paddle.two_plus_two (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'ff0f188c95030158cc6398d2a6c55two'))""",
"""three_plus_three (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'md5sum of three_plus_three'))""", """paddle.three_plus_three (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'ff0f188c95030158cc6398d2a6cthree'))""",
"""four_plus_four (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'md5sum of four_plus_four'))""", """paddle.four_plus_four (paddle.four_plus_four, ('document', 'ff0f188c95030158cc6398d2a6c5four'))""",
])) ]))
def tearDown(self): def tearDown(self):
...@@ -174,11 +174,14 @@ class Test_get_api_md5(unittest.TestCase): ...@@ -174,11 +174,14 @@ class Test_get_api_md5(unittest.TestCase):
def test_get_api_md5(self): def test_get_api_md5(self):
res = get_api_md5('paddle/fluid/API_PR.spec') res = get_api_md5('paddle/fluid/API_PR.spec')
self.assertEqual("'md5sum of one_plus_one'", res['one_plus_one']) self.assertEqual("ff0f188c95030158cc6398d2a6c55one",
self.assertEqual("'md5sum of two_plus_two'", res['two_plus_two']) res['paddle.one_plus_one'])
self.assertEqual("'md5sum of three_plus_three'", self.assertEqual("ff0f188c95030158cc6398d2a6c55two",
res['three_plus_three']) res['paddle.two_plus_two'])
self.assertEqual("'md5sum of four_plus_four'", res['four_plus_four']) self.assertEqual("ff0f188c95030158cc6398d2a6cthree",
res['paddle.three_plus_three'])
self.assertEqual("ff0f188c95030158cc6398d2a6c5four",
res['paddle.four_plus_four'])
class Test_get_incrementapi(unittest.TestCase): class Test_get_incrementapi(unittest.TestCase):
...@@ -187,16 +190,16 @@ class Test_get_incrementapi(unittest.TestCase): ...@@ -187,16 +190,16 @@ class Test_get_incrementapi(unittest.TestCase):
os.path.join(os.getcwd(), "..", 'paddle/fluid/API_PR.spec')) os.path.join(os.getcwd(), "..", 'paddle/fluid/API_PR.spec'))
with open(self.api_pr_spec_filename, 'w') as f: with open(self.api_pr_spec_filename, 'w') as f:
f.write("\n".join([ f.write("\n".join([
"""one_plus_one (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'md5sum of one_plus_one'))""", """paddle.one_plus_one (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'ff0f188c95030158cc6398d2a6c55one'))""",
"""two_plus_two (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'md5sum of two_plus_two'))""", """paddle.two_plus_two (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'ff0f188c95030158cc6398d2a6c55two'))""",
"""three_plus_three (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'md5sum of three_plus_three'))""", """paddle.three_plus_three (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'ff0f188c95030158cc6398d2a6cthree'))""",
"""four_plus_four (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'md5sum of four_plus_four'))""", """paddle.four_plus_four (paddle.four_plus_four, ('document', 'ff0f188c95030158cc6398d2a6c5four'))""",
])) ]))
self.api_dev_spec_filename = os.path.abspath( self.api_dev_spec_filename = os.path.abspath(
os.path.join(os.getcwd(), "..", 'paddle/fluid/API_DEV.spec')) os.path.join(os.getcwd(), "..", 'paddle/fluid/API_DEV.spec'))
with open(self.api_dev_spec_filename, 'w') as f: with open(self.api_dev_spec_filename, 'w') as f:
f.write("\n".join([ f.write("\n".join([
"""one_plus_one (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'md5sum of one_plus_one'))""", """paddle.one_plus_one (ArgSpec(args=[], varargs=None, keywords=None, defaults=(,)), ('document', 'ff0f188c95030158cc6398d2a6c55one'))""",
])) ]))
self.api_diff_spec_filename = os.path.abspath( self.api_diff_spec_filename = os.path.abspath(
os.path.join(os.getcwd(), "dev_pr_diff_api.spec")) os.path.join(os.getcwd(), "dev_pr_diff_api.spec"))
...@@ -210,9 +213,10 @@ class Test_get_incrementapi(unittest.TestCase): ...@@ -210,9 +213,10 @@ class Test_get_incrementapi(unittest.TestCase):
get_incrementapi() get_incrementapi()
with open(self.api_diff_spec_filename, 'r') as f: with open(self.api_diff_spec_filename, 'r') as f:
lines = f.readlines() lines = f.readlines()
self.assertCountEqual( self.assertCountEqual([
["two_plus_two\n", "three_plus_three\n", "four_plus_four\n"], "paddle.two_plus_two\n", "paddle.three_plus_three\n",
lines) "paddle.four_plus_four\n"
], lines)
class Test_get_wlist(unittest.TestCase): class Test_get_wlist(unittest.TestCase):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册