def test_instantiate_from_instance(self):
     """Test passing instance to factory methods works."""
     t1 = T.utcnow()
     self.assertIsNot(t1, T.fromISOformat(t1))
     self.assertEqual(t1, T.fromISOformat(t1))
     self.assertIsInstance(T.fromISOformat(t1), T)
     self.assertIsNot(t1, T.fromtimestampformat(t1))
     self.assertEqual(t1, T.fromtimestampformat(t1))
     self.assertIsInstance(T.fromtimestampformat(t1), T)
 def test_instantiate_from_instance(self):
     """Test passing instance to factory methods works."""
     t1 = Timestamp.utcnow()
     self.assertIsNot(t1, Timestamp.fromISOformat(t1))
     self.assertEqual(t1, Timestamp.fromISOformat(t1))
     self.assertIsInstance(Timestamp.fromISOformat(t1), Timestamp)
     self.assertIsNot(t1, Timestamp.fromtimestampformat(t1))
     self.assertEqual(t1, Timestamp.fromtimestampformat(t1))
     self.assertIsInstance(Timestamp.fromtimestampformat(t1), Timestamp)
Beispiel #3
0
    def _upcast_dict(map_):
        """Upcast dictionary values."""
        with suppress(KeyError):  # enable doctest
            map_['timestamp'] = Timestamp.fromISOformat(map_['timestamp'])

        map_.update(anon='anon' in map_)
        map_.update(minor='minor' in map_)
        map_.update(userhidden='userhidden' in map_)
        map_.update(commenthidden='commenthidden' in map_)

        map_.setdefault('comment', '')
        map_.setdefault('user', '')

        if 'slots' in map_:  # mw 1.32+
            mainslot = map_['slots'].get('main', {})
            map_['text'] = mainslot.get('*')
            map_['contentmodel'] = mainslot.get('contentmodel')
        else:
            map_['slots'] = None
            map_['text'] = map_.get('*')

        map_.setdefault('sha1')
        if map_['sha1'] is None and map_['text'] is not None:
            map_['sha1'] = hashlib.sha1(
                map_['text'].encode('utf8')).hexdigest()
 def test_build_table_with_check(self):
     """Test buildt table with check option."""
     bot = imagereview.CheckImageBot(check=True, total=0)
     bot.cat = 'Nonexisting page for imagereview'
     table = bot.build_table(save=False, unittest=True)
     if not table:
         self.skipTest('Table of files to review is empty')
     key = list(table.keys())[0]  # py3 comp
     data = table[key]
     item = data[0]
     self.assertIsInstance(key, StringTypes)
     self.assertIsInstance(data, list)
     self.assertIsInstance(item, list)
     self.assertEqual(len(item), 4)
     linkedtitle, uploader, filepage, reason = item
     user, time = uploader
     self.assertIsInstance(linkedtitle, StringTypes)
     self.assertIsInstance(uploader, list)
     self.assertIsInstance(filepage, imagereview.DUP_Image)
     self.assertIsInstance(reason, StringTypes)
     self.assertIsInstance(user, StringTypes)
     self.assertIsInstance(time, StringTypes)
     self.assertEqual(reason, '')
     self.assertEqual(filepage.title(asLink=True, textlink=True),
                      linkedtitle)
     self.assertEqual(user, key)
     self.assertIsInstance(Timestamp.fromISOformat(time), Timestamp)
 def test_iso_format(self):
     t1 = T.utcnow()
     ts1 = t1.toISOformat()
     t2 = T.fromISOformat(ts1)
     ts2 = t2.toISOformat()
     # MediaWiki ISO format doesn't include microseconds
     self.assertNotEqual(t1, t2)
     t1 = t1.replace(microsecond=0)
     self.assertEqual(t1, t2)
     self.assertEqual(ts1, ts2)
 def test_iso_format(self):
     t1 = T.utcnow()
     ts1 = t1.toISOformat()
     t2 = T.fromISOformat(ts1)
     ts2 = t2.toISOformat()
     # MediaWiki ISO format doesn't include microseconds
     self.assertNotEqual(t1, t2)
     t1 = t1.replace(microsecond=0)
     self.assertEqual(t1, t2)
     self.assertEqual(ts1, ts2)
Beispiel #7
0
 def test_iso_format(self):
     """Test conversion from and to ISO format."""
     t1 = Timestamp.utcnow()
     ts1 = t1.isoformat()
     t2 = Timestamp.fromISOformat(ts1)
     ts2 = t2.isoformat()
     # MediaWiki ISO format doesn't include microseconds
     self.assertNotEqual(t1, t2)
     t1 = t1.replace(microsecond=0)
     self.assertEqual(t1, t2)
     self.assertEqual(ts1, ts2)
Beispiel #8
0
 def test_iso_format_with_sep(self):
     """Test conversion from and to ISO format with separator."""
     sep = '*'
     t1 = Timestamp.utcnow().replace(microsecond=0)
     ts1 = t1.isoformat(sep=sep)
     t2 = Timestamp.fromISOformat(ts1, sep=sep)
     ts2 = t2.isoformat(sep=sep)
     self.assertEqual(t1, t2)
     self.assertEqual(t1, t2)
     self.assertEqual(ts1, ts2)
     date, sep, time = ts1.partition(sep)
     time = time.rstrip('Z')
     self.assertEqual(date, str(t1.date()))
     self.assertEqual(time, str(t1.time()))
 def test_iso_format_with_sep(self):
     """Test conversion from and to ISO format with separator."""
     SEP = '*'
     t1 = Timestamp.utcnow().replace(microsecond=0)
     ts1 = t1.isoformat(sep=SEP)
     t2 = Timestamp.fromISOformat(ts1, sep=SEP)
     ts2 = t2.isoformat(sep=SEP)
     self.assertEqual(t1, t2)
     self.assertEqual(t1, t2)
     self.assertEqual(ts1, ts2)
     date, sep, time = ts1.partition(SEP)
     time = time.rstrip('Z')
     self.assertEqual(date, str(t1.date()))
     self.assertEqual(time, str(t1.time()))
Beispiel #10
0
 def test_iso_format(self):
     """Test conversion from and to ISO format."""
     SEP = 'T'
     t1 = Timestamp.utcnow()
     ts1 = t1.isoformat()
     t2 = Timestamp.fromISOformat(ts1)
     ts2 = t2.isoformat()
     # MediaWiki ISO format doesn't include microseconds
     self.assertNotEqual(t1, t2)
     t1 = t1.replace(microsecond=0)
     self.assertEqual(t1, t2)
     self.assertEqual(ts1, ts2)
     date, sep, time = ts1.partition(SEP)
     time = time.rstrip('Z')
     self.assertEqual(date, str(t1.date()))
     self.assertEqual(time, str(t1.time()))
Beispiel #11
0
 def test_iso_format(self):
     """Test conversion from and to ISO format."""
     SEP = 'T'
     t1 = Timestamp.utcnow()
     ts1 = t1.isoformat()
     t2 = Timestamp.fromISOformat(ts1)
     ts2 = t2.isoformat()
     # MediaWiki ISO format doesn't include microseconds
     self.assertNotEqual(t1, t2)
     t1 = t1.replace(microsecond=0)
     self.assertEqual(t1, t2)
     self.assertEqual(ts1, ts2)
     date, sep, time = ts1.partition(SEP)
     time = time.rstrip('Z')
     self.assertEqual(date, str(t1.date()))
     self.assertEqual(time, str(t1.time()))