Skip to content

Commit aedb3d4

Browse files
committed
Feature: htmlfile fixture
1 parent 3f71d20 commit aedb3d4

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

yhttp/dev/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.1.3'
1+
__version__ = '3.2.0'

yhttp/dev/fixtures.py

+26
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import socket
44
import tempfile
55
import datetime
6+
import contextlib
67
from unittest.mock import patch
78

89
import pytest
@@ -135,3 +136,28 @@ def close(self):
135136

136137
with patch('redis.Redis', new=RedisMock) as p:
137138
yield p
139+
140+
141+
@pytest.fixture(scope='session')
142+
def htmlfile():
143+
@contextlib.contextmanager
144+
def create(filename, title, cssfile=None):
145+
with open(filename, 'a') as file:
146+
file.truncate(0)
147+
file.write(
148+
'<!DOCTYPE html>\n'
149+
'<html lang="en">\n'
150+
'<head>\n'
151+
'<meta charset="utf-8" />\n'
152+
f'<title>{title}</title>\n'
153+
)
154+
155+
if cssfile:
156+
file.write(f'<link rel="stylesheet" href="{cssfile}" '
157+
'type="text/css" />\n')
158+
159+
file.write('</head><body>\n')
160+
yield file
161+
file.write('</body></html>')
162+
163+
return create

0 commit comments

Comments
 (0)