File: test_powershell.py

package info (click to toggle)
python-virtualenv 20.4.0%2Bds-2%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,592 kB
  • sloc: python: 9,471; sh: 155; ansic: 61; csh: 35; makefile: 10
file content (33 lines) | stat: -rw-r--r-- 1,211 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from __future__ import absolute_import, unicode_literals

import pipes
import sys

import pytest

from virtualenv.activation import PowerShellActivator


@pytest.mark.slow
def test_powershell(activation_tester_class, activation_tester):
    class PowerShell(activation_tester_class):
        def __init__(self, session):
            cmd = "powershell.exe" if sys.platform == "win32" else "pwsh"
            super(PowerShell, self).__init__(PowerShellActivator, session, cmd, "activate.ps1", "ps1")
            self._version_cmd = [cmd, "-c", "$PSVersionTable"]
            self._invoke_script = [cmd, "-ExecutionPolicy", "ByPass", "-File"]
            self.activate_cmd = "."
            self.script_encoding = "utf-16"

        def quote(self, s):
            """powershell double double quote needed for quotes within single quotes"""
            return pipes.quote(s).replace('"', '""')

        def _get_test_lines(self, activate_script):
            # for BATCH utf-8 support need change the character code page to 650001
            return super(PowerShell, self)._get_test_lines(activate_script)

        def invoke_script(self):
            return [self.cmd, "-File"]

    activation_tester(PowerShell)