Skip to content

Commit

Permalink
Use \n instead if \r\n as line separator
Browse files Browse the repository at this point in the history
The logging framework will write to a pipe, which then will blindly transform
all carriage returns to carriage return plus line feed, when on Windows. So
injecting the \r\n leaves us with double carriage return.

Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Jul 24, 2020
1 parent 012d5b5 commit 60b46de
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/virtualenv/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import absolute_import, print_function, unicode_literals

import logging
import os
import sys
from datetime import datetime

Expand Down Expand Up @@ -52,7 +51,7 @@ def __str__(self):
)
if self.session.activators:
lines.append(" activators {}".format(",".join(i.__class__.__name__ for i in self.session.activators)))
return os.linesep.join(lines)
return "\n".join(lines)


def run_with_catch(args=None):
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/config/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __bool__(self):
def epilog(self):
msg = "{}config file {} {} (change{} via env var {})"
return msg.format(
os.linesep,
"\n",
self.config_file,
self.STATE[self.has_config_file],
"d" if self.is_env_var else "",
Expand Down
25 changes: 22 additions & 3 deletions tests/unit/config/test___main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import, unicode_literals

import os
import re
import sys

Expand Down Expand Up @@ -65,8 +66,13 @@ def test_session_report_full(session_app_data, tmp_path, capsys):
r" added seed packages: .*pip==.*, setuptools==.*, wheel==.*",
r" activators .*",
]
_match_regexes(lines, regexes)


def _match_regexes(lines, regexes):
for line, regex in zip(lines, regexes):
assert re.match(regex, line), line
comp_regex = re.compile(r"^{}$".format(regex))
assert comp_regex.match(line), line


def test_session_report_minimal(session_app_data, tmp_path, capsys):
Expand All @@ -78,5 +84,18 @@ def test_session_report_minimal(session_app_data, tmp_path, capsys):
r"created virtual environment .* in \d+ms",
r" creator .*",
]
for line, regex in zip(lines, regexes):
assert re.match(regex, line), line
_match_regexes(lines, regexes)


def test_session_report_subprocess(session_app_data, tmp_path):
# when called via a subprocess the logging framework should flush and POSIX line normalization happen
out = subprocess.check_output(
[sys.executable, "-m", "virtualenv", str(tmp_path), "--activators", "powershell", "--without-pip"],
)
lines = out.decode().split(os.linesep)
regexes = [
r"created virtual environment .* in \d+ms",
r" creator .*",
r" activators .*",
]
_match_regexes(lines, regexes)

0 comments on commit 60b46de

Please sign in to comment.