Exemplo n.º 1
0
 def test_unwritable_directory(self):
     with temp_umask(146):
         __import__(TESTFN)
     self.assertTrue(os.path.exists('__pycache__'))
     pyc_path = importlib.util.cache_from_source(self.source)
     self.assertFalse(os.path.exists(pyc_path),
         'bytecode file {!r} for {!r} exists'.format(pyc_path, TESTFN))
Exemplo n.º 2
0
 def test_unwritable_directory(self):
     # When the umask causes the new __pycache__ directory to be
     # unwritable, the import still succeeds but no .pyc file is written.
     with temp_umask(0o222):
         __import__(TESTFN)
     self.assertTrue(os.path.exists("__pycache__"))
     self.assertFalse(os.path.exists(os.path.join("__pycache__", "{}.{}.pyc".format(TESTFN, self.tag))))
Exemplo n.º 3
0
 def test_unwritable_directory(self):
     # When the umask causes the new __pycache__ directory to be
     # unwritable, the import still succeeds but no .pyc file is written.
     with temp_umask(0o222):
         __import__(TESTFN)
     self.assertTrue(os.path.exists('__pycache__'))
     self.assertFalse(os.path.exists(os.path.join(
         '__pycache__', '{}.{}.pyc'.format(TESTFN, self.tag))))
Exemplo n.º 4
0
 def test_unwritable_directory(self):
     # When the umask causes the new __pycache__ directory to be
     # unwritable, the import still succeeds but no .pyc file is written.
     with temp_umask(0o222):
         __import__(TESTFN)
     self.assertTrue(os.path.exists("__pycache__"))
     pyc_path = importlib.util.cache_from_source(self.source)
     self.assertFalse(os.path.exists(pyc_path), "bytecode file {!r} for {!r} " "exists".format(pyc_path, TESTFN))
Exemplo n.º 5
0
 def test_unwritable_directory(self):
     # When the umask causes the new __pycache__ directory to be
     # unwritable, the import still succeeds but no .pyc file is written.
     with temp_umask(0o222):
         __import__(TESTFN)
     self.assertTrue(os.path.exists('__pycache__'))
     pyc_path = importlib.util.cache_from_source(self.source)
     self.assertFalse(
         os.path.exists(pyc_path), 'bytecode file {!r} for {!r} '
         'exists'.format(pyc_path, TESTFN))
Exemplo n.º 6
0
 def test_creation_mode(self):
     mask = 18
     with temp_umask(mask), _ready_to_import() as (name, path):
         cached_path = importlib.util.cache_from_source(path)
         module = __import__(name)
         if not os.path.exists(cached_path):
             self.fail(
                 '__import__ did not result in creation of a .pyc file')
         stat_info = os.stat(cached_path)
     self.assertEqual(oct(stat.S_IMODE(stat_info.st_mode)), oct(438 & ~mask)
         )
Exemplo n.º 7
0
 def test_cached_mode_issue_2051(self):
     mode = 384
     with temp_umask(18), _ready_to_import() as (name, path):
         cached_path = importlib.util.cache_from_source(path)
         os.chmod(path, mode)
         __import__(name)
         if not os.path.exists(cached_path):
             self.fail(
                 '__import__ did not result in creation of a .pyc file')
         stat_info = os.stat(cached_path)
     self.assertEqual(oct(stat.S_IMODE(stat_info.st_mode)), oct(mode))
Exemplo n.º 8
0
    def test_cached_mode_issue_2051(self):
        # permissions of .pyc should match those of .py, regardless of mask
        mode = 0o600
        with temp_umask(0o022), _ready_to_import() as (name, path):
            cached_path = importlib.util.cache_from_source(path)
            os.chmod(path, mode)
            __import__(name)
            if not os.path.exists(cached_path):
                self.fail("__import__ did not result in creation of " "a .pyc file")
            stat_info = os.stat(cached_path)

        self.assertEqual(oct(stat.S_IMODE(stat_info.st_mode)), oct(mode))
Exemplo n.º 9
0
    def test_cached_readonly(self):
        mode = 0o400
        with temp_umask(0o022), _ready_to_import() as (name, path):
            cached_path = importlib.util.cache_from_source(path)
            os.chmod(path, mode)
            __import__(name)
            if not os.path.exists(cached_path):
                self.fail("__import__ did not result in creation of " "a .pyc file")
            stat_info = os.stat(cached_path)

        expected = mode | 0o200  # Account for fix for issue #6074
        self.assertEqual(oct(stat.S_IMODE(stat_info.st_mode)), oct(expected))
Exemplo n.º 10
0
    def test_creation_mode(self):
        mask = 0o022
        with temp_umask(mask), _ready_to_import() as (name, path):
            cached_path = importlib.util.cache_from_source(path)
            module = __import__(name)
            if not os.path.exists(cached_path):
                self.fail("__import__ did not result in creation of " "a .pyc file")
            stat_info = os.stat(cached_path)

        # Check that the umask is respected, and the executable bits
        # aren't set.
        self.assertEqual(oct(stat.S_IMODE(stat_info.st_mode)), oct(0o666 & ~mask))
