Repository: pypa/pip
File: tests/functional/test_configuration.py (Python)

Code before:
        # commands runs inside a subprocess.
        # So we just check if the file can be identified
        global_config_file = get_configuration_files()[kinds.GLOBAL][0]
        result = script.pip("config", "debug")
        assert f"{global_config_file}, exists:" in result.stdout

    def test_editor_does_not_exist(self, script: PipTestEnvironment) -> None:
        """Ensure that FileNotFoundError sets filename correctly"""
        result = script.pip(
            "config", "edit", "--editor", "notrealeditor", expect_error=True
        )
        assert "notrealeditor" in result.stderr

    def test_config_separated(
        self, script: PipTestEnvironment, virtualenv: VirtualEnvironment
    ) -> None:
        """Test that the pip configuration values in the different config sections
        are correctly assigned to their origin files.
        """

        # Use new config file
        new_config_file = get_configuration_files()[kinds.USER][1]

        # Get legacy config file and touch it for testing purposes
        legacy_config_file = get_configuration_files()[kinds.USER][0]
        os.makedirs(legacy_config_file.rsplit("/", 1)[0])
        open(legacy_config_file, "a").close()

        # Site config file
        site_config_file = virtualenv.location / CONFIG_BASENAME

        script.pip("config", "--user", "set", "global.timeout", "60")
        script.pip("config", "--site", "set", "freeze.timeout", "10")

        result = script.pip("config", "debug")

        assert (
            f"{site_config_file}, exists: True\n    freeze.timeout: 10" in result.stdout
        )
        assert (
            f"{new_config_file}, exists: True\n    global.timeout: 60" in result.stdout
        )
        assert re.search(
            rf"{legacy_config_file}, exists: True\n(  {new_config_file}.+\n)+",
            result.stdout,
        )


Review comment (suggestion):
```suggestion
        os.makedirs(os.path.dirname(legacy_config_file))
```

Code after:
        assert re.search(r"user:\n(  .+\n)+", result.stdout)

    def test_site_values(
        self, script: PipTestEnvironment, virtualenv: VirtualEnvironment
    ) -> None:
        """Test that the current environment configuration set using --site
        is correctly displayed under "site".
        """

        # Site config file will be inside the virtualenv
        site_config_file = virtualenv.location / CONFIG_BASENAME

        script.pip("config", "--site", "set", "global.timeout", "60")
        script.pip("config", "--site", "set", "freeze.timeout", "10")

        result = script.pip("config", "debug")
        assert f"{site_config_file}, exists: True" in result.stdout
        assert "global.timeout: 60" in result.stdout
        assert "freeze.timeout: 10" in result.stdout
        assert re.search(r"site:\n(  .+\n)+", result.stdout)

    def test_global_config_file(self, script: PipTestEnvironment) -> None:
        """Test that the system-wide  configuration can be identified"""

        # We cannot  write to system-wide files which might have permissions
        # defined in a way that the tox virtualenvcannot write to those
        # locations. Additionally we cannot patch those paths since pip config
        # commands runs inside a subprocess.
        # So we just check if the file can be identified
        global_config_file = get_configuration_files()[kinds.GLOBAL][0]
        result = script.pip("config", "debug")
        assert f"{global_config_file}, exists:" in result.stdout

    def test_editor_does_not_exist(self, script: PipTestEnvironment) -> None:
        """Ensure that FileNotFoundError sets filename correctly"""
        result = script.pip(
            "config", "edit", "--editor", "notrealeditor", expect_error=True
        )
        assert "notrealeditor" in result.stderr

    def test_config_separated(
        self, script: PipTestEnvironment, virtualenv: VirtualEnvironment
    ) -> None:
        """Test that the pip configuration values in the different config sections
        are correctly assigned to their origin files.
        """

        # Use new config file
        new_config_file = get_configuration_files()[kinds.USER][1]

        # Get legacy config file and touch it for testing purposes