[Python-3000-checkins] r58747 - python/branches/py3k/Lib/test/test_import.py python/branches/py3k/Lib/test/test_os.py

Guido van Rossum guido at python.org
Thu Nov 1 20:44:37 CET 2007


Two things:

(1) please don't use non-ASCII text in the standard library, even in
test code. Instead, use \uXXXX escapes.

(2) test_sys_path fails on my Ubuntu box:

======================================================================
ERROR: test_sys_path (__main__.UnicodePathsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Lib/test/test_import.py", line 183, in test_sys_path
    mod = __import__("testimport%i" % i)
ImportError: No module named testimport1


On 11/1/07, christian.heimes <python-3000-checkins at python.org> wrote:
> Author: christian.heimes
> Date: Thu Nov  1 20:08:42 2007
> New Revision: 58747
>
> Modified:
>    python/branches/py3k/Lib/test/test_import.py
>    python/branches/py3k/Lib/test/test_os.py
> Log:
> Fixed unit tests for os.environ. Some of the tests didn't test at all because os.environ was empty.
> Added import test for sys.path entries with non ASCII characters. The tests are passing on my Ubuntu box with utf-8 locales but they aren't passing on Windows XP.
>
> Modified: python/branches/py3k/Lib/test/test_import.py
> ==============================================================================
> --- python/branches/py3k/Lib/test/test_import.py        (original)
> +++ python/branches/py3k/Lib/test/test_import.py        Thu Nov  1 20:08:42 2007
> @@ -3,10 +3,11 @@
>  import unittest
>  import os
>  import random
> +import shutil
>  import sys
>  import py_compile
>  import warnings
> -from test.test_support import unlink
> +from test.test_support import unlink, TESTFN, unload
>
>
>  def remove_files(name):
> @@ -157,8 +158,37 @@
>              warnings.simplefilter('error', ImportWarning)
>              self.assertRaises(ImportWarning, __import__, "site-packages")
>
> +class UnicodePathsTests(unittest.TestCase):
> +    SAMPLES = ('test', 'testäöüß', 'testéè', 'test°³²')
> +    path = TESTFN
> +
> +    def setUp(self):
> +        os.mkdir(self.path)
> +        self.syspath = sys.path[:]
> +
> +    def tearDown(self):
> +        shutil.rmtree(self.path)
> +        sys.path = self.syspath
> +
> +    def test_sys_path(self):
> +        for i, subpath in enumerate(self.SAMPLES):
> +            path = os.path.join(self.path, subpath)
> +            os.mkdir(path)
> +            self.failUnless(os.path.exists(path), os.listdir(self.path))
> +            f = open(os.path.join(path, 'testimport%i.py' % i), 'w')
> +            f.write("testdata = 'unicode path %i'\n" % i)
> +            f.close()
> +            sys.path.append(path)
> +            try:
> +                mod = __import__("testimport%i" % i)
> +            except ImportError:
> +                print(path, file=sys.stderr)
> +                raise
> +            self.assertEqual(mod.testdata, 'unicode path %i' % i)
> +            unload("testimport%i" % i)
> +
>  def test_main(verbose=None):
> -    run_unittest(ImportTest)
> +    run_unittest(ImportTest, UnicodePathsTests)
>
>  if __name__ == '__main__':
>      test_main()
>
> Modified: python/branches/py3k/Lib/test/test_os.py
> ==============================================================================
> --- python/branches/py3k/Lib/test/test_os.py    (original)
> +++ python/branches/py3k/Lib/test/test_os.py    Thu Nov  1 20:08:42 2007
> @@ -191,20 +191,26 @@
>  class EnvironTests(mapping_tests.BasicTestMappingProtocol):
>      """check that os.environ object conform to mapping protocol"""
>      type2test = None
> -    def _reference(self):
> -        return {"KEY1":"VALUE1", "KEY2":"VALUE2", "KEY3":"VALUE3"}
> -    def _empty_mapping(self):
> -        os.environ.clear()
> -        return os.environ
> +
>      def setUp(self):
>          self.__save = dict(os.environ)
> -        os.environ.clear()
> +        for key, value in self._reference().items():
> +            os.environ[key] = value
> +
>      def tearDown(self):
>          os.environ.clear()
>          os.environ.update(self.__save)
>
> +    def _reference(self):
> +        return {"KEY1":"VALUE1", "KEY2":"VALUE2", "KEY3":"VALUE3"}
> +
> +    def _empty_mapping(self):
> +        os.environ.clear()
> +        return os.environ
> +
>      # Bug 1110478
>      def test_update2(self):
> +        os.environ.clear()
>          if os.path.exists("/bin/sh"):
>              os.environ.update(HELLO="World")
>              value = os.popen("/bin/sh -c 'echo $HELLO'").read().strip()
> @@ -217,6 +223,10 @@
>              self.assertEquals(type(key), str)
>              self.assertEquals(type(val), str)
>
> +    def test_items(self):
> +        for key, value in self._reference().items():
> +            self.assertEqual(os.environ.get(key), value)
> +
>  class WalkTests(unittest.TestCase):
>      """Tests for os.walk()."""
>
> _______________________________________________
> Python-3000-checkins mailing list
> Python-3000-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-3000-checkins
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000-checkins mailing list