Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common_helper_files
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
common_helper_files
Commits
fd4a5833
Commit
fd4a5833
authored
Jan 09, 2019
by
Peter Weidenbach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rm windows line break in get_list_of_strings
parent
f36ff66f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
6 deletions
+16
-6
fail_safe_file_operations.py
common_helper_files/fail_safe_file_operations.py
+7
-2
setup.py
setup.py
+1
-1
test_fail_safe_file_operations.py
tests/test_fail_safe_file_operations.py
+8
-3
No files found.
common_helper_files/fail_safe_file_operations.py
View file @
fd4a5833
...
@@ -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.
...
...
setup.py
View file @
fd4a5833
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'
,
...
...
tests/test_fail_safe_file_operations.py
View file @
fd4a5833
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\n
c'
,
'ab
\n
c'
)])
def
test_rm_cr
(
input_data
,
expected
):
assert
_rm_cr
(
input_data
)
==
expected
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment