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

Update output stream #52

Merged
merged 1 commit into from
Aug 30, 2024
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
7 changes: 4 additions & 3 deletions pytest_logikal/browser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from contextlib import contextmanager
from importlib import import_module
from pathlib import Path
from sys import stderr
from time import sleep
from typing import Any, Dict, Iterator, Optional, Type

Expand Down Expand Up @@ -78,14 +79,14 @@ def driver(self, **kwargs: Any) -> 'Browser':
@staticmethod
def print(message: str) -> None:
if not BrowserVersion._initial_info:
print(colored('Installing browsers', 'yellow', attrs=['bold']))
print(colored('Installing browsers', 'yellow', attrs=['bold']), file=stderr)
BrowserVersion._initial_info = True
print(f'\n{colored(message, attrs=["bold"])}')
print(f'\n{colored(message, attrs=["bold"])}', file=stderr)

@staticmethod
def final_info() -> None:
if BrowserVersion._initial_info:
print() # trailing newline
print(file=stderr) # trailing newline


class Browser(ABC, WebDriver):
Expand Down
3 changes: 2 additions & 1 deletion pytest_logikal/browser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import shutil
import stat
from pathlib import Path
from sys import stderr
from zipfile import ZipFile

import requests
from tqdm import tqdm


def download(url: str, output: Path) -> Path:
print(f'Downloading "{url}"...')
print(f'Downloading "{url}"...', file=stderr)
data_stream = requests.get(url, stream=True, timeout=30)
total_size = int(data_stream.headers.get('content-length', 0))

Expand Down
3 changes: 2 additions & 1 deletion pytest_logikal/node_install.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import subprocess
from pathlib import Path
from sys import stderr
from typing import Optional

