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-depend
common_helper_files
Commits
a6f2d22f
Commit
a6f2d22f
authored
Dec 03, 2021
by
Marten Ringwelski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inline _rm_cr
parent
dd46ab43
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
14 deletions
+2
-14
fail_safe_file_operations.py
common_helper_files/fail_safe_file_operations.py
+1
-5
test_fail_safe_file_operations.py
tests/test_fail_safe_file_operations.py
+1
-9
No files found.
common_helper_files/fail_safe_file_operations.py
View file @
a6f2d22f
...
@@ -40,14 +40,10 @@ def get_string_list_from_file(file_path: Union[str, Path]) -> List[str]:
...
@@ -40,14 +40,10 @@ def get_string_list_from_file(file_path: Union[str, Path]) -> List[str]:
'''
'''
raw
=
get_binary_from_file
(
file_path
)
raw
=
get_binary_from_file
(
file_path
)
raw_string
=
raw
.
decode
(
encoding
=
'utf-8'
,
errors
=
'replace'
)
raw_string
=
raw
.
decode
(
encoding
=
'utf-8'
,
errors
=
'replace'
)
cleaned_string
=
_rm_cr
(
raw_string
)
cleaned_string
=
raw_string
.
replace
(
'
\r
'
,
''
)
return
cleaned_string
.
split
(
'
\n
'
)
return
cleaned_string
.
split
(
'
\n
'
)
def
_rm_cr
(
input_string
):
return
input_string
.
replace
(
'
\r
'
,
''
)
def
write_binary_to_file
(
file_binary
:
Union
[
str
,
bytes
],
file_path
:
Union
[
str
,
Path
],
overwrite
:
bool
=
False
,
file_copy
:
bool
=
False
)
->
None
:
def
write_binary_to_file
(
file_binary
:
Union
[
str
,
bytes
],
file_path
:
Union
[
str
,
Path
],
overwrite
:
bool
=
False
,
file_copy
:
bool
=
False
)
->
None
:
'''
'''
Fail-safe file write operation. Creates directories if needed.
Fail-safe file write operation. Creates directories if needed.
...
...
tests/test_fail_safe_file_operations.py
View file @
a6f2d22f
...
@@ -8,7 +8,7 @@ from common_helper_files import (
...
@@ -8,7 +8,7 @@ from common_helper_files import (
create_symlink
,
delete_file
,
get_safe_name
,
get_binary_from_file
,
get_dir_of_file
,
get_directory_for_filename
,
create_symlink
,
delete_file
,
get_safe_name
,
get_binary_from_file
,
get_dir_of_file
,
get_directory_for_filename
,
get_dirs_in_dir
,
get_files_in_dir
,
get_string_list_from_file
,
safe_rglob
,
write_binary_to_file
get_dirs_in_dir
,
get_files_in_dir
,
get_string_list_from_file
,
safe_rglob
,
write_binary_to_file
)
)
from
common_helper_files.fail_safe_file_operations
import
_get_counted_file_path
,
_rm_cr
from
common_helper_files.fail_safe_file_operations
import
_get_counted_file_path
TEST_DATA_DIR
=
Path
(
__file__
)
.
absolute
()
.
parent
/
'data'
TEST_DATA_DIR
=
Path
(
__file__
)
.
absolute
()
.
parent
/
'data'
EMPTY_FOLDER
=
TEST_DATA_DIR
/
'empty_folder'
EMPTY_FOLDER
=
TEST_DATA_DIR
/
'empty_folder'
...
@@ -188,11 +188,3 @@ def test_safe_rglob_empty_dir():
...
@@ -188,11 +188,3 @@ def test_safe_rglob_empty_dir():
assert
EMPTY_FOLDER
.
exists
()
assert
EMPTY_FOLDER
.
exists
()
result
=
safe_rglob
(
EMPTY_FOLDER
)
result
=
safe_rglob
(
EMPTY_FOLDER
)
assert
len
(
list
(
result
))
==
0
assert
len
(
list
(
result
))
==
0
@pytest.mark.parametrize
(
'input_data, expected'
,
[
(
'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