def test_find_meta_tag_all_one_line(self): test_html = '<!DOCTYPE html><html><head><meta name="go-import" content="google.golang.org/api git https://code.googlesource.com/google-api-go-client"></head><body> Nothing to see here.</body></html>' meta_tag_content = GoImportMetaTagReader.find_meta_tags(test_html) self.assertEqual(meta_tag_content, [('google.golang.org/api', 'git', 'https://code.googlesource.com/google-api-go-client')])
def test_find_meta_tag_all_one_line(self): test_html = '<!DOCTYPE html><html><head><meta name="go-import" content="google.golang.org/api git https://code.googlesource.com/google-api-go-client"></head><body> Nothing to see here.</body></html>' meta_tag_content = GoImportMetaTagReader.find_meta_tags(test_html) self.assertEqual(meta_tag_content, [('google.golang.org/api', 'git', 'https://code.googlesource.com/google-api-go-client')])
def test_find_multiline_meta_tag(self): test_html = """ <!DOCTYPE html> <html> <head> <meta name="go-import" content="google.golang.org/api git https://code.googlesource.com/google-api-go-client"> <meta http-equiv="refresh" content="0; url=https://godoc.org/google.golang.org/api/googleapi"> </head> <body> Nothing to see here. Please <a href="https://godoc.org/google.golang.org/api/googleapi">move along</a>. </body> </html> """ meta_tag_content = GoImportMetaTagReader.find_meta_tags(test_html) self.assertEqual( meta_tag_content, [ ( "google.golang.org/api", "git", "https://code.googlesource.com/google-api-go-client", ) ], )
def test_meta_tag_end_with_forward_slash(self): test_html = """ <!DOCTYPE html> <html> <head> <meta name="go-import" content="google.golang.org/notapi git https://code.googlesource.com/google-notapi-go-client" /> </head> <body> Nothing to see here. Please <a href="https://godoc.org/google.golang.org/api/googleapi">move along</a>. </body> </html> """ meta_tag_content = GoImportMetaTagReader.find_meta_tags(test_html) self.assertEqual( meta_tag_content, [ ( "google.golang.org/notapi", "git", "https://code.googlesource.com/google-notapi-go-client", ) ], )
def get_fetcher(self, import_path): for matcher, unexpanded_url_info in self._matchers: # Note that the url_formats are filled in in two stages. We match.expand them here, # and the ArchiveFetcher applies .format() later, when it knows the rev. match = matcher.match(import_path) if match: expanded_url_info = ArchiveFetcher.UrlInfo(match.expand(unexpanded_url_info.url_format), unexpanded_url_info.default_rev, unexpanded_url_info.strip_level) return ArchiveFetcher(import_path, match.group(0), expanded_url_info, ArchiveRetriever.global_instance()) if self.get_options().disallow_cloning_fetcher: raise FetchError('Cannot fetch {}. No archive match, and remote repo cloning ' 'disallowed.'.format(import_path)) return CloningFetcher(import_path, GoImportMetaTagReader.global_instance())
def get_fetcher(self, import_path): for matcher, unexpanded_url_info in self._matchers: # Note that the url_formats are filled in in two stages. We match.expand them here, # and the ArchiveFetcher applies .format() later, when it knows the rev. match = matcher.match(import_path) if match: expanded_url_info = ArchiveFetcher.UrlInfo(match.expand(unexpanded_url_info.url_format), unexpanded_url_info.default_rev, unexpanded_url_info.strip_level) return ArchiveFetcher(import_path, match.group(0), expanded_url_info, ArchiveRetriever.global_instance()) if self.get_options().disallow_cloning_fetcher: raise FetchError('Cannot fetch {}. No archive match, and remote repo cloning ' 'disallowed.'.format(import_path)) return CloningFetcher(import_path, GoImportMetaTagReader.global_instance())
def test_find_meta_tag_typical(self): test_html = """ <!DOCTYPE html> <html> <head> <meta name="go-import" content="google.golang.org/api git https://code.googlesource.com/google-api-go-client"> <meta name="go-source" content="google.golang.org/api https://github.com/google/google-api-go-client https://github.com/google/google-api-go-client/tree/master{/dir} https://github.com/google/google-api-go-client/tree/master{/dir}/{file}#L{line}"> <meta http-equiv="refresh" content="0; url=https://godoc.org/google.golang.org/api/googleapi"> </head> <body> Nothing to see here. Please <a href="https://godoc.org/google.golang.org/api/googleapi">move along</a>. </body> </html> """ meta_tag_content = GoImportMetaTagReader.find_meta_tags(test_html) self.assertEqual(meta_tag_content, [('google.golang.org/api', 'git', 'https://code.googlesource.com/google-api-go-client')])
def test_meta_tag_end_with_forward_slash(self): test_html = """ <!DOCTYPE html> <html> <head> <meta name="go-import" content="google.golang.org/notapi git https://code.googlesource.com/google-notapi-go-client" /> </head> <body> Nothing to see here. Please <a href="https://godoc.org/google.golang.org/api/googleapi">move along</a>. </body> </html> """ meta_tag_content = GoImportMetaTagReader.find_meta_tags(test_html) self.assertEqual(meta_tag_content, [('google.golang.org/notapi', 'git', 'https://code.googlesource.com/google-notapi-go-client')])
def test_find_meta_tag_typical(self): test_html = """ <!DOCTYPE html> <html> <head> <meta name="go-import" content="google.golang.org/api git https://code.googlesource.com/google-api-go-client"> <meta name="go-source" content="google.golang.org/api https://github.com/google/google-api-go-client https://github.com/google/google-api-go-client/tree/master{/dir} https://github.com/google/google-api-go-client/tree/master{/dir}/{file}#L{line}"> <meta http-equiv="refresh" content="0; url=https://godoc.org/google.golang.org/api/googleapi"> </head> <body> Nothing to see here. Please <a href="https://godoc.org/google.golang.org/api/googleapi">move along</a>. </body> </html> """ meta_tag_content = GoImportMetaTagReader.find_meta_tags(test_html) self.assertEqual(meta_tag_content, [('google.golang.org/api', 'git', 'https://code.googlesource.com/google-api-go-client')])
def test_find_multiple_go_import_meta_tag(self): test_html = """ <!DOCTYPE html> <html> <head> <meta name="go-import" content="google.golang.org/notapi git https://code.googlesource.com/google-notapi-go-client"> <meta name="go-import" content="google.golang.org/api git https://code.googlesource.com/google-api-go-client"> <meta name="go-import" content="google.golang.org/otherapi git https://code.googlesource.com/google-otherapi-go-client"> <meta http-equiv="refresh" content="0; url=https://godoc.org/google.golang.org/api/googleapi"> </head> <body> Nothing to see here. Please <a href="https://godoc.org/google.golang.org/api/googleapi">move along</a>. </body> </html> """ meta_tag_content = GoImportMetaTagReader.find_meta_tags(test_html) self.assertEqual(meta_tag_content, [ ('google.golang.org/notapi', 'git', 'https://code.googlesource.com/google-notapi-go-client'), ('google.golang.org/api', 'git', 'https://code.googlesource.com/google-api-go-client'), ('google.golang.org/otherapi', 'git', 'https://code.googlesource.com/google-otherapi-go-client'), ])
def test_no_meta_tag(self): test_html = "<!DOCTYPE html><html><head></head><body>Nothing to see here.</body></html>" meta_tag_content = GoImportMetaTagReader.find_meta_tags(test_html) self.assertEqual(meta_tag_content, [])
def test_no_meta_tag(self): test_html = "<!DOCTYPE html><html><head></head><body>Nothing to see here.</body></html>" meta_tag_content = GoImportMetaTagReader.find_meta_tag(test_html) self.assertEqual(meta_tag_content, (None, None, None))