Skip to content

Commit de40ca5

Browse files
committed
Simplify code
1 parent 915f2d6 commit de40ca5

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
from pathlib import Path
2-
import pytest
32
from subprocess import check_output
3+
import pytest
4+
45

56
@pytest.fixture(scope='module')
67
def text_file():
78
file_path = Path('my_text.txt')
9+
nr_lines, nr_words = 10, 0
810
with open(file_path, 'w') as out_file:
9-
for line_nr in range(1, 11):
10-
for word_nr in range(1, line_nr + 1):
11-
print('bla', file=out_file, end=' ')
12-
print('', file=out_file)
13-
yield file_path
11+
for line_nr in range(nr_lines):
12+
print(' '.join(['bla']*(line_nr + 1)), file=out_file)
13+
nr_words += line_nr + 1
14+
yield file_path, nr_lines, nr_words
1415
file_path.unlink()
1516

17+
1618
def test_wc_l(text_file):
17-
output = check_output(['wc', '-l', text_file])
18-
nr_lines = 10
19+
path, nr_lines, _ = text_file
20+
output = check_output(['wc', '-l', path])
1921
lines, _ = output.decode(encoding='utf-8').split()
2022
assert int(lines) == nr_lines
2123

24+
2225
def test_wc_w(text_file):
23-
output = check_output(['wc', '-w', text_file])
24-
nr_lines = 10
25-
nr_words = 0
26-
for words in range(1, nr_lines + 1):
27-
nr_words += words
28-
lines, _ = output.decode(encoding='utf-8').split()
29-
assert int(lines) == nr_words
26+
path, _, nr_words = text_file
27+
output = check_output(['wc', '-w', path])
28+
words, _ = output.decode(encoding='utf-8').split()
29+
assert int(words) == nr_words

0 commit comments

Comments
 (0)