-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from pomponchik/develop
0.0.20
- Loading branch information
Showing
10 changed files
with
157 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ dist | |
*.egg-info | ||
test.py | ||
.coverage | ||
.coverage.* | ||
tests/cli/data/chpok | ||
tests/cli/data/pok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import os | ||
import sys | ||
|
||
|
||
def get_python_file(): | ||
if len(sys.argv) < 2: | ||
print('usage: instld python_file.py [argv ...]', file=sys.stderr) | ||
exit(1) | ||
sys.exit(1) | ||
|
||
return sys.argv[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import os | ||
import sys | ||
import tempfile | ||
import subprocess | ||
from functools import partial | ||
|
||
from io import StringIO | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pytest==7.4.0 | ||
pytest==7.4.1 | ||
coverage==7.2.7 | ||
twine==4.0.2 | ||
wheel==0.40.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import io | ||
import os | ||
import sys | ||
import traceback | ||
from typing import List, Dict, Any, Optional | ||
from dataclasses import dataclass | ||
from subprocess import CalledProcessError | ||
from contextlib import redirect_stdout, redirect_stderr | ||
|
||
import pytest | ||
|
||
from installed.cli.main import start | ||
|
||
|
||
@dataclass | ||
class MainRunResult: | ||
stdout: bytes | ||
stderr: bytes | ||
before_stderr: bytes | ||
returncode: int | ||
command: List[str] | ||
|
||
def check_returncode(self): | ||
if self.returncode != 0: | ||
raise CalledProcessError(self.returncode, self.command) | ||
|
||
@pytest.fixture | ||
def main_runner(): | ||
def runner_function(arguments: List[str], env: Optional[Dict[str, str]] = None, universal_newlines: Optional[bool] = None, **kwargs: Any): | ||
old_excepthook = sys.excepthook | ||
old_argv = sys.argv | ||
old_environ = os.environ | ||
old_exit = sys.exit | ||
old_env = os.environ | ||
|
||
if env is not None: | ||
os.environ = env | ||
|
||
sys.argv = arguments | ||
|
||
class LocalError(Exception): pass | ||
def exit_handler(number): raise LocalError | ||
sys.exit = exit_handler | ||
|
||
stdout_buffer = io.StringIO() | ||
stderr_buffer = io.StringIO() | ||
returncode = 0 | ||
with redirect_stdout(stdout_buffer) as stdout, redirect_stderr(stderr_buffer) as stderr: | ||
try: | ||
start() | ||
stdout = stdout_buffer.getvalue() | ||
stderr = stderr_buffer.getvalue() | ||
before_stderr = str.encode(stderr) | ||
except LocalError: | ||
returncode = 1 | ||
stdout = stdout_buffer.getvalue() | ||
stderr = stderr_buffer.getvalue() | ||
before_stderr = str.encode(stderr) | ||
except Exception as e: | ||
returncode = 1 | ||
sys.excepthook(type(e), e, e.__traceback__) | ||
stdout = stdout_buffer.getvalue() | ||
stderr = stderr_buffer.getvalue() | ||
before_stderr = str.encode(stderr) | ||
if sys.platform.lower() in ('win32',): | ||
stdout = stdout.replace('\n', os.linesep).replace('\r\r', '\r') | ||
stderr = stderr.replace('\n', os.linesep).replace('\r\r', '\r') | ||
finally: | ||
if not (universal_newlines is not None and universal_newlines): | ||
stdout = str.encode(stdout) | ||
stderr = str.encode(stderr) | ||
result = MainRunResult(command=arguments, stdout=stdout, stderr=stderr, before_stderr=before_stderr, returncode=returncode) | ||
|
||
sys.excepthook = old_excepthook | ||
sys.argv = old_argv | ||
os.environ = old_environ | ||
sys.exit = old_exit | ||
os.environ = old_env | ||
|
||
return result | ||
|
||
return runner_function |