Skip to content

Commit

Permalink
Fix tests on Windows: Ignore different line endings styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Croydon authored and SSE4 committed Apr 21, 2019
1 parent a6588e2 commit d21e06f
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions tests/test_update_file.py
Expand Up @@ -4,7 +4,6 @@
from bincrafters_conventions.bincrafters_conventions import Command

import tempfile
import filecmp
from shutil import copyfile


Expand All @@ -24,6 +23,20 @@ def _prepare_old_file(file_name: str, suffix: str, old = "", expected=""):
return path_old, expected_path


def _compare_file(path_old: str, expected_path: str):
""" This is needed to ignore differnt line endings styles
e.g. filecmp.cmp would throw an error with differnt line ending
"""
l1 = l2 = True
with open(path_old, 'r') as f1, open(expected_path, 'r') as f2:
while l1 and l2:
l1 = f1.readline()
l2 = f2.readline()
if l1 != l2:
return False
return True


def test_updated_conanfile():
""" Try to update an already up-to-date file, nothing should change
"""
Expand All @@ -34,7 +47,7 @@ def test_updated_conanfile():
command = Command()
command.run(args)

assert filecmp.cmp(path_old, path_expected)
assert _compare_file(path_old, path_expected)


def test_conanfile_default_options():
Expand All @@ -47,7 +60,7 @@ def test_conanfile_default_options():
command = Command()
command.run(args)

assert filecmp.cmp(path_old, path_expected)
assert _compare_file(path_old, path_expected)


def test_conanfile_default_options_mutiline():
Expand All @@ -60,7 +73,7 @@ def test_conanfile_default_options_mutiline():
command = Command()
command.run(args)

assert filecmp.cmp(path_old, path_expected)
assert _compare_file(path_old, path_expected)


def test_appveyor_update_up_to_date():
Expand All @@ -73,7 +86,7 @@ def test_appveyor_update_up_to_date():
command = Command()
command.run(args)

assert filecmp.cmp(path_old, path_expected)
assert _compare_file(path_old, path_expected)


def test_appveyor_update():
Expand All @@ -86,7 +99,7 @@ def test_appveyor_update():
command = Command()
command.run(args)

assert filecmp.cmp(path_old, path_expected)
assert _compare_file(path_old, path_expected)


def test_appveyor_update_new_compiler_jobs():
Expand All @@ -99,7 +112,7 @@ def test_appveyor_update_new_compiler_jobs():
command = Command()
command.run(args)

assert filecmp.cmp(path_old, path_expected)
assert _compare_file(path_old, path_expected)


def test_update_travis_file():
Expand All @@ -112,7 +125,7 @@ def test_update_travis_file():
command = Command()
command.run(args)

assert filecmp.cmp(path_old, path_expected)
assert _compare_file(path_old, path_expected)

def test_update_travis_file_with_global():
""" Create a standard travis file and update it.
Expand All @@ -124,7 +137,7 @@ def test_update_travis_file_with_global():
command = Command()
command.run(args)

assert filecmp.cmp(path_old, path_expected)
assert _compare_file(path_old, path_expected)


def test_travis_update_url():
Expand All @@ -137,4 +150,4 @@ def test_travis_update_url():
command = Command()
command.run(args)

assert filecmp.cmp(path_old, path_expected)
assert _compare_file(path_old, path_expected)

0 comments on commit d21e06f

Please sign in to comment.