本文整理匯總了Python中mdn.scrape.ScrapedViewFeature.load_or_new_reference方法的典型用法代碼示例。如果您正苦於以下問題:Python ScrapedViewFeature.load_or_new_reference方法的具體用法?Python ScrapedViewFeature.load_or_new_reference怎麽用?Python ScrapedViewFeature.load_or_new_reference使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mdn.scrape.ScrapedViewFeature
的用法示例。
在下文中一共展示了ScrapedViewFeature.load_or_new_reference方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_load_specification_row_existing_resources
# 需要導入模塊: from mdn.scrape import ScrapedViewFeature [as 別名]
# 或者: from mdn.scrape.ScrapedViewFeature import load_or_new_reference [as 別名]
def test_load_specification_row_existing_resources(self):
reference = self.get_instance(
'Reference', ('web-css-background-size', 'background-size'))
section = reference.section
spec = section.specification
scraped_spec = {
'section.note': 'new note',
'section.subpath': section.subpath['en'],
'section.name': section.name['en'],
'specification.mdn_key': spec.mdn_key,
'section.id': section.id,
'specification.id': spec.id}
scraped_data = self.empty_scrape()
scraped_data['specs'].append(scraped_spec)
view = ScrapedViewFeature(self.page, scraped_data)
out = view.generate_data()
expected = self.empty_view(scraped_data)
spec_content, mat_content = view.load_specification(spec.id)
section_content = view.load_section(section.id)
reference_content = view.load_or_new_reference(section.id)
reference_content['note'] = {'en': 'new note'}
expected['features']['links']['references'] = [reference_content['id']]
expected['linked']['maturities'] = [mat_content]
expected['linked']['specifications'] = [spec_content]
expected['linked']['sections'] = [section_content]
expected['linked']['references'] = [reference_content]
self.assertDataEqual(expected, out)
示例2: test_load_specification_row_empty_resources
# 需要導入模塊: from mdn.scrape import ScrapedViewFeature [as 別名]
# 或者: from mdn.scrape.ScrapedViewFeature import load_or_new_reference [as 別名]
def test_load_specification_row_empty_resources(self):
scraped_data = self.empty_scrape()
scraped_spec = {
'section.note': '',
'section.subpath': '',
'section.name': '',
'specification.mdn_key': 'CSS3 UI',
'section.id': None,
'specification.id': None}
scraped_data['specs'].append(scraped_spec)
view = ScrapedViewFeature(self.page, scraped_data)
out = view.generate_data()
spec_content, mat_content = view.new_specification(scraped_spec)
section_content = view.new_section(scraped_spec, spec_content['id'])
# TODO: bug 1251252 - Empty string should mean omittied name, subpath
section_content['name']['en'] = ''
section_content['subpath']['en'] = ''
reference_content = view.load_or_new_reference(section_content['id'])
reference_content['note'] = None
expected = self.empty_view(scraped_data)
expected['features']['links']['references'] = [reference_content['id']]
expected['linked']['maturities'] = [mat_content]
expected['linked']['specifications'] = [spec_content]
expected['linked']['sections'] = [section_content]
expected['linked']['references'] = [reference_content]
self.assertDataEqual(expected, out)