lists.wikimedia.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
List overview
Download
Pywikipedia-svn
June 2013
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
pywikipedia-svn@lists.wikimedia.org
8 participants
103 discussions
Start a n
N
ew thread
SVN: [11634] branches/rewrite/tests/ui_tests.py
by valhallasw@svn.wikimedia.org
09 Jun '13
09 Jun '13
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11634
Revision: 11634 Author: valhallasw Date: 2013-06-09 15:50:19 +0000 (Sun, 09 Jun 2013) Log Message: ----------- + document incorrect colorization behavior + test unix unicode input/output Modified Paths: -------------- branches/rewrite/tests/ui_tests.py Modified: branches/rewrite/tests/ui_tests.py =================================================================== --- branches/rewrite/tests/ui_tests.py 2013-06-09 11:31:40 UTC (rev 11633) +++ branches/rewrite/tests/ui_tests.py 2013-06-09 15:50:19 UTC (rev 11634) @@ -255,6 +255,13 @@ self.assertEqual(newstdout.getvalue(), "") self.assertEqual(newstderr.getvalue(), "normal text light purple text normal text ***") + def testOutputNoncolorizedText_incorrect(self): + ''' This test documents current (incorrect) behavior ''' + pywikibot.config.colorized_output = False + pywikibot.output(u"normal text \03{lightpurple}light purple text\03{default} normal text") + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "normal text \x03{lightpurple}light purple text\x03{default} normal text\n") + @unittest.expectedFailure def testOutputColorCascade(self): pywikibot.config.colorized_output = True @@ -262,9 +269,42 @@ self.assertEqual(newstdout.getvalue(), "") self.assertEqual(newstderr.getvalue(), "normal text \x1b[35;1m light purple \x1b[94;1m light blue \x1b[35;1m light purple \x1b[0m normal text\n\x1b[0m") + def testOutputColorCascade_incorrect(self): + ''' This test documents current (incorrect) behavior ''' + pywikibot.config.colorized_output = True + pywikibot.output(u"normal text \03{lightpurple} light purple \03{lightblue} light blue \03{default} light purple \03{default} normal text") + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "normal text \x1b[35;1m light purple \x1b[94;1m light blue \x1b[0m light purple \x1b[0m normal text\n\x1b[0m") + + class TestTerminalUnicodeUnix(unittest.TestCase): + def setUp(self): + patch() + newstdout.truncate(0) + newstderr.truncate(0) + newstdin.truncate(0) + def tearDown(self): + unpatch() + def testOutputUnicodeText(self): + pywikibot.config.console_encoding = 'utf-8' + pywikibot.output(u"Заглавная_страница") + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), u"Заглавная_страница\n".encode('utf-8')) + + def testInputUnicodeText(self): + pywikibot.config.console_encoding = 'utf-8' + newstdin.write(u"Заглавная_страница\n".encode('utf-8')) + newstdin.seek(0) + + returned = pywikibot.input(u"Википедию? ") + + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), u"Википедию? ".encode('utf-8')) + + self.assertIsInstance(returned, unicode) + self.assertEqual(returned, u"Заглавная_страница") try: try:
1
0
0
0
SVN: [11633] trunk/pywikipedia/family.py
by xqt@svn.wikimedia.org
09 Jun '13
09 Jun '13
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11633
Revision: 11633 Author: xqt Date: 2013-06-09 11:31:40 +0000 (Sun, 09 Jun 2013) Log Message: ----------- mw 1.22wmf5 update from rewrite r11632 Modified Paths: -------------- trunk/pywikipedia/family.py Modified: trunk/pywikipedia/family.py =================================================================== --- trunk/pywikipedia/family.py 2013-06-09 11:30:27 UTC (rev 11632) +++ trunk/pywikipedia/family.py 2013-06-09 11:31:40 UTC (rev 11633) @@ -4710,7 +4710,7 @@ """Return Wikimedia projects version number as a string.""" # Don't use this, use versionnumber() instead. This only exists # to not break family files. - return '1.22wmf4' + return '1.22wmf5' def shared_image_repository(self, code): return ('commons', 'commons')
1
0
0
0
SVN: [11632] branches/rewrite/pywikibot/family.py
by xqt@svn.wikimedia.org
09 Jun '13
09 Jun '13
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11632
Revision: 11632 Author: xqt Date: 2013-06-09 11:30:27 +0000 (Sun, 09 Jun 2013) Log Message: ----------- mw 1.22wmf5 Modified Paths: -------------- branches/rewrite/pywikibot/family.py Modified: branches/rewrite/pywikibot/family.py =================================================================== --- branches/rewrite/pywikibot/family.py 2013-06-08 22:38:42 UTC (rev 11631) +++ branches/rewrite/pywikibot/family.py 2013-06-09 11:30:27 UTC (rev 11632) @@ -937,7 +937,7 @@ """Return Wikimedia projects version number as a string.""" # Don't use this, use versionnumber() instead. This only exists # to not break family files. - return '1.22wmf4' + return '1.22wmf5' def shared_image_repository(self, code): return ('commons', 'commons')
1
0
0
0
SVN: [11631] branches/rewrite/tests/ui_tests.py
by valhallasw@svn.wikimedia.org
09 Jun '13
09 Jun '13
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11631
Revision: 11631 Author: valhallasw Date: 2013-06-08 22:38:42 +0000 (Sat, 08 Jun 2013) Log Message: ----------- + unix coloring tests Modified Paths: -------------- branches/rewrite/tests/ui_tests.py Modified: branches/rewrite/tests/ui_tests.py =================================================================== --- branches/rewrite/tests/ui_tests.py 2013-06-08 22:25:52 UTC (rev 11630) +++ branches/rewrite/tests/ui_tests.py 2013-06-08 22:38:42 UTC (rev 11631) @@ -232,8 +232,40 @@ self.assertIsInstance(returned, unicode) self.assertEqual(returned, "n") + class TestTerminalOutputColorUnix(unittest.TestCase): + def setUp(self): + patch() + newstdout.truncate(0) + newstderr.truncate(0) + newstdin.truncate(0) + def tearDown(self): + unpatch() + def testOutputColorizedText(self): + pywikibot.config.colorized_output = True + pywikibot.output(u"normal text \03{lightpurple}light purple text\03{default} normal text") + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "normal text \x1b[35;1mlight purple text\x1b[0m normal text\n\x1b[0m") + + @unittest.expectedFailure + def testOutputNoncolorizedText(self): + pywikibot.config.colorized_output = False + pywikibot.output(u"normal text \03{lightpurple}light purple text\03{default} normal text") + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "normal text light purple text normal text ***") + + @unittest.expectedFailure + def testOutputColorCascade(self): + pywikibot.config.colorized_output = True + pywikibot.output(u"normal text \03{lightpurple} light purple \03{lightblue} light blue \03{default} light purple \03{default} normal text") + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "normal text \x1b[35;1m light purple \x1b[94;1m light blue \x1b[35;1m light purple \x1b[0m normal text\n\x1b[0m") + + + + + try: try: unittest.main()
1
0
0
0
SVN: [11630] branches/rewrite/tests/ui_tests.py
by valhallasw@svn.wikimedia.org
09 Jun '13
09 Jun '13
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11630
Revision: 11630 Author: valhallasw Date: 2013-06-08 22:25:52 +0000 (Sat, 08 Jun 2013) Log Message: ----------- + UI input tests Modified Paths: -------------- branches/rewrite/tests/ui_tests.py Modified: branches/rewrite/tests/ui_tests.py =================================================================== --- branches/rewrite/tests/ui_tests.py 2013-06-08 22:20:26 UTC (rev 11629) +++ branches/rewrite/tests/ui_tests.py 2013-06-08 22:25:52 UTC (rev 11630) @@ -50,7 +50,7 @@ 'caller_line': 0, 'newline': "\n"} - class TestTerminalUI(unittest.TestCase): + class TestTerminalOutput(unittest.TestCase): def setUp(self): patch() newstdout.truncate(0) @@ -161,7 +161,79 @@ self.assertNotEqual(stderrlines[-1], "\n") + class TestTerminalInput(unittest.TestCase): + def setUp(self): + patch() + newstdout.truncate(0) + newstderr.truncate(0) + newstdin.truncate(0) + def tearDown(self): + unpatch() + + def testInput(self): + newstdin.write("input to read\n") + newstdin.seek(0) + + returned = pywikibot.input("question") + + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "question ") + + self.assertIsInstance(returned, unicode) + self.assertEqual(returned, u"input to read") + + @unittest.expectedFailure + def testInputChoiceDefault(self): + newstdin.write("\n") + newstdin.seek(0) + + returned = pywikibot.inputChoice("question", ["answer 1", "answer 2", "answer 3"], ["A", "N", "S"], "A") + + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "question ([A]nswer 1, a[N]swer 2, an[S]wer 3) ") + + self.assertIsInstance(returned, unicode) + self.assertEqual(returned, "a") + + def testInputChoiceCapital(self): + newstdin.write("N\n") + newstdin.seek(0) + + returned = pywikibot.inputChoice("question", ["answer 1", "answer 2", "answer 3"], ["A", "N", "S"], "A") + + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "question ([A]nswer 1, a[N]swer 2, an[S]wer 3) ") + + self.assertIsInstance(returned, unicode) + self.assertEqual(returned, "n") + + def testInputChoiceNonCapital(self): + newstdin.write("n\n") + newstdin.seek(0) + + returned = pywikibot.inputChoice("question", ["answer 1", "answer 2", "answer 3"], ["A", "N", "S"], "A") + + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "question ([A]nswer 1, a[N]swer 2, an[S]wer 3) ") + + self.assertIsInstance(returned, unicode) + self.assertEqual(returned, "n") + + def testInputChoiceIncorrectAnswer(self): + newstdin.write("X\nN\n") + newstdin.seek(0) + + returned = pywikibot.inputChoice("question", ["answer 1", "answer 2", "answer 3"], ["A", "N", "S"], "A") + + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "question ([A]nswer 1, a[N]swer 2, an[S]wer 3) "*2) + + self.assertIsInstance(returned, unicode) + self.assertEqual(returned, "n") + + + try: try: unittest.main()
1
0
0
0
SVN: [11629] trunk/pywikipedia/catimages.py
by drtrigon@svn.wikimedia.org
09 Jun '13
09 Jun '13
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11629
Revision: 11629 Author: drtrigon Date: 2013-06-08 22:20:26 +0000 (Sat, 08 Jun 2013) Log Message: ----------- improvement; add 24 'Created with ...' categories (from 'Metadata') Modified Paths: -------------- trunk/pywikipedia/catimages.py Modified: trunk/pywikipedia/catimages.py =================================================================== --- trunk/pywikipedia/catimages.py 2013-06-08 22:09:06 UTC (rev 11628) +++ trunk/pywikipedia/catimages.py 2013-06-08 22:20:26 UTC (rev 11629) @@ -189,159 +189,194 @@ def _detect_HeaderAndMetadata(self): # check/look into the file by midnight commander (mc) - #
https://pypi.python.org/pypi/hachoir-metadata
+ # use exif as first hint - in fact gives also image-size, streams, ... -#### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### -#try: -# from hachoir_core.error import error, HachoirError -# from hachoir_core.cmd_line import unicodeFilename -# from hachoir_core.i18n import getTerminalCharset, _ -# from hachoir_core.benchmark import Benchmark -# from hachoir_core.stream import InputStreamError -# from hachoir_core.tools import makePrintable -# from hachoir_parser import createParser, ParserList -# import hachoir_core.config as hachoir_config -# from hachoir_metadata import config -#except ImportError, err: -# raise -# print >>sys.stderr, "Unable to import an Hachoir module: %s" % err -# sys.exit(1) -#from optparse import OptionGroup, OptionParser -#from hachoir_metadata import extractMetadata -#from hachoir_metadata.metadata import extractors as metadata_extractors + exif = self._util_get_DataTags_EXIF() + #print exif + result = { 'Software': exif['Software'] if 'Software' in exif else u'-', + 'Output_Extension': exif['Output_extension'] if 'Output_extension' in exif else u'-', + 'Desc': exif['Desc'] if 'Desc' in exif else u'-', + 'DescProducer': exif['DescProducer'] if 'DescProducer' in exif else u'-', + 'DescCreator': exif['DescCreator'] if 'DescCreator' in exif else u'-', + 'Comment': exif['Comment'] if 'Comment' in exif else u'-', + 'Producer': exif['Producer'] if 'Producer' in exif else u'-',} + #'Comments': exif['Comments'] if 'Comments' in exif else u'-', + #'WorkDesc': exif['WorkDescription'] if 'WorkDescription' in exif else u'-', + ##'Dimensions': tuple(map(int, exif['ImageSize'].split(u'x'))),} + #'Dimensions': tuple(exif['ImageSize'].split(u'x')) if 'ImageSize' in exif else (None, None),} + #'Mode': exif['ColorType'], } + +# TODO: vvv +#* metadata template in commons has to be worked out and code adopted +#* like in 'Streams' a nice content listing of MIDI (exif or music21 - if needed at all?) +#* docu all this stuff in commons +#* docu and do all open things on "commons TODO list" # # -#def parseOptions(): -# parser = OptionParser(usage="%prog [options] files") -# parser.add_option("--type", help=_("Only display file type (description)"), -# action="store_true", default=False) -# parser.add_option("--mime", help=_("Only display MIME type"), -# action="store_true", default=False) -# parser.add_option("--level", -# help=_("Quantity of information to display from 1 to 9 (9 is the maximum)"), -# action="store", default="9", type="choice", -# choices=[ str(choice) for choice in xrange(1,9+1) ]) -# parser.add_option("--raw", help=_("Raw output"), -# action="store_true", default=False) -# parser.add_option("--bench", help=_("Run benchmark"), -# action="store_true", default=False) -# parser.add_option("--force-parser",help=_("List all parsers then exit"), -# type="str") -# parser.add_option("--profiler", help=_("Run profiler"), -# action="store_true", default=False) -# parser.add_option("--quality", help=_("Information quality (0.0=fastest, 1.0=best, and default is 0.5)"), -# action="store", type="float", default="0.5") -# parser.add_option("--maxlen", help=_("Maximum string length in characters, 0 means unlimited (default: %s)" % config.MAX_STR_LENGTH), -# type="int", default=config.MAX_STR_LENGTH) -# parser.add_option("--verbose", help=_("Verbose mode"), -# default=False, action="store_true") -# parser.add_option("--debug", help=_("Debug mode"), -# default=False, action="store_true") # -# values, filename = parser.parse_args() -# if len(filename) == 0: -# parser.print_help() -# sys.exit(1) -# -# # Update limits -# config.MAX_STR_LENGTH = values.maxlen -# if values.raw: -# config.RAW_OUTPUT = True -# -# return values, filename -# -#def processFile(values, filename, -#display_filename=False, priority=None, human=True, display=True): -# charset = getTerminalCharset() -# filename, real_filename = unicodeFilename(filename, charset), filename -# -# # Create parser -# try: -# if values.force_parser: -# tags = [ ("id", values.force_parser), None ] -# else: -# tags = None -# parser = createParser(filename, real_filename=real_filename, tags=tags) -# help(parser) -# print parser.getParserTags() -# print parser.PARSER_TAGS -# for i, item in enumerate(parser.createFields()): -# print item -# if i > 5: -# break -# except InputStreamError, err: -# error(unicode(err)) -# return False -# if not parser: -# error(_("Unable to parse file: %s") % filename) -# return False -# -# # Extract metadata -# extract_metadata = not(values.mime or values.type) -# if extract_metadata: -# try: -# metadata = extractMetadata(parser, values.quality) -# except HachoirError, err: -# error(unicode(err)) -# metadata = None -# if not metadata: -# parser.error(_("Hachoir can't extract metadata, but is able to parse: %s") -# % filename) -# return False -# -# if display: -# # Display metadatas on stdout -# if extract_metadata: -# text = metadata.exportPlaintext(priority=priority, human=human) -# if not text: -# text = [_("(no metadata, priority may be too small)")] -# if display_filename: -# for line in text: -# line = "%s: %s" % (filename, line) -# print makePrintable(line, charset) -# else: -# for line in text: -# print makePrintable(line, charset) -# else: -# if values.type: -# text = parser.description -# else: -# text = parser.mime_type -# if display_filename: -# text = "%s: %s" % (filename, text) -# print text -# return True -# -#### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### -# -# def processFiles(values, filenames, display=True): -# human = not(values.raw) -# ok = True -# priority = int(values.level)*100 + 99 -# display_filename = (1 < len(filenames)) -# for filename in filenames: -# ok &= processFile(values, filename, display_filename, priority, human, display) -# return ok -# -# try: -# # Parser options and initialize Hachoir -# values, filenames = parseOptions() -# -# ok = processFiles(values, filenames) -# except KeyboardInterrupt: -# print _("Program interrupted (CTRL+C).") -# ok = False -# sys.exit(int(not ok)) -# -#### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### +#(* initial audio midi support (music21)) +#[TODO: docu on Commons ... / template ...] - pass +# TODO: if '_detect_History' is not needed here, moveit back into _JpegFile !!! + #print "self._detect_History()" + #print self._detect_History() + #
https://pypi.python.org/pypi/hachoir-metadata
(needs 'core' and 'parser') + # + #from hachoir_core.error import HachoirError + #from hachoir_core.stream import InputStreamError + #from hachoir_parser import createParser + #import hachoir_core.config as hachoir_config + # + #from hachoir_metadata import extractMetadata + # + #hachoir_config.debug = True + #hachoir_config.verbose = True + #hachoir_config.quiet = True + # + ## Create parser + #try: + # parser = createParser(self.file_name.decode('utf-8'), + # real_filename=self.file_name.encode('utf-8'), + # tags=None) + # #print [val for val in enumerate(parser.createFields())] + # desc = parser.description + # ptags = parser.getParserTags() + #except (InputStreamError, AttributeError): + # desc = u'-' + # ptags = {} + # + ## Extract metadata + #try: + # # quality: 0.0 fastest, 1.0 best, and default is 0.5 + # metadata = extractMetadata(parser, 0.5) + # #mtags = dict([(key, metadata.getValues(key)) + # mtags = dict([(key, metadata.getValues(key)) # get, getItem, getItems, getText + # for key in metadata._Metadata__data.keys()#]) + # if metadata.getValues(key)]) + #except (HachoirError, AttributeError): + # mtags = {} + # + ##result = {'parser_desc': desc, 'parserdata': ptags, 'metadata': mtags} + ##print result + #print {'parser_desc': desc, 'parserdata': ptags, 'metadata': mtags} + # + ### Display metadatas on stdout + ##text = metadata.exportPlaintext(priority=None, human=False) + ##if not text: + ## text = [u"(no metadata, priority may be too small, try priority=999)"] + ##print u'\n'.join(text) + + self._properties['Metadata'] = [result] + #print self._properties['Metadata'] + return + def _detect_Properties(self): # get mime-type file-size, ... pass + def _util_get_DataTags_EXIF(self): + #
http://tilloy.net/dev/pyexiv2/tutorial.html
+ # (is UNFORTUNATELY NOT ABLE to handle all tags, e.g. 'FacesDetected', ...) + + if hasattr(self, '_buffer_EXIF'): + return self._buffer_EXIF + res = {} + enable_recovery() # enable recovery from hard crash + try: + if hasattr(pyexiv2, 'ImageMetadata'): + metadata = pyexiv2.ImageMetadata(self.file_name) + metadata.read() + + for key in metadata.exif_keys: + res[key] = metadata[key] + + for key in metadata.iptc_keys: + res[key] = metadata[key] + + for key in metadata.xmp_keys: + res[key] = metadata[key] + else: + image = pyexiv2.Image(self.file_name) + image.readMetadata() + + for key in image.exifKeys(): + res[key] = image[key] + + for key in image.iptcKeys(): + res[key] = image[key] + + #for key in image.xmpKeys(): + # res[key] = image[key] + except IOError: + pass + except RuntimeError: + pass + disable_recovery() # disable since everything worked out fine + + + #
http://www.sno.phy.queensu.ca/~phil/exiftool/
+ # MIGHT BE BETTER TO USE AS PYTHON MODULE; either by wrapper or perlmodule: + #
http://search.cpan.org/~gaas/pyperl-1.0/perlmodule.pod
+ # (or use C++ with embbedded perl to write a python module) + data = Popen("exiftool -j %s" % self.file_name, + shell=True, stdout=PIPE).stdout.read() + if not data: + raise ImportError("exiftool not found!") + try: # work-a-round for badly encoded exif data (from pywikibot/comms/http.py) + data = unicode(data, 'utf-8', errors = 'strict') + except UnicodeDecodeError: + data = unicode(data, 'utf-8', errors = 'replace') + #res = {} + data = re.sub("(?<!\")\(Binary data (?P<size>\d*) bytes\)", "\"(Binary data \g<size> bytes)\"", data) # work-a-round some issue + for item in json.loads(data): + res.update( item ) + #print res + self._buffer_EXIF = res + + return self._buffer_EXIF + + def _detect_History(self): + res = self._util_get_DataTags_EXIF() + + #a = [] + #for k in res.keys(): + # if 'history' in k.lower(): + # a.append( k ) + #for item in sorted(a): + # print item + #
http://tilloy.net/dev/pyexiv2/api.html#pyexiv2.xmp.XmpTag
+ #print [getattr(res['Xmp.xmpMM.History'], item) for item in ['key', 'type', 'name', 'title', 'description', 'raw_value', 'value', ]] + result = [] + i = 1 + while (('Xmp.xmpMM.History[%i]' % i) in res): + data = { 'ID': i, + 'Software': u'-', + 'Timestamp': u'-', + 'Action': u'-', + 'Info': u'-', } + if ('Xmp.xmpMM.History[%i]/stEvt:softwareAgent'%i) in res: + data['Software'] = res['Xmp.xmpMM.History[%i]/stEvt:softwareAgent'%i].value + data['Timestamp'] = res['Xmp.xmpMM.History[%i]/stEvt:when'%i].value + data['Action'] = res['Xmp.xmpMM.History[%i]/stEvt:action'%i].value + if ('Xmp.xmpMM.History[%i]/stEvt:changed'%i) in res: + data['Info'] = res['Xmp.xmpMM.History[%i]/stEvt:changed'%i].value + #print res['Xmp.xmpMM.History[%i]/stEvt:instanceID'%i].value + result.append( data ) + elif ('Xmp.xmpMM.History[%i]/stEvt:parameters'%i) in res: + data['Action'] = res['Xmp.xmpMM.History[%i]/stEvt:action'%i].value + data['Info'] = res['Xmp.xmpMM.History[%i]/stEvt:parameters'%i].value + #data['Action'] = data['Info'].split(' ')[0] + result.append( data ) + else: + pass + i += 1 + + self._features['History'] = result + return + + class _JpegFile(_UnknownFile): # for '_detect_Trained' cascade_files = [(u'Legs', 'haarcascade_lowerbody.xml'), @@ -1965,6 +2000,7 @@ #self._util_drawAxes(mat, 250, 350, im) #self._util_drawAxes(mat, 50, 50, im) +# TODO: compare face and chessboard pose estimations and unify them, then document everything (template in wiki, ...) pywikibot.output(u'result for calibrated camera:\n rot=%s\n perp=%s\n perp2D=%s' % (rot.transpose()[0], perp[:,2], ortho)) pywikibot.output(u'nice would be to do the same for uncalibrated/default cam settings') @@ -2045,68 +2081,6 @@ # cv2.line(im, (x,y), (x+D2norm[0].astype(int),y+D2norm[1].astype(int)), color[i], 1) # cv2.putText(im, label[i], (x+D2norm[0].astype(int),y+D2norm[1].astype(int)), cv2.FONT_HERSHEY_PLAIN, 1., color[i]) - def _util_get_DataTags_EXIF(self): - #
http://tilloy.net/dev/pyexiv2/tutorial.html
- # (is UNFORTUNATELY NOT ABLE to handle all tags, e.g. 'FacesDetected', ...) - - if hasattr(self, '_buffer_EXIF'): - return self._buffer_EXIF - - res = {} - enable_recovery() # enable recovery from hard crash - try: - if hasattr(pyexiv2, 'ImageMetadata'): - metadata = pyexiv2.ImageMetadata(self.image_path) - metadata.read() - - for key in metadata.exif_keys: - res[key] = metadata[key] - - for key in metadata.iptc_keys: - res[key] = metadata[key] - - for key in metadata.xmp_keys: - res[key] = metadata[key] - else: - image = pyexiv2.Image(self.image_path) - image.readMetadata() - - for key in image.exifKeys(): - res[key] = image[key] - - for key in image.iptcKeys(): - res[key] = image[key] - - #for key in image.xmpKeys(): - # res[key] = image[key] - except IOError: - pass - except RuntimeError: - pass - disable_recovery() # disable since everything worked out fine - - - #
http://www.sno.phy.queensu.ca/~phil/exiftool/
- # MIGHT BE BETTER TO USE AS PYTHON MODULE; either by wrapper or perlmodule: - #
http://search.cpan.org/~gaas/pyperl-1.0/perlmodule.pod
- # (or use C++ with embbedded perl to write a python module) - data = Popen("exiftool -j %s" % self.image_path, - shell=True, stdout=PIPE).stdout.read() - if not data: - raise ImportError("exiftool not found!") - try: # work-a-round for badly encoded exif data (from pywikibot/comms/http.py) - data = unicode(data, 'utf-8', errors = 'strict') - except UnicodeDecodeError: - data = unicode(data, 'utf-8', errors = 'replace') - #res = {} - data = re.sub("(?<!\")\(Binary data (?P<size>\d*) bytes\)", "\"(Binary data \g<size> bytes)\"", data) # work-a-round some issue - for item in json.loads(data): - res.update( item ) - #print res - self._buffer_EXIF = res - - return self._buffer_EXIF - def _detect_Faces_EXIF(self): res = self._util_get_DataTags_EXIF() @@ -2282,46 +2256,7 @@ self._features['Faces'] += data return - - def _detect_History(self): - res = self._util_get_DataTags_EXIF() - #a = [] - #for k in res.keys(): - # if 'history' in k.lower(): - # a.append( k ) - #for item in sorted(a): - # print item - #
http://tilloy.net/dev/pyexiv2/api.html#pyexiv2.xmp.XmpTag
- #print [getattr(res['Xmp.xmpMM.History'], item) for item in ['key', 'type', 'name', 'title', 'description', 'raw_value', 'value', ]] - result = [] - i = 1 - while (('Xmp.xmpMM.History[%i]' % i) in res): - data = { 'ID': i, - 'Software': u'-', - 'Timestamp': u'-', - 'Action': u'-', - 'Info': u'-', } - if ('Xmp.xmpMM.History[%i]/stEvt:softwareAgent'%i) in res: - data['Software'] = res['Xmp.xmpMM.History[%i]/stEvt:softwareAgent'%i].value - data['Timestamp'] = res['Xmp.xmpMM.History[%i]/stEvt:when'%i].value - data['Action'] = res['Xmp.xmpMM.History[%i]/stEvt:action'%i].value - if ('Xmp.xmpMM.History[%i]/stEvt:changed'%i) in res: - data['Info'] = res['Xmp.xmpMM.History[%i]/stEvt:changed'%i].value - #print res['Xmp.xmpMM.History[%i]/stEvt:instanceID'%i].value - result.append( data ) - elif ('Xmp.xmpMM.History[%i]/stEvt:parameters'%i) in res: - data['Action'] = res['Xmp.xmpMM.History[%i]/stEvt:action'%i].value - data['Info'] = res['Xmp.xmpMM.History[%i]/stEvt:parameters'%i].value - #data['Action'] = data['Info'].split(' ')[0] - result.append( data ) - else: - pass - i += 1 - - self._features['History'] = result - return - def _util_merge_Regions(self, regs, sub=False, overlap=False, close=False): # sub=False, overlap=False, close=False ; level 0 ; similar regions, similar position (default) # sub=True, overlap=False, close=False ; level 1 ; region contained in other, any shape/size @@ -2964,15 +2899,19 @@ return self._features def _detect_HeaderAndMetadata(self): - result = {} + #_UnknownFile._detect_HeaderAndMetadata(self) + #result = {'Desc': self._properties['Metadata'][0]['Desc'].splitlines()} + result = {'Desc': []} + # extract data from midi file #
http://valentin.dasdeck.com/midi/midifile.htm
#
http://stackoverflow.com/questions/3943149/reading-and-interpreting-data-fr…
ba = bytearray(open(self.file_name, 'rb').read()) i = -1 - for key, data in [('Text', '\x01'), ('Copyright', '\x02'), ('Lyrics', '\x05')]: - result[key] = [] + for key, data in [('Text', '\x01'), ('Copyright', '\x02')]:#, ('Lyrics', '\x05')]: + key = 'Desc' + #result[key] = [] while True: i = ba.find('\xff%s' % data, i+1) if i < 0: # something found? @@ -2981,7 +2920,10 @@ if ba[e] != 0: # length match with string end (00)? e = ba.find('\x00', (i+3+ba[i+2])) result[key].append(ba[i+3:e].decode('latin-1').strip()) - result[key] = u'\n'.join(result[key]) + #result[key] = u'\n'.join(result[key]) + result[key] = u'\n'.join(result[key]) + if not result['Desc']: + result['Desc'] = u'-' ## find specific info in extracted data #print [item.strip() for item in re.findall('Generated .*?\n', result['Text'])] @@ -3076,19 +3018,22 @@ return +#
http://commons.wikimedia.org/wiki/File_formats
_FILETYPES = { '*': _UnknownFile, ( 'image', 'jpeg'): _JpegFile, ( 'image', 'png'): _PngFile, ( 'image', 'gif'): _GifFile, ( 'image', 'tiff'): _TiffFile, ( 'image', 'x-xcf'): _XcfFile, - ( 'image', 'svg+xml'): _SvgFile, + ( 'image', 'svg+xml'): _SvgFile, # unify/merge them? + ('application', 'xml'): _SvgFile, # ('application', 'pdf'): _PdfFile, # djvu: python-djvulibre or python-djvu for djvu support #
http://pypi.python.org/pypi/python-djvulibre/0.3.9
# ( 'image', 'vnd.djvu'): DjvuFile, - ('application', 'ogg'): _OggFile, - ( 'audio', 'midi'): _MidiFile,} + ( 'audio', 'midi'): _MidiFile, + ('application', 'ogg'): _OggFile,} +# ( '?', '?'): _WebMFile,} def GenericFile(file_name): # 'magic' (libmagic) @@ -3327,11 +3272,257 @@ # Category:MIDI files created with GNU LilyPond def _cat_meta_MIDIfilescreatedwithGNULilyPond(self): result = self._info_filter['Metadata'] - relevance = (u"Generated automatically by: GNU LilyPond" in - result[0]['Text']) + relevance = len(result) and ('Desc' in result[0]) and \ + (u"Generated automatically by: GNU LilyPond" in + result[0]['Desc']) return (u'MIDI files created with GNU LilyPond', bool(relevance)) + # Category:Bitmap_from_Inkscape (png) + def _cat_meta_BitmapfromInkscape(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Software' in result[0]) and \ + (u"
www.inkscape.org
" in + result[0]['Software'].lower()) + + return (u'Bitmap from Inkscape', bool(relevance)) + + # Category:Created_with_Inkscape (svg) + def _cat_meta_CreatedwithInkscape(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Output_Extension' in result[0]) and \ + (u"org.inkscape.output.svg.inkscape" in + result[0]['Output_Extension'].lower()) + + return (u'Created with Inkscape', bool(relevance)) + + # Category:Created_with_MATLAB (png) + # Category:Created_with_MATLAB (svg) + def _cat_meta_CreatedwithMATLAB(self): + result = self._info_filter['Metadata'] + relevance = len(result) and \ + ((('Software' in result[0]) and \ + (u"MATLAB, The Mathworks, Inc." in + result[0]['Software'])) \ + or \ + (('Desc' in result[0]) and \ + (u"Matlab Figure" in + result[0]['Desc'])) ) + + return (u'Created with MATLAB', bool(relevance)) + + # Category:Created_with_PLOT2SVG (svg) [new] + def _cat_meta_CreatedwithPLOT2SVG(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Desc' in result[0]) and \ + (u"Converted by PLOT2SVG" in + result[0]['Desc']) + + return (u'Created with PLOT2SVG', bool(relevance)) + + # Category:Created_with_ImageMagick (jpg) + def _cat_meta_CreatedwithImageMagick(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Software' in result[0]) and \ + (u"ImageMagick" in + result[0]['Software']) + + return (u'Created with ImageMagick', bool(relevance)) + + # Category:Created_with_Adobe_ImageReady (png) + def _cat_meta_CreatedwithAdobeImageReady(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Software' in result[0]) and \ + (u"Adobe ImageReady" in + result[0]['Software']) + + return (u'Created with Adobe ImageReady', bool(relevance)) + + # Category:Created_with_Adobe_Photoshop (jpg) + def _cat_meta_CreatedwithAdobePhotoshop(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Software' in result[0]) and \ + (u"Adobe Photoshop" in + result[0]['Software']) + + return (u'Created with Adobe Photoshop', bool(relevance)) + + # Category:Created_with_Picasa (jpg) + def _cat_meta_CreatedwithPicasa(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Software' in result[0]) and \ + (u"Picasa" in + result[0]['Software']) + + return (u'Created with Picasa', bool(relevance)) + + # Category:Created_with_Qtpfsgui (jpg) + def _cat_meta_CreatedwithQtpfsgui(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Software' in result[0]) and \ + (u"Created with opensource tool Qtpfsgui" in + result[0]['Software']) + + return (u'Created with Qtpfsgui', bool(relevance)) + + # Category:Created_with_Autopano (jpg) + def _cat_meta_CreatedwithAutopano(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Software' in result[0]) and \ + (u"Autopano" in + result[0]['Software']) + + return (u'Created with Autopano', bool(relevance)) + + # Category:Created_with_Xmgrace (png) + def _cat_meta_CreatedwithXmgrace(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Software' in result[0]) and \ + (u"Grace" in + result[0]['Software']) + + return (u'Created with Xmgrace', bool(relevance)) + + # Category:Created_with_darktable (jpg) + def _cat_meta_Createdwithdarktable(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Software' in result[0]) and \ + (u"darktable" in + result[0]['Software'].lower()) + + return (u'Created with darktable', bool(relevance)) + + # Category:Created_with_easyHDR (jpg) + def _cat_meta_CreatedwitheasyHDR(self): + result = self._info_filter['Metadata'] + relevance = len(result) and \ + ((('Software' in result[0]) and \ + (u"easyHDR" in + result[0]['Software'])) \ + or \ + (('Comment' in result[0]) and \ + (u"easyHDR" in + result[0]['Comment'])) ) + + return (u'Created with easyHDR', bool(relevance)) + + # Category:Created_with_GIMP (jpg) [new] + def _cat_meta_CreatedwithGIMP(self): + result = self._info_filter['Metadata'] + relevance = len(result) and \ + ((('Software' in result[0]) and \ + (u"GIMP" in + result[0]['Software'])) \ + or \ + (('Comment' in result[0]) and \ + (u"Created with GIMP" in + result[0]['Comment'])) ) + + return (u'Created with GIMP', bool(relevance)) + + # Category:Created_with_R (svg) + def _cat_meta_CreatedwithR(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Desc' in result[0]) and \ + (u"R SVG" in + result[0]['Desc']) + + return (u'Created with R', bool(relevance)) + + # Category:Created_with_VectorFieldPlot (svg) + def _cat_meta_CreatedwithVectorFieldPlot(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Desc' in result[0]) and \ + (u"created with VectorFieldPlot" in + result[0]['Desc']) + + return (u'Created with VectorFieldPlot', bool(relevance)) + + # Category:Created_with_Chemtool (svg) + def _cat_meta_CreatedwithChemtool(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Desc' in result[0]) and \ + (u"Created with Chemtool" in + result[0]['Desc']) + + return (u'Created with Chemtool', bool(relevance)) + + # Category:Created_with_GNU_Octave (svg) + def _cat_meta_CreatedwithGNUOctave(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Desc' in result[0]) and \ + (u"Produced by GNUPLOT" in + result[0]['Desc']) + + return (u'Created with GNU Octave', bool(relevance)) + + # Category:Created_with_GeoGebra (svg) + def _cat_meta_CreatedwithGeoGebra(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('DescProducer' in result[0]) and \ + (u"geogebra.d.W" in + result[0]['DescProducer']) #and \ + #(u"FreeHEP Graphics2D Driver" in + # result[0]['DescCreator']) + + return (u'Created with GeoGebra', bool(relevance)) + + # Category:Created_with_Stella (png) + def _cat_meta_CreatedwithStella(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Comment' in result[0]) and \ + (u"Created using Stella4D" in + result[0]['Comment']) + + return (u'Created with Stella', bool(relevance)) + + # Category:Created_with_PhotoStitch (jpg) + def _cat_meta_CreatedwithPhotoStitch(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Comment' in result[0]) and \ + (u"LEAD Technologies Inc." in + result[0]['Comment']) + + return (u'Created with PhotoStitch', bool(relevance)) + + # Category:Created_with_Scribus (pdf) + def _cat_meta_CreatedwithScribus(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Producer' in result[0]) and \ + (u"Scribus PDF Library" in + result[0]['Producer']) + + return (u'Created with Scribus', bool(relevance)) + + #
Category:Created_with_OpenOffice.org
(pdf) + def _cat_meta_CreatedwithOpenOfficeorg(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Producer' in result[0]) and \ + (u"
OpenOffice.org
" in + result[0]['Producer']) + + return (u'Created with
OpenOffice.org
', bool(relevance)) + + # Category:Created_with_Tux_Paint (pdf) + def _cat_meta_CreatedwithTuxPaint(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Software' in result[0]) and \ + (u"Tux Paint" in + result[0]['Software']) + + return (u'Created with Tux Paint', bool(relevance)) + + # Category:Created_with_Microsoft_Image_Composite_Editor (jpg) + def _cat_meta_CreatedwithMicrosoftImageCompositeEditor(self): + result = self._info_filter['Metadata'] + relevance = len(result) and ('Software' in result[0]) and \ + (u"Microsoft ICE" in + result[0]['Software']) + + return (u'Created with Microsoft Image Composite Editor', bool(relevance)) + +# TODO: make '_cat_meta_general(self)' + # Category:Categorized by DrTrigonBot def _addcat_BOT(self): # - ALWAYS -
1
0
0
0
SVN: [11628] branches/rewrite/tests/ui_tests.py
by valhallasw@svn.wikimedia.org
09 Jun '13
09 Jun '13
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11628
Revision: 11628 Author: valhallasw Date: 2013-06-08 22:09:06 +0000 (Sat, 08 Jun 2013) Log Message: ----------- Additional UI tests, now using pywikibot.* functions Modified Paths: -------------- branches/rewrite/tests/ui_tests.py Modified: branches/rewrite/tests/ui_tests.py =================================================================== --- branches/rewrite/tests/ui_tests.py 2013-06-08 21:23:39 UTC (rev 11627) +++ branches/rewrite/tests/ui_tests.py 2013-06-08 22:09:06 UTC (rev 11628) @@ -100,7 +100,68 @@ self.assertEqual(newstdout.getvalue(), "") self.assertEqual(newstderr.getvalue(), "CRITICAL: CRITICAL\n") - + def test_output(self): + pywikibot.output("output", toStdout=False) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "output\n") + + def test_output(self): + pywikibot.output("output", toStdout=True) + self.assertEqual(newstdout.getvalue(), "output\n") + self.assertEqual(newstderr.getvalue(), "") + + def test_warning(self): + pywikibot.warning("warning") + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "WARNING: warning\n") + + def test_error(self): + pywikibot.error("error") + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "ERROR: error\n") + + def test_log(self): + pywikibot.log("log") + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "") + + def test_critical(self): + pywikibot.critical("critical") + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "CRITICAL: critical\n") + + def test_debug(self): + pywikibot.debug("debug", "test") + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "") + + def test_exception(self): + class TestException(Exception): + pass + try: + raise TestException("Testing Exception") + except TestException: + pywikibot.exception("exception") + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "ERROR: TestException: Testing Exception\n") + + def test_exception(self): + class TestException(Exception): + pass + try: + raise TestException("Testing Exception") + except TestException: + pywikibot.exception("exception", tb=True) + self.assertEqual(newstdout.getvalue(), "") + stderrlines = newstderr.getvalue().split("\n") + self.assertEqual(stderrlines[0], "ERROR: TestException: Testing Exception") + self.assertEqual(stderrlines[1], "Traceback (most recent call last):") + self.assertEqual(stderrlines[3], """ raise TestException("Testing Exception")""") + self.assertEqual(stderrlines[4], "TestException: Testing Exception") + + self.assertNotEqual(stderrlines[-1], "\n") + + try: try: unittest.main()
1
0
0
0
SVN: [11627] branches/rewrite/tests/ui_tests.py
by valhallasw@svn.wikimedia.org
08 Jun '13
08 Jun '13
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11627
Revision: 11627 Author: valhallasw Date: 2013-06-08 21:23:39 +0000 (Sat, 08 Jun 2013) Log Message: ----------- Improved reporting when ui_tests are run as part of setup.py test Modified Paths: -------------- branches/rewrite/tests/ui_tests.py Modified: branches/rewrite/tests/ui_tests.py =================================================================== --- branches/rewrite/tests/ui_tests.py 2013-06-08 21:00:06 UTC (rev 11626) +++ branches/rewrite/tests/ui_tests.py 2013-06-08 21:23:39 UTC (rev 11627) @@ -15,95 +15,92 @@ import StringIO import logging -if __name__ != "__main__": - raise Exception('This test can only be run as single file due to heavy monkey patching') +if __name__ == "__main__": + import sys -import sys + oldstderr = sys.stderr + oldstdout = sys.stdout + oldstdin = sys.stdin -oldstderr = sys.stderr -oldstdout = sys.stdout -oldstdin = sys.stdin + newstdout = cStringIO.StringIO() + newstderr = cStringIO.StringIO() + newstdin = StringIO.StringIO() -newstdout = cStringIO.StringIO() -newstderr = cStringIO.StringIO() -newstdin = StringIO.StringIO() + def patch(): + sys.stdout = newstdout + sys.stderr = newstderr + sys.stdin = newstdin -def patch(): - sys.stdout = newstdout - sys.stderr = newstderr - sys.stdin = newstdin + def unpatch(): + sys.stdout = oldstdout + sys.stderr = oldstderr + sys.stdin = oldstdin -def unpatch(): - sys.stdout = oldstdout - sys.stderr = oldstderr - sys.stdin = oldstdin + try: + patch() + import pywikibot + finally: + unpatch() -try: - patch() - import pywikibot -finally: - unpatch() + from pywikibot.bot import DEBUG, VERBOSE, INFO, STDOUT, INPUT, WARNING, ERROR, CRITICAL -from pywikibot.bot import DEBUG, VERBOSE, INFO, STDOUT, INPUT, WARNING, ERROR, CRITICAL + logger = logging.getLogger('pywiki') + loggingcontext = {'caller_name': "ui_tests", + 'caller_file': "ui_tests", + 'caller_line': 0, + 'newline': "\n"} -logger = logging.getLogger('pywiki') -loggingcontext = {'caller_name': "ui_tests", - 'caller_file': "ui_tests", - 'caller_line': 0, - 'newline': "\n"} + class TestTerminalUI(unittest.TestCase): + def setUp(self): + patch() + newstdout.truncate(0) + newstderr.truncate(0) + newstdin.truncate(0) -class TestTerminalUI(unittest.TestCase): - def setUp(self): - patch() - newstdout.truncate(0) - newstderr.truncate(0) - newstdin.truncate(0) + def tearDown(self): + unpatch() - def tearDown(self): - unpatch() + def testOutputLevels_logging_debug(self): + logger.log(DEBUG, 'debug', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "") - def testOutputLevels_logging_debug(self): - logger.log(DEBUG, 'debug', extra=loggingcontext) - self.assertEqual(newstdout.getvalue(), "") - self.assertEqual(newstderr.getvalue(), "") + def testOutputLevels_logging_verbose(self): + logger.log(VERBOSE, 'verbose', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "") - def testOutputLevels_logging_verbose(self): - logger.log(VERBOSE, 'verbose', extra=loggingcontext) - self.assertEqual(newstdout.getvalue(), "") - self.assertEqual(newstderr.getvalue(), "") + def testOutputLevels_logging_info(self): + logger.log(INFO, 'info', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "info\n") - def testOutputLevels_logging_info(self): - logger.log(INFO, 'info', extra=loggingcontext) - self.assertEqual(newstdout.getvalue(), "") - self.assertEqual(newstderr.getvalue(), "info\n") + def testOutputLevels_logging_stdout(self): + logger.log(STDOUT, 'stdout', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "stdout\n") + self.assertEqual(newstderr.getvalue(), "") - def testOutputLevels_logging_stdout(self): - logger.log(STDOUT, 'stdout', extra=loggingcontext) - self.assertEqual(newstdout.getvalue(), "stdout\n") - self.assertEqual(newstderr.getvalue(), "") + def testOutputLevels_logging_input(self): + logger.log(INPUT, 'input', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "input\n") - def testOutputLevels_logging_input(self): - logger.log(INPUT, 'input', extra=loggingcontext) - self.assertEqual(newstdout.getvalue(), "") - self.assertEqual(newstderr.getvalue(), "input\n") + def testOutputLevels_logging_WARNING(self): + logger.log(WARNING, 'WARNING', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "WARNING: WARNING\n") - def testOutputLevels_logging_WARNING(self): - logger.log(WARNING, 'WARNING', extra=loggingcontext) - self.assertEqual(newstdout.getvalue(), "") - self.assertEqual(newstderr.getvalue(), "WARNING: WARNING\n") + def testOutputLevels_logging_ERROR(self): + logger.log(ERROR, 'ERROR', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "ERROR: ERROR\n") - def testOutputLevels_logging_ERROR(self): - logger.log(ERROR, 'ERROR', extra=loggingcontext) - self.assertEqual(newstdout.getvalue(), "") - self.assertEqual(newstderr.getvalue(), "ERROR: ERROR\n") + def testOutputLevels_logging_CRITICAL(self): + logger.log(CRITICAL, 'CRITICAL', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "CRITICAL: CRITICAL\n") - def testOutputLevels_logging_CRITICAL(self): - logger.log(CRITICAL, 'CRITICAL', extra=loggingcontext) - self.assertEqual(newstdout.getvalue(), "") - self.assertEqual(newstderr.getvalue(), "CRITICAL: CRITICAL\n") - - -if __name__ == '__main__': + try: try: unittest.main() @@ -112,3 +109,10 @@ finally: unpatch() pywikibot.stopme() + +else: + class TestTerminalUI(unittest.TestCase): + @unittest.skip("Terminal UI tests can only be run by directly running tests/ui_tests.py") + def testCannotBeRun(self): + pass +
1
0
0
0
SVN: [11626] branches/rewrite/tests/ui_tests.py
by valhallasw@svn.wikimedia.org
08 Jun '13
08 Jun '13
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11626
Revision: 11626 Author: valhallasw Date: 2013-06-08 21:00:06 +0000 (Sat, 08 Jun 2013) Log Message: ----------- Initial test cases for user interface tests Added Paths: ----------- branches/rewrite/tests/ui_tests.py Added: branches/rewrite/tests/ui_tests.py =================================================================== --- branches/rewrite/tests/ui_tests.py (rev 0) +++ branches/rewrite/tests/ui_tests.py 2013-06-08 21:00:06 UTC (rev 11626) @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- +""" +Tests for the page module. +""" +# +# (C) Pywikipedia bot team, 2008 +# +# Distributed under the terms of the MIT license. +# +__version__ = '$Id: page_tests.py 11625 2013-06-08 19:55:59Z valhallasw $' + + +import unittest +import cStringIO +import StringIO +import logging + +if __name__ != "__main__": + raise Exception('This test can only be run as single file due to heavy monkey patching') + +import sys + +oldstderr = sys.stderr +oldstdout = sys.stdout +oldstdin = sys.stdin + +newstdout = cStringIO.StringIO() +newstderr = cStringIO.StringIO() +newstdin = StringIO.StringIO() + +def patch(): + sys.stdout = newstdout + sys.stderr = newstderr + sys.stdin = newstdin + +def unpatch(): + sys.stdout = oldstdout + sys.stderr = oldstderr + sys.stdin = oldstdin + +try: + patch() + import pywikibot +finally: + unpatch() + +from pywikibot.bot import DEBUG, VERBOSE, INFO, STDOUT, INPUT, WARNING, ERROR, CRITICAL + +logger = logging.getLogger('pywiki') +loggingcontext = {'caller_name': "ui_tests", + 'caller_file': "ui_tests", + 'caller_line': 0, + 'newline': "\n"} + +class TestTerminalUI(unittest.TestCase): + def setUp(self): + patch() + newstdout.truncate(0) + newstderr.truncate(0) + newstdin.truncate(0) + + def tearDown(self): + unpatch() + + def testOutputLevels_logging_debug(self): + logger.log(DEBUG, 'debug', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "") + + def testOutputLevels_logging_verbose(self): + logger.log(VERBOSE, 'verbose', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "") + + def testOutputLevels_logging_info(self): + logger.log(INFO, 'info', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "info\n") + + def testOutputLevels_logging_stdout(self): + logger.log(STDOUT, 'stdout', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "stdout\n") + self.assertEqual(newstderr.getvalue(), "") + + def testOutputLevels_logging_input(self): + logger.log(INPUT, 'input', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "input\n") + + def testOutputLevels_logging_WARNING(self): + logger.log(WARNING, 'WARNING', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "WARNING: WARNING\n") + + def testOutputLevels_logging_ERROR(self): + logger.log(ERROR, 'ERROR', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "ERROR: ERROR\n") + + def testOutputLevels_logging_CRITICAL(self): + logger.log(CRITICAL, 'CRITICAL', extra=loggingcontext) + self.assertEqual(newstdout.getvalue(), "") + self.assertEqual(newstderr.getvalue(), "CRITICAL: CRITICAL\n") + + +if __name__ == '__main__': + try: + try: + unittest.main() + except SystemExit: + pass + finally: + unpatch() + pywikibot.stopme()
1
0
0
0
SVN: [11625] branches/rewrite
by valhallasw@svn.wikimedia.org
08 Jun '13
08 Jun '13
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11625
Revision: 11625 Author: valhallasw Date: 2013-06-08 19:55:59 +0000 (Sat, 08 Jun 2013) Log Message: ----------- Improved extensionability of ItemPage * fromPage now returns the most specialised form in the class hieriarchy, e.g. MyItemPage.fromPage will return MyItemPage objects instead of ItemPage objects. (includes test) * instead of using ParentClass.function, use super(ThisClass, self).function Modified Paths: -------------- branches/rewrite/pywikibot/page.py branches/rewrite/tests/page_tests.py Modified: branches/rewrite/pywikibot/page.py =================================================================== --- branches/rewrite/pywikibot/page.py 2013-06-07 23:51:26 UTC (rev 11624) +++ branches/rewrite/pywikibot/page.py 2013-06-08 19:55:59 UTC (rev 11625) @@ -2415,21 +2415,20 @@ site=pywikibot.DataSite & title=Q42 site=pywikibot.Site & title=Main Page """ - WikibasePage.__init__(self, site, title, ns=0) + super(ItemPage, self).__init__(site, title, ns=0) self.id = title - @staticmethod - def fromPage(page): + @classmethod + def fromPage(cls, page): """ Get the ItemPage based on a Page that links to it """ repo = page.site.data_repository() - i = ItemPage(repo, 'null') + i = cls(repo, 'null') del i.id i._site = page.site i._title = page.title() return i - #return ItemPage(page.site, page.title()) def __make_site(self, dbname): """ @@ -2447,7 +2446,7 @@ args are the values of props """ if force or not hasattr(self, '_content'): - WikibasePage.get(self, force=force, *args) + super(ItemPage, self).get(force=force, *args) #claims self.claims = {} Modified: branches/rewrite/tests/page_tests.py =================================================================== --- branches/rewrite/tests/page_tests.py 2013-06-07 23:51:26 UTC (rev 11624) +++ branches/rewrite/tests/page_tests.py 2013-06-08 19:55:59 UTC (rev 11625) @@ -311,8 +311,11 @@ self.assertEqual(prop.getType(), 'wikibase-item') self.assertEqual(prop.namespace(), 120) + def testItemPageExtensionability(self): + class MyItemPage(pywikibot.ItemPage): + pass + self.assertIsInstance(MyItemPage.fromPage(mainpage), MyItemPage) - # methods that still need tests implemented or expanded: ## def autoFormat(self):
1
0
0
0
← Newer
1
...
5
6
7
8
9
10
11
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
Results per page:
10
25
50
100
200