Skip to content

Commit

Permalink
Tests: Use pathlib for files read/write (test_generate_files.py)
Browse files Browse the repository at this point in the history
  • Loading branch information
insspb committed Jun 8, 2022
1 parent f98f067 commit 8876b10
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tests/test_generate_files.py
Expand Up @@ -44,7 +44,7 @@ def test_generate_files(tmp_path):
assert simple_file.exists()
assert simple_file.is_file()

simple_text = open(simple_file, encoding='utf-8').read()
simple_text = Path(simple_file).open().read()
assert simple_text == 'I eat pizzä'


Expand All @@ -60,7 +60,7 @@ def test_generate_files_with_linux_newline(tmp_path):
assert newline_file.is_file()
assert newline_file.exists()

with open(newline_file, encoding='utf-8', newline='') as f:
with Path(newline_file).open(newline='') as f:
simple_text = f.readline()
assert simple_text == 'newline is LF\n'
assert f.newlines == '\n'
Expand All @@ -83,7 +83,7 @@ def test_generate_files_with_jinja2_environment(tmp_path):
assert conditions_file.is_file()
assert conditions_file.exists()

simple_text = conditions_file.open('rt', encoding='utf-8').read()
simple_text = conditions_file.open('rt').read()
assert simple_text == 'I eat pizzä\n'


Expand All @@ -100,7 +100,7 @@ def test_generate_files_with_trailing_newline_forced_to_linux_by_context(tmp_pat
assert newline_file.is_file()
assert newline_file.exists()

with open(newline_file, encoding='utf-8', newline='') as f:
with Path(newline_file).open(newline='') as f:
simple_text = f.readline()
assert simple_text == 'newline is LF\r\n'
assert f.newlines == '\r\n'
Expand All @@ -118,7 +118,7 @@ def test_generate_files_with_windows_newline(tmp_path):
assert newline_file.is_file()
assert newline_file.exists()

with open(newline_file, encoding='utf-8', newline='') as f:
with Path(newline_file).open(newline='') as f:
simple_text = f.readline()
assert simple_text == 'newline is CRLF\r\n'
assert f.newlines == '\r\n'
Expand All @@ -136,7 +136,7 @@ def test_generate_files_with_windows_newline_forced_to_linux_by_context(tmp_path
assert newline_file.is_file()
assert newline_file.exists()

with open(newline_file, encoding='utf-8', newline='') as f:
with Path(newline_file).open(newline='') as f:
simple_text = f.readline()

assert simple_text == 'newline is CRLF\n'
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_generate_files_with_overwrite_if_exists_with_skip_if_file_exists(tmp_pa
simple_with_new_line_file = Path(tmp_path, 'inputpizzä/simple-with-newline.txt')

Path(tmp_path, 'inputpizzä').mkdir(parents=True)
with open(simple_file, 'w') as f:
with Path(simple_file).open('w') as f:
f.write('temp')

generate.generate_files(
Expand All @@ -257,7 +257,7 @@ def test_generate_files_with_overwrite_if_exists_with_skip_if_file_exists(tmp_pa
assert Path(simple_with_new_line_file).is_file()
assert Path(simple_with_new_line_file).exists()

simple_text = open(simple_file, encoding='utf-8').read()
simple_text = Path(simple_file).open().read()
assert simple_text == 'temp'


Expand All @@ -267,7 +267,7 @@ def test_generate_files_with_skip_if_file_exists(tmp_path):
simple_with_new_line_file = Path(tmp_path, 'inputpizzä/simple-with-newline.txt')

Path(tmp_path, 'inputpizzä').mkdir(parents=True)
with open(simple_file, 'w') as f:
with Path(simple_file).open('w') as f:
f.write('temp')

with pytest.raises(exceptions.OutputDirExistsException):
Expand All @@ -283,7 +283,7 @@ def test_generate_files_with_skip_if_file_exists(tmp_path):
assert not Path(simple_with_new_line_file).is_file()
assert not Path(simple_with_new_line_file).exists()

simple_text = open(simple_file, encoding='utf-8').read()
simple_text = Path(simple_file).open().read()
assert simple_text == 'temp'


Expand All @@ -293,7 +293,7 @@ def test_generate_files_with_overwrite_if_exists(tmp_path):
simple_with_new_line_file = Path(tmp_path, 'inputpizzä/simple-with-newline.txt')

Path(tmp_path, 'inputpizzä').mkdir(parents=True)
with open(simple_file, 'w') as f:
with Path(simple_file).open('w') as f:
f.write('temp')

generate.generate_files(
Expand All @@ -308,7 +308,7 @@ def test_generate_files_with_overwrite_if_exists(tmp_path):
assert Path(simple_with_new_line_file).is_file()
assert Path(simple_with_new_line_file).exists()

simple_text = open(simple_file, encoding='utf-8').read()
simple_text = Path(simple_file).open().read()
assert simple_text == 'I eat pizzä'


Expand Down

0 comments on commit 8876b10

Please sign in to comment.