Exemplo n.º 11
0
    def test_cached_readonly(self):
        mode = 0o400
        with temp_umask(0o022), _ready_to_import() as (name, path):
            cached_path = importlib.util.cache_from_source(path)
            os.chmod(path, mode)
            __import__(name)
            if not os.path.exists(cached_path):
                self.fail("__import__ did not result in creation of "
                          "a .pyc file")
            stat_info = os.stat(cached_path)

        expected = mode | 0o200  # Account for fix for issue #6074
        self.assertEqual(oct(stat.S_IMODE(stat_info.st_mode)), oct(expected))
Exemplo n.º 12
0
    def test_cached_mode_issue_2051(self):
        # permissions of .pyc should match those of .py, regardless of mask
        mode = 0o600
        with temp_umask(0o022), _ready_to_import() as (name, path):
            cached_path = importlib.util.cache_from_source(path)
            os.chmod(path, mode)
            __import__(name)
            if not os.path.exists(cached_path):
                self.fail("__import__ did not result in creation of "
                          "a .pyc file")
            stat_info = os.stat(cached_path)

        self.assertEqual(oct(stat.S_IMODE(stat_info.st_mode)), oct(mode))
Exemplo n.º 13
0
    def test_creation_mode(self):
        mask = 0o022
        with temp_umask(mask), _ready_to_import() as (name, path):
            cached_path = importlib.util.cache_from_source(path)
            module = __import__(name)
            if not os.path.exists(cached_path):
                self.fail("__import__ did not result in creation of "
                          "a .pyc file")
            stat_info = os.stat(cached_path)

        # Check that the umask is respected, and the executable bits
        # aren't set.
        self.assertEqual(oct(stat.S_IMODE(stat_info.st_mode)),
                         oct(0o666 & ~mask))
Exemplo n.º 14
0
 def test_creation_mode(self):
     mask = 0o022
     with temp_umask(mask):
         sys.path.insert(0, os.curdir)
         try:
             fname = TESTFN + os.extsep + "py"
             create_empty_file(fname)
             fn = imp.cache_from_source(fname)
             unlink(fn)
             importlib.invalidate_caches()
             __import__(TESTFN)
             if not os.path.exists(fn):
                 self.fail("__import__ did not result in creation of " "either a .pyc or .pyo file")
             s = os.stat(fn)
             # Check that the umask is respected, and the executable bits
             # aren't set.
             self.assertEqual(stat.S_IMODE(s.st_mode), 0o666 & ~mask)
         finally:
             del sys.path[0]
             remove_files(TESTFN)
             unload(TESTFN)
Exemplo n.º 15
0
 def test_creation_mode(self):
     mask = 0o022
     with temp_umask(mask):
         sys.path.insert(0, os.curdir)
         try:
             fname = TESTFN + os.extsep + "py"
             create_empty_file(fname)
             fn = imp.cache_from_source(fname)
             unlink(fn)
             importlib.invalidate_caches()
             __import__(TESTFN)
             if not os.path.exists(fn):
                 self.fail("__import__ did not result in creation of "
                           "either a .pyc or .pyo file")
             s = os.stat(fn)
             # Check that the umask is respected, and the executable bits
             # aren't set.
             self.assertEqual(stat.S_IMODE(s.st_mode), 0o666 & ~mask)
         finally:
             del sys.path[0]
             remove_files(TESTFN)
             unload(TESTFN)
 def test_execute_bit_not_copied(self):
     # Issue 6070: under posix .pyc files got their execute bit set if
     # the .py file had the execute bit set, but they aren't executable.
     with temp_umask(0o022):
         sys.path.insert(0, os.curdir)
         try:
             fname = TESTFN + os.extsep + "py"
             open(fname, 'w').close()
             os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH
                              | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH))
             fn = imp.cache_from_source(fname)
             unlink(fn)
             __import__(TESTFN)
             if not os.path.exists(fn):
                 self.fail("__import__ did not result in creation of "
                           "either a .pyc or .pyo file")
             s = os.stat(fn)
             self.assertEqual(stat.S_IMODE(s.st_mode),
                              stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
         finally:
             del sys.path[0]
             remove_files(TESTFN)
             unload(TESTFN)
Exemplo n.º 17
0
 def test_execute_bit_not_copied(self):
     # Issue 6070: under posix .pyc files got their execute bit set if
     # the .py file had the execute bit set, but they aren't executable.
     with temp_umask(0o022):
         sys.path.insert(0, os.curdir)
         try:
             fname = TESTFN + os.extsep + "py"
             open(fname, 'w').close()
             os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH |
                              stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH))
             fn = imp.cache_from_source(fname)
             unlink(fn)
             __import__(TESTFN)
             if not os.path.exists(fn):
                 self.fail("__import__ did not result in creation of "
                           "either a .pyc or .pyo file")
             s = os.stat(fn)
             self.assertEqual(stat.S_IMODE(s.st_mode),
                              stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
         finally:
             del sys.path[0]
             remove_files(TESTFN)
             unload(TESTFN)