1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414# ==============================================================================
15- import time
15+ import os
1616import unittest
1717import subprocess
1818from shutil import rmtree
@@ -30,23 +30,36 @@ class TestDocsLinks(unittest.TestCase):
3030
3131 @staticmethod
3232 def check_link (_url , branch_name ):
33- headers = {'User-Agent' : 'Mozilla/5.0' }
34- try :
35- response = requests .get (_url , headers = headers , timeout = 1 )
36- print (f"[{ response .status_code } ] { _url } " )
33+ if 'sony/model_optimization' in _url :
34+ index = _url .find (f"/{ branch_name } /" )
3735
38- if response .status_code == 200 :
39- return True
40- except Exception as e :
41- print (f"Error checking link '{ _url } ': { e } " )
36+ if index != - 1 :
37+ link_path = _url [index + len ("/main/" ):]
38+ print (link_path )
39+ else :
40+ print ("The substring 'main' was not found." )
41+ raise Exception ()
4242
43- try :
44- _url = _url .replace ('/main/' , f'/{ branch_name } /' )
45- response = requests .get (_url )
46- if response .status_code == 200 :
47- return True
48- except Exception as e :
49- print (f"Error checking link '{ _url } ': { e } " )
43+ repo_root = f'https://github.com/sony/model_optimization/blob/{ branch_name } /'
44+ abs_path = os .path .join (repo_root , link_path )
45+
46+ assert os .path .isfile (abs_path ), f"Missing file: { link_path } "
47+ else :
48+ try :
49+ response = requests .head (_url )
50+ print (f"[{ response .status_code } ] { _url } " )
51+ if response .status_code == 200 :
52+ return True
53+ except Exception as e :
54+ print (f"Error checking link '{ _url } ': { e } " )
55+
56+ # try:
57+ # _url = _url.replace('/main/', f'/{branch_name}/')
58+ # response = requests.get(_url)
59+ # if response.status_code == 200:
60+ # return True
61+ # except Exception as e:
62+ # print(f"Error checking link '{_url}': {e}")
5063
5164 return False
5265
0 commit comments