File: compat_test.py

package info (click to toggle)
python-certbot 0.31.0-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,152 kB
  • sloc: python: 17,551; makefile: 171; sh: 31
file content (21 lines) | stat: -rw-r--r-- 736 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Tests for certbot.compat."""
import os

from certbot import compat
import certbot.tests.util as test_util

class OsReplaceTest(test_util.TempDirTestCase):
    """Test to ensure consistent behavior of os_rename method"""

    def test_os_rename_to_existing_file(self):
        """Ensure that os_rename will effectively rename src into dst for all platforms."""
        src = os.path.join(self.tempdir, 'src')
        dst = os.path.join(self.tempdir, 'dst')
        open(src, 'w').close()
        open(dst, 'w').close()

        # On Windows, a direct call to os.rename will fail because dst already exists.
        compat.os_rename(src, dst)

        self.assertFalse(os.path.exists(src))
        self.assertTrue(os.path.exists(dst))