Commits

Piet Delport  committed b03555d

Make doctest pass under Python 2 and 3.

  • Participants
  • Parent commits dcf3b55

Comments (0)

Files changed (2)

File src/pycountry/README.txt

   >>> germany
   <pycountry.db.Country object at 0x...>
   >>> germany.alpha2
-  u'DE'
+  'DE'
   >>> germany.alpha3
-  u'DEU'
+  'DEU'
   >>> germany.numeric
-  u'276'
+  '276'
   >>> germany.name
-  u'Germany'
+  'Germany'
   >>> germany.official_name
-  u'Federal Republic of Germany'
+  'Federal Republic of Germany'
 
 Note that historic countries, defined by the ISO 3166-3 sub-standard are not
 included in this list.
 
   >>> de_st= pycountry.subdivisions.get(code='DE-ST')
   >>> de_st.code
-  u'DE-ST'
+  'DE-ST'
   >>> de_st.name
-  u'Sachsen-Anhalt'
+  'Sachsen-Anhalt'
   >>> de_st.type
-  u'State'
+  'State'
   >>> de_st.country
   <pycountry.db.Country object at 0x...>
 
 
   >>> al_br = pycountry.subdivisions.get(code='AL-BU')
   >>> al_br.code
-  u'AL-BU'
+  'AL-BU'
   >>> al_br.name
-  u'Bulqiz\xeb'
+  'Bulqiz\xeb'
   >>> al_br.type
-  u'District'
+  'District'
   >>> al_br.parent_code
-  u'AL-09'
+  'AL-09'
   >>> al_br.parent
   <pycountry.db.Subdivision object at 0x...>
   >>> al_br.parent.name
-  u'Dib\xebr'
+  'Dib\xebr'
 
 The divisions of a single country can be queried using the country_code index:
 
   >>> latin
   <pycountry.db.Script object at 0x...>
   >>> latin.alpha4
-  u'Latn'
+  'Latn'
   >>> latin.name
-  u'Latin'
+  'Latin'
   >>> latin.numeric
-  u'215'
+  '215'
 
 
 Currencies (ISO 4217)
   >>> argentine_peso
   <pycountry.db.Currency object at 0x...>
   >>> argentine_peso.letter
-  u'ARS'
+  'ARS'
   >>> argentine_peso.name
-  u'Argentine Peso'
+  'Argentine Peso'
   >>> argentine_peso.numeric
-  u'032'
+  '032'
 
 
 Languages (ISO 639)
 
   >>> aragonese = pycountry.languages.get(alpha2='an')
   >>> aragonese.alpha2
-  u'an'
+  'an'
   >>> aragonese.bibliographic
-  u'arg'
+  'arg'
   >>> aragonese.terminology
-  u'arg'
+  'arg'
   >>> aragonese.name
-  u'Aragonese'
+  'Aragonese'
 
 Locales
 =======

File src/pycountry/tests.py

 # $Id$
 """Test harness for pycountry."""
 
+import sys
 import doctest
 import unittest
 
 
+class CompatChecker(doctest.OutputChecker, object):
+    """
+    Python < 3 compatibility checker that strips a leading `u` from results.
+
+    Hopefully, this hack can be removed once either doctest or 2to3 handles
+    unicode literals better.
+    """
+
+    def check_output(self, want, got, optionflags):
+        if got.startswith('u'):
+            got = got[1:]
+        return super(CompatChecker, self).check_output(want, got, optionflags)
+
+
 def test_suite():
+    checker = CompatChecker() if sys.version_info < (3,) else None
     suite = unittest.TestSuite()
     suite.addTest(doctest.DocFileSuite('README.txt',
+                                       checker=checker,
                                        optionflags=doctest.ELLIPSIS))
     return suite