Skip to content

Commit

Permalink
[test] Properly test iso8859-1 files by sanitizing them
Browse files Browse the repository at this point in the history
  • Loading branch information
tohanss authored Aug 6, 2020
1 parent a13f420 commit 7fe6181
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
1 change: 0 additions & 1 deletion tests/resources/iso8859-1-encoded-file.txt

This file was deleted.

7 changes: 7 additions & 0 deletions tests/resources/iso8859.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--REPOBEE-SANITIZER-START

HELLO WORLD

--REPOBEE-SANITIZER-REPLACE-WITH
--Hello I'm Simon Lars�n and this file is encoded in ISO8859-1
--REPOBEE-SANITIZER-END
1 change: 1 addition & 0 deletions tests/resources/sanitized-iso8859.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello I'm Simon Lars�n and this file is encoded in ISO8859-1
32 changes: 21 additions & 11 deletions tests/test_ext_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,32 @@ def test_target_branch_with_iso8859_file(self, fake_repo):
"""Test sanitize-repo when there are ISO8859 files in the repo. This is to
ensure that we can sanitize using ISO8859 without errors.
"""
file_src_path = testhelpers.get_resource("iso8859-1-encoded-file.txt")
file_dst_path = fake_repo.path / file_src_path.name
shutil.copy(file_src_path, file_dst_path)
in_src_path = testhelpers.get_resource("iso8859.txt")
in_dst_path = fake_repo.path / in_src_path.name
shutil.copy(in_src_path, in_dst_path)

fake_repo.repo.git.add(file_dst_path)
fake_repo.repo.git.commit("-m", "Add ISO8859 file")
sanitized_src_path = testhelpers.get_resource("sanitized-iso8859.txt")
sanitized_dst_path = fake_repo.path / sanitized_src_path.name
shutil.copy(sanitized_src_path, sanitized_dst_path)

relpath = _fileutils.create_relpath(file_dst_path, fake_repo.path)
fake_repo.repo.git.add(sanitized_dst_path)
fake_repo.repo.git.add(in_dst_path)
fake_repo.repo.git.commit("-m", "Add ISO8859 files")

in_rel = _fileutils.create_relpath(in_dst_path, fake_repo.path)
sanitzed_rel = _fileutils.create_relpath(
sanitized_dst_path, fake_repo.path
)

fake_repo.file_infos.append(
_FileInfo(
original_text=relpath.read_text_relative_to(fake_repo.path),
expected_text=relpath.read_text_relative_to(fake_repo.path),
abspath=file_dst_path,
relpath=relpath.__str__(),
encoding=relpath.encoding,
original_text=in_rel.read_text_relative_to(fake_repo.path),
expected_text=sanitzed_rel.read_text_relative_to(
fake_repo.path
),
abspath=in_dst_path,
relpath=in_rel.__str__(),
encoding=in_rel.encoding,
)
)

Expand Down
21 changes: 0 additions & 21 deletions tests/test_fileutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from repobee_sanitizer import _fileutils

import testhelpers


class TestCreateRelativePath:
"""Tests for the create_smart_relpath function."""
Expand Down Expand Up @@ -47,22 +45,3 @@ def test_raises_if_abspath_is_not_contained_in_basedir(self, tmpdir):
assert f"'{abspath}' does not start with '{basedir}'" in str(
exc_info.value
)


class TestRelativePath:
"""Tests for the RelativePath class."""

def test_read_iso8859_1_encoded_file(self):
"""Currently, guessing ISO8859 encodings with the file command often
only gives ``ISO8859``, which is not a complete encoding (i.e. it
should be ``ISO8859-1``, ``ISO8859-2``, etc).
"""
basedir = testhelpers.RESOURCES_BASEDIR
abspath = testhelpers.get_resource("iso8859-1-encoded-file.txt")
expected_text = (
"Hello I'm Simon Larsén and this file is encoded in ISO8859-1"
)

relpath = _fileutils.create_relpath(abspath=abspath, basedir=basedir)

assert relpath.read_text_relative_to(basedir).strip() == expected_text

0 comments on commit 7fe6181

Please sign in to comment.