from termcolor import colored
Expand All @@ -8,6 +9,6 @@
def install_node_packages(node_prefix: Optional[Path] = None) -> None:
node_prefix = node_prefix or Path(__file__).parent
if not (node_prefix / 'node_modules').exists():
print(colored('Installing Node.js packages', 'yellow', attrs=['bold']))
print(colored('Installing Node.js packages', 'yellow', attrs=['bold']), file=stderr)
command = ['npm', 'install', '--no-save', '--prefix', str(node_prefix)]
subprocess.run(command, text=True, check=True) # nosec: secure, not using untrusted input
2 changes: 1 addition & 1 deletion requirements/core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ pytest-mypy==0.10.3
pytest-xdist[psutil]==3.6.1
pillow~=10.4
Pygments~=2.18 # pytest code highlighting
logikal-utils~=1.2
logikal-utils~=1.3
pyorbs~=2.1
termcolor~=2.4
34 changes: 17 additions & 17 deletions requirements/dev.txt.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## DO NOT EDIT THIS FILE.
## This is a locked requirements file generated by pyorbs.
##
## Requirements hash: 1ea8944c82f7823b638a753eb759c7d03bc8ac907695415f4bb1f2bbfeb858dd
## Requirements hash: c8834286a36fee83cdc665963b94c85c817abb942d177ae567aeed1e4073b86e
##
###################################################################################################
-e .
Expand All @@ -12,13 +12,13 @@ appdirs==1.4.4
asgiref==3.8.1
astroid==3.2.4
attrs==24.2.0
Babel==2.15.0
babel==2.16.0
backports.tarfile==1.2.0
backports.zoneinfo==0.2.1
bandit==1.7.9
black==24.8.0
build==1.2.1
certifi==2024.7.4
certifi==2024.8.30
cffi==1.17.0
charset-normalizer==3.3.2
click==8.1.7
Expand All @@ -37,29 +37,29 @@ docutils==0.20.1
EditorConfig==0.12.4
exceptiongroup==1.2.2
execnet==2.1.1
factory-boy==3.3.0
Faker==26.2.0
factory_boy==3.3.1
Faker==28.0.0
filelock==3.15.4
h11==0.14.0
html-tag-names==0.1.2
html-void-elements==0.1.0
idna==3.7
idna==3.8
imagesize==1.4.1
importlib_metadata==8.2.0
importlib_resources==6.4.0
importlib_metadata==8.4.0
importlib_resources==6.4.4
inflection==0.5.1
iniconfig==2.0.0
isort==5.13.2
jaraco.classes==3.4.0
jaraco.context==5.3.0
jaraco.context==6.0.1
jaraco.functools==4.0.2
jeepney==0.8.0
Jinja2==3.1.4
jsbeautifier==1.15.1
json5==0.9.25
keyring==25.3.0
logikal-docs==1.1.4
logikal-utils==1.2.0
logikal-utils==1.3.1
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mccabe==0.7.0
Expand All @@ -71,14 +71,14 @@ nh3==0.2.18
outcome==1.3.0.post0
packaging==23.2
pathspec==0.12.1
pbr==6.0.0
pbr==6.1.0
pillow==10.4.0
pip==24.2
pip-licenses==4.4.0
pkginfo==1.10.0
platformdirs==4.2.2
pluggy==1.5.0
prettytable==3.10.2
prettytable==3.11.0
psutil==6.0.0
pycodestyle==2.12.1
pycparser==2.22
Expand All @@ -105,10 +105,10 @@ regex==2023.12.25
requests==2.32.3
requests-toolbelt==1.0.0
rfc3986==2.0.0
rich==13.7.1
rich==13.8.0
SecretStorage==3.3.3
selenium==4.23.1
setuptools==72.1.0
setuptools==74.0.0
six==1.16.0
sniffio==1.3.1
snowballstemmer==2.2.0
Expand All @@ -123,12 +123,12 @@ sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
sqlparse==0.5.1
stevedore==5.2.0
stevedore==5.3.0
termcolor==2.4.0
toml==0.10.2
tomli==2.0.1
tomli_w==1.0.0
tomlkit==0.13.0
tomlkit==0.13.2
tqdm==4.66.5
trio==0.26.2
trio-websocket==0.11.1
Expand All @@ -144,4 +144,4 @@ websocket-client==1.8.0
wheel==0.44.0
wsproto==1.2.0
xdg==5.1.1
zipp==3.19.2
zipp==3.20.1
30 changes: 15 additions & 15 deletions requirements/docs.txt.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## DO NOT EDIT THIS FILE.
## This is a locked requirements file generated by pyorbs.
##
## Requirements hash: 9067321e1e54d10ffd36457834a9a2b827e75d1a58618f834950aa4702a36039
## Requirements hash: 4b75d0398c735def701d026561fa317f86d8c1c497c4f329e83197bb8f6bf0e2
##
###################################################################################################
-e .
Expand All @@ -12,11 +12,11 @@ appdirs==1.4.4
asgiref==3.8.1
astroid==3.2.4
attrs==24.2.0
Babel==2.15.0
babel==2.16.0
backports.zoneinfo==0.2.1
bandit==1.7.9
black==24.8.0
certifi==2024.7.4
certifi==2024.8.30
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
Expand All @@ -33,23 +33,23 @@ docutils==0.20.1
EditorConfig==0.12.4
exceptiongroup==1.2.2
execnet==2.1.1
factory-boy==3.3.0
Faker==26.2.0
factory_boy==3.3.1
Faker==28.0.0
filelock==3.15.4
h11==0.14.0
html-tag-names==0.1.2
html-void-elements==0.1.0
idna==3.7
idna==3.8
imagesize==1.4.1
importlib_metadata==8.2.0
importlib_metadata==8.4.0
inflection==0.5.1
iniconfig==2.0.0
isort==5.13.2
Jinja2==3.1.4
jsbeautifier==1.15.1
json5==0.9.25
logikal-docs==1.1.4
logikal-utils==1.2.0
logikal-utils==1.3.1
markdown-it-py==3.0.0
MarkupSafe==2.1.5
mccabe==0.7.0
Expand All @@ -59,13 +59,13 @@ mypy-extensions==1.0.0
outcome==1.3.0.post0
packaging==23.2
pathspec==0.12.1
pbr==6.0.0
pbr==6.1.0
pillow==10.4.0
pip==24.2
pip-licenses==4.4.0
platformdirs==4.2.2
pluggy==1.5.0
prettytable==3.10.2
prettytable==3.11.0
psutil==6.0.0
pycodestyle==2.12.1
pydocstyle==6.3.0
Expand All @@ -87,9 +87,9 @@ pytz==2024.1
PyYAML==6.0.2
regex==2023.12.25
requests==2.32.3
rich==13.7.1
rich==13.8.0
selenium==4.23.1
setuptools==72.1.0
setuptools==74.0.0
six==1.16.0
sniffio==1.3.1
snowballstemmer==2.2.0
Expand All @@ -104,11 +104,11 @@ sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
sqlparse==0.5.1
stevedore==5.2.0
stevedore==5.3.0
termcolor==2.4.0
toml==0.10.2
tomli==2.0.1
tomlkit==0.13.0
tomlkit==0.13.2
tqdm==4.66.5
trio==0.26.2
trio-websocket==0.11.1
Expand All @@ -121,4 +121,4 @@ websocket-client==1.8.0
wheel==0.44.0
wsproto==1.2.0
xdg==5.1.1
zipp==3.19.2
zipp==3.20.1
2 changes: 1 addition & 1 deletion requirements/extras/django.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ pytest-factoryboy==2.7.0

# Validator
requests~=2.32
logikal-utils[docker]~=1.2
logikal-utils[docker]~=1.3
6 changes: 3 additions & 3 deletions tests/pytest_logikal/browser/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from pytest_logikal.browser import base


def test_browser_version_print(mocker: MockerFixture, capsys: pytest.CaptureFixture[str]) -> None:
def test_browser_version_print(mocker: MockerFixture, capfd: pytest.CaptureFixture[str]) -> None:
mocker.patch(
'pytest_logikal.browser.base.BrowserVersion._initial_info',
new_callable=mocker.PropertyMock,
return_value=False,
)

base.BrowserVersion.print('test')
assert 'Installing browsers' in capsys.readouterr().out
assert 'Installing browsers' in capfd.readouterr().err

base.BrowserVersion.final_info()
assert capsys.readouterr().out == '\n'
assert capfd.readouterr().err == '\n'