def test_make_wikidata_template_special_fail(self): with self.assertRaises(ValueError) as cm: PreviewItem.make_wikidata_template('dummy', special=True) self.assertEqual( str(cm.exception), 'Sorry but "dummy" is not a recognized special value/snaktype.' )
def test_make_wikidata_template_none(self): with self.assertRaises(ValueError) as cm: PreviewItem.make_wikidata_template(None) self.assertEqual( str(cm.exception), 'Sorry only items and properties are supported, not whatever ' '"None" is.')
def test_make_wikidata_template_none(self): with self.assertRaises(ValueError) as cm: PreviewItem.make_wikidata_template(None) self.assertEqual( str(cm.exception), 'Sorry only items and properties are supported, not whatever ' '"None" is.' )
def test_format_itis_quantity_unit(self): unit = pywikibot.ItemPage(self.repo, 'Q123') itis = pywikibot.WbQuantity(123, unit=unit, site=self.repo) expected = '123 wd_template_1' self.assertEqual(PreviewItem.format_itis(itis), expected) self.mock_wd_template.assert_called_once_with(unit) self.mock_format_timestring.assert_not_called()
def test_format_claim_basic(self): claim = pywikibot.Claim(self.repo, 'P123') claim.setTarget('1') expected = 'wd_template_1: formatted_itis' self.assertEqual(PreviewItem.format_claim(claim), expected) self.mock_wd_template.assert_called_once_with('P123') self.mock_format_itis.assert_called_once_with('1', False)
def test_format_reference_no_notest(self): ref = Reference(source_test=self.claim_1) expected = (':italics_tested:\n' ':*formatted_claim_1\n') self.assertEqual(PreviewItem.format_reference(ref), expected) self.mock_format_claim.assert_called_once_with(self.claim_1) self.mock_italics.assert_called_once_with('tested')
def test_format_claim_special(self): claim = pywikibot.Claim(self.repo, 'P123') claim.setSnakType('novalue') expected = 'wd_template_1: formatted_itis' self.assertEqual(PreviewItem.format_claim(claim), expected) self.mock_wd_template.assert_called_once_with('P123') self.mock_format_itis.assert_called_once_with('novalue', True)
def test_make_wikidata_template_item_page(self): expected = '{{Q|Q321}}' item = pywikibot.ItemPage(self.repo, 'Q321') self.assertEqual( PreviewItem.make_wikidata_template(item), expected )
def test_make_wikidata_template_property_page(self): expected = '{{P|P321}}' prop = pywikibot.PropertyPage(self.repo, 'P321') self.assertEqual( PreviewItem.make_wikidata_template(prop), expected )
def test_format_itis_statement_item(self): item = pywikibot.ItemPage(self.repo, 'Q123') itis = Statement(item) expected = 'wd_template_1' self.assertEqual(PreviewItem.format_itis(itis), expected) self.mock_wd_template.assert_called_once_with(item) self.mock_format_timestring.assert_not_called()
def setUp(self): super(TestPreviewItemBase, self).setUp() self.preview_item = PreviewItem(labels={}, descriptions={}, protoclaims={}, item=None, ref=None)
def test_format_reference_basic(self): ref = Reference( source_test=[self.claim_1, self.claim_2], source_notest=[self.claim_3, self.claim_4] ) expected = ( ':italics_tested:\n' ':*formatted_claim_1\n' ':*formatted_claim_2\n' ':italics_not tested:\n' ':*formatted_claim_3\n' ':*formatted_claim_4\n' ) self.assertEqual(PreviewItem.format_reference(ref), expected) self.mock_format_claim.assert_has_calls([ mock.call(self.claim_1), mock.call(self.claim_2), mock.call(self.claim_3), mock.call(self.claim_4) ]) self.mock_italics.assert_has_calls([ mock.call('tested'), mock.call('not tested') ])
def test_format_itis_statement_other(self): itis = Statement('dummy') expected = 'dummy' self.assertEqual( PreviewItem.format_itis(itis), expected ) self.mock_wd_template.assert_not_called() self.mock_format_timestring.assert_not_called()
def test_format_itis_statement_detect_special(self): itis = Statement('novalue', special=True) expected = 'wd_template_1' self.assertEqual( PreviewItem.format_itis(itis), expected ) self.mock_wd_template.assert_called_once_with('novalue', special=True) self.mock_format_timestring.assert_not_called()
def test_format_itis_special(self): itis = 'dummy' expected = 'wd_template_1' self.assertEqual( PreviewItem.format_itis(itis, special=True), expected ) self.mock_wd_template.assert_called_once_with(itis, special=True) self.mock_format_timestring.assert_not_called()
def test_format_reference_no_notest(self): ref = Reference(source_test=self.claim_1) expected = ( ':italics_tested:\n' ':*formatted_claim_1\n' ) self.assertEqual(PreviewItem.format_reference(ref), expected) self.mock_format_claim.assert_called_once_with(self.claim_1) self.mock_italics.assert_called_once_with('tested')
def test_format_itis_statement_item(self): item = pywikibot.ItemPage(self.repo, 'Q123') itis = Statement(item) expected = 'wd_template_1' self.assertEqual( PreviewItem.format_itis(itis), expected ) self.mock_wd_template.assert_called_once_with(item) self.mock_format_timestring.assert_not_called()
def test_format_reference_basic(self): ref = Reference(source_test=[self.claim_1, self.claim_2], source_notest=[self.claim_3, self.claim_4]) expected = (':italics_tested:\n' ':*formatted_claim_1\n' ':*formatted_claim_2\n' ':italics_not tested:\n' ':*formatted_claim_3\n' ':*formatted_claim_4\n') self.assertEqual(PreviewItem.format_reference(ref), expected) self.mock_format_claim.assert_has_calls([ mock.call(self.claim_1), mock.call(self.claim_2), mock.call(self.claim_3), mock.call(self.claim_4) ]) self.mock_italics.assert_has_calls( [mock.call('tested'), mock.call('not tested')])
def test_format_itis_other(self): itis = [1, 2, 3] expected = '[1, 2, 3]' self.assertEqual(PreviewItem.format_itis(itis), expected) self.mock_wd_template.assert_not_called() self.mock_format_timestring.assert_not_called()
def test_format_itis_time(self): itis = pywikibot.WbTime(year=1999) expected = 'formatted_WbTime' self.assertEqual(PreviewItem.format_itis(itis), expected) self.mock_wd_template.assert_not_called() self.mock_format_timestring.assert_called_once()
def test_format_itis_special(self): itis = 'dummy' expected = 'wd_template_1' self.assertEqual(PreviewItem.format_itis(itis, special=True), expected) self.mock_wd_template.assert_called_once_with(itis, special=True) self.mock_format_timestring.assert_not_called()
def test_format_itis_quantity(self): itis = pywikibot.WbQuantity(123, site=self.repo) expected = '123' self.assertEqual(PreviewItem.format_itis(itis), expected) self.mock_wd_template.assert_not_called() self.mock_format_timestring.assert_not_called()
def test_format_itis_none(self): itis = None expected = 'None' self.assertEqual(PreviewItem.format_itis(itis), expected) self.mock_wd_template.assert_not_called() self.mock_format_timestring.assert_not_called()
def test_make_wikidata_template_special_somevalue(self): expected = "{{Q'|some value}}" self.assertEqual( PreviewItem.make_wikidata_template('somevalue', special=True), expected )
def test_format_itis_statement_other(self): itis = Statement('dummy') expected = 'dummy' self.assertEqual(PreviewItem.format_itis(itis), expected) self.mock_wd_template.assert_not_called() self.mock_format_timestring.assert_not_called()
def test_format_itis_statement_detect_special(self): itis = Statement('novalue', special=True) expected = 'wd_template_1' self.assertEqual(PreviewItem.format_itis(itis), expected) self.mock_wd_template.assert_called_once_with('novalue', special=True) self.mock_format_timestring.assert_not_called()
def test_format_qual_basic(self): qual = Qualifier('P123', 'val') self.assertEqual(PreviewItem.format_qual(qual), 'wd_template_1: formatted_itis') self.mock_wd_template.assert_called_once_with('P123') self.mock_format_itis.assert_called_once_with('val')
def test_make_wikidata_template_special_fail(self): with self.assertRaises(ValueError) as cm: PreviewItem.make_wikidata_template('dummy', special=True) self.assertEqual( str(cm.exception), 'Sorry but "dummy" is not a recognized special value/snaktype.')
def test_make_wikidata_template_pid(self): expected = '{{P|P123}}' self.assertEqual(PreviewItem.make_wikidata_template('P123'), expected)
def test_make_wikidata_template_item_page(self): expected = '{{Q|Q321}}' item = pywikibot.ItemPage(self.repo, 'Q321') self.assertEqual(PreviewItem.make_wikidata_template(item), expected)
def test_format_qual_basic(self): qual = Qualifier('P123', 'val') self.assertEqual( PreviewItem.format_qual(qual), 'wd_template_1: formatted_itis') self.mock_wd_template.assert_called_once_with('P123') self.mock_format_itis.assert_called_once_with('val')
def test_make_wikidata_template_property_page(self): expected = '{{P|P321}}' prop = pywikibot.PropertyPage(self.repo, 'P321') self.assertEqual(PreviewItem.make_wikidata_template(prop), expected)
def test_make_wikidata_template_pid(self): expected = '{{P|P123}}' self.assertEqual( PreviewItem.make_wikidata_template('P123'), expected )
def test_make_wikidata_template_special_somevalue(self): expected = "{{Q'|some value}}" self.assertEqual( PreviewItem.make_wikidata_template('somevalue', special=True), expected)