~ubuntu-branches/ubuntu/trusty/python3.4/trusty-proposed

« back to all changes in this revision

Viewing changes to Lib/test/test_importlib/extension/test_case_sensitivity.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-11-25 09:44:27 UTC
  • Revision ID: package-import@ubuntu.com-20131125094427-lzxj8ap5w01lmo7f
Tags: upstream-3.4~b1
ImportĀ upstreamĀ versionĀ 3.4~b1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from importlib import _bootstrap
 
2
import sys
 
3
from test import support
 
4
import unittest
 
5
 
 
6
from .. import util
 
7
from . import util as ext_util
 
8
 
 
9
frozen_machinery, source_machinery = util.import_importlib('importlib.machinery')
 
10
 
 
11
 
 
12
# XXX find_spec tests
 
13
 
 
14
@unittest.skipIf(ext_util.FILENAME is None, '_testcapi not available')
 
15
@util.case_insensitive_tests
 
16
class ExtensionModuleCaseSensitivityTest:
 
17
 
 
18
    def find_module(self):
 
19
        good_name = ext_util.NAME
 
20
        bad_name = good_name.upper()
 
21
        assert good_name != bad_name
 
22
        finder = self.machinery.FileFinder(ext_util.PATH,
 
23
                                          (self.machinery.ExtensionFileLoader,
 
24
                                           self.machinery.EXTENSION_SUFFIXES))
 
25
        return finder.find_module(bad_name)
 
26
 
 
27
    def test_case_sensitive(self):
 
28
        with support.EnvironmentVarGuard() as env:
 
29
            env.unset('PYTHONCASEOK')
 
30
            if b'PYTHONCASEOK' in _bootstrap._os.environ:
 
31
                self.skipTest('os.environ changes not reflected in '
 
32
                              '_os.environ')
 
33
            loader = self.find_module()
 
34
            self.assertIsNone(loader)
 
35
 
 
36
    def test_case_insensitivity(self):
 
37
        with support.EnvironmentVarGuard() as env:
 
38
            env.set('PYTHONCASEOK', '1')
 
39
            if b'PYTHONCASEOK' not in _bootstrap._os.environ:
 
40
                self.skipTest('os.environ changes not reflected in '
 
41
                              '_os.environ')
 
42
            loader = self.find_module()
 
43
            self.assertTrue(hasattr(loader, 'load_module'))
 
44
 
 
45
Frozen_ExtensionCaseSensitivity, Source_ExtensionCaseSensitivity = util.test_both(
 
46
        ExtensionModuleCaseSensitivityTest,
 
47
        machinery=[frozen_machinery, source_machinery])
 
48
 
 
49
 
 
50
if __name__ == '__main__':
 
51
    unittest.main()