Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use \n instead if \r\n as line separator #1905

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog/1905.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use ``\n`` instead if ``\r\n`` as line separator for report (because Python already performs this transformation
automatically upon write to the logging pipe) - by :user:`gaborbernat`.
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)