Commit fd4a5833 by Peter Weidenbach

rm windows line break in get_list_of_strings

parent f36ff66f
...@@ -38,13 +38,18 @@ def get_string_list_from_file(file_path): ...@@ -38,13 +38,18 @@ def get_string_list_from_file(file_path):
''' '''
try: try:
raw = get_binary_from_file(file_path) raw = get_binary_from_file(file_path)
string = raw.decode(encoding='utf_8', errors='replace') raw_string = raw.decode(encoding='utf-8', errors='replace')
return string.split('\n') cleaned_string = _rm_cr(raw_string)
return cleaned_string.split('\n')
except Exception as e: except Exception as e:
logging.error('Could not read file: {} {}'.format(sys.exc_info()[0].__name__, e)) logging.error('Could not read file: {} {}'.format(sys.exc_info()[0].__name__, e))
return [] return []
def _rm_cr(input_string):
return input_string.replace('\r', '')
def write_binary_to_file(file_binary, file_path, overwrite=False, file_copy=False): def write_binary_to_file(file_binary, file_path, overwrite=False, file_copy=False):
''' '''
Fail-safe file write operation. Creates directories if needed. Fail-safe file write operation. Creates directories if needed.
......
from setuptools import setup, find_packages from setuptools import setup, find_packages
VERSION = '0.2' VERSION = '0.2.1'
setup( setup(
name='common_helper_files', name='common_helper_files',
......
import os import os
from tempfile import TemporaryDirectory from tempfile import TemporaryDirectory
import unittest import unittest
import pytest
from common_helper_files import get_binary_from_file, \ from common_helper_files import get_binary_from_file, \
write_binary_to_file, delete_file, get_safe_name, \ write_binary_to_file, delete_file, get_safe_name, \
get_files_in_dir, get_string_list_from_file, \ get_files_in_dir, get_string_list_from_file, \
get_dirs_in_dir, get_directory_for_filename, \ get_dirs_in_dir, get_directory_for_filename, \
create_symlink, get_dir_of_file create_symlink, get_dir_of_file
from common_helper_files.fail_safe_file_operations import _get_counted_file_path from common_helper_files.fail_safe_file_operations import _get_counted_file_path,\
_rm_cr
class Test_FailSafeFileOperations(unittest.TestCase): class Test_FailSafeFileOperations(unittest.TestCase):
...@@ -128,5 +130,8 @@ class Test_FailSafeFileOperations(unittest.TestCase): ...@@ -128,5 +130,8 @@ class Test_FailSafeFileOperations(unittest.TestCase):
self.assertEqual(absolute_file_path_result, self.tmp_dir.name) self.assertEqual(absolute_file_path_result, self.tmp_dir.name)
if __name__ == "__main__": @pytest.mark.parametrize('input_data, expected', [
unittest.main() ('abc', 'abc'),
('ab\r\nc', 'ab\nc')])
def test_rm_cr(input_data, expected):
assert _rm_cr(input_data) == expected
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment