Esempio n. 1
0
    def test_format_claim_value_time(self):
        self.set_claim_type('time')
        expected_data = 'iso_to_wbtime return value'

        data = format_claim_value(self.mock_claim, '2021-03-02')
        self.assertEqual(data, expected_data)
        self.mock_iso_to_wbtime.assert_called_once_with('2021-03-02')
Esempio n. 2
0
    def test_format_claim_value_coord_oneliner_allow_space(self):
        self.set_claim_type('globe-coordinate')
        expected_data = pywikibot.Coordinate(55.7, 13.19, precision=0.1)

        data = format_claim_value(self.mock_claim, '55.70@lat, 13.19@lon')
        self.assertEqual(data, expected_data)
        self.assertEqual(self.mock_coord_precision.call_count, 2)
Esempio n. 3
0
    def test_format_claim_value_unitfull_quantity_oneliner(self):
        self.set_claim_type('quantity')
        unit = pywikibot.ItemPage(self.mock_site, 'Q123')
        expected_data = pywikibot.WbQuantity(12.34, unit, site=self.mock_site)

        data = format_claim_value(self.mock_claim, '12.34@Q123')
        self.assertEqual(data, expected_data)
Esempio n. 4
0
    def test_format_claim_value_strings(self):
        string_types = ('string', 'url', 'math', 'external-id',
                        'musical-notation', 'unknown')
        for st in string_types:
            self.set_claim_type('st')
            expected_data = 'foobar'

            data = format_claim_value(self.mock_claim, 'foobar')
            self.assertEqual(data, expected_data)
Esempio n. 5
0
    def test_format_claim_value_coord_use_lesser_precision(self):
        self.set_claim_type('globe-coordinate')
        expected_data = pywikibot.Coordinate(55.7, 13.19, precision=1)

        self.mock_coord_precision.side_effect = [0.1, 1]
        data = format_claim_value(self.mock_claim, {
            'lat': '55.70',
            'lon': '13.19'
        })
        self.assertEqual(data, expected_data)

        # ensure order of precisions are irrelevant
        self.mock_coord_precision.side_effect = [1, 0.1]
        data = format_claim_value(self.mock_claim, {
            'lat': '55.70',
            'lon': '13.19'
        })
        self.assertEqual(data, expected_data)
Esempio n. 6
0
    def test_format_claim_value_monolingual(self):
        self.set_claim_type('monolingualtext')
        expected_data = pywikibot.WbMonolingualText('Foo', 'sv')

        data = format_claim_value(self.mock_claim, {
            'text': 'Foo',
            'lang': 'sv'
        })
        self.assertEqual(data, expected_data)
Esempio n. 7
0
    def test_format_claim_value_coord(self):
        self.set_claim_type('globe-coordinate')
        expected_data = pywikibot.Coordinate(55.7, 13.19, precision=0.1)

        data = format_claim_value(self.mock_claim, {
            'lat': '55.70',
            'lon': '13.19'
        })
        self.assertEqual(data, expected_data)
        self.assertEqual(self.mock_coord_precision.call_count, 2)
Esempio n. 8
0
    def test_format_claim_value_unitless_quantity(self):
        self.set_claim_type('quantity')
        expected_data = pywikibot.WbQuantity(12.34, site=self.mock_site)

        data = format_claim_value(self.mock_claim, '12.34')
        self.assertEqual(data, expected_data)
Esempio n. 9
0
    def test_format_claim_value_filepage_wo_namespace(self):
        self.set_claim_type('commonsMedia')
        expected_data = pywikibot.FilePage(self.mock_commons, 'File:Foo.jpg')

        data = format_claim_value(self.mock_claim, 'Foo.jpg')
        self.assertEqual(data, expected_data)
Esempio n. 10
0
    def test_format_claim_value_item(self):
        self.set_claim_type('wikibase-item')
        expected_data = pywikibot.ItemPage(self.mock_site, 'Q123')

        data = format_claim_value(self.mock_claim, 'Q123')
        self.assertEqual(data, expected_data)