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
c561df1c
Commit
c561df1c
authored
Oct 17, 2017
by
Peter Weidenbach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test coverage increased
parent
4e061dde
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
8 deletions
+38
-8
.gitignore
.gitignore
+1
-0
pytest.ini
pytest.ini
+1
-1
link_test
tests/data/link_test
+2
-0
test_fail_safe_file_operations.py
tests/test_fail_safe_file_operations.py
+6
-1
test_file_functions.py
tests/test_file_functions.py
+22
-6
test_git_functions.py
tests/test_git_functions.py
+6
-0
No files found.
.gitignore
View file @
c561df1c
# general things to ignore
# general things to ignore
.project
.project
.pydevproject
.pydevproject
.coverage
build/
build/
dist/
dist/
*.egg-info/
*.egg-info/
...
...
pytest.ini
View file @
c561df1c
[pytest]
[pytest]
addopts
=
--pep8 -v
addopts
=
--pep8 -
-cov=./ -
v
pep8ignore
=
pep8ignore
=
*.py E501
*.py E501
tests/data/link_test
0 → 120000
View file @
c561df1c
read_test
\ No newline at end of file
tests/test_fail_safe_file_operations.py
View file @
c561df1c
...
@@ -30,6 +30,10 @@ class Test_FailSafeFileOperations(unittest.TestCase):
...
@@ -30,6 +30,10 @@ class Test_FailSafeFileOperations(unittest.TestCase):
none_existing_file_path
=
os
.
path
.
join
(
self
.
get_directory_of_current_file
(),
"data"
,
"none_existing_file"
)
none_existing_file_path
=
os
.
path
.
join
(
self
.
get_directory_of_current_file
(),
"data"
,
"none_existing_file"
)
file_binary
=
get_binary_from_file
(
none_existing_file_path
)
file_binary
=
get_binary_from_file
(
none_existing_file_path
)
self
.
assertEqual
(
file_binary
,
b
''
,
"content not correct"
)
self
.
assertEqual
(
file_binary
,
b
''
,
"content not correct"
)
# Test link
link_path
=
os
.
path
.
join
(
self
.
get_directory_of_current_file
(),
"data"
,
"link_test"
)
file_binary
=
get_binary_from_file
(
link_path
)
assert
file_binary
==
'symbolic link -> read_test'
def
test_fail_safe_read_file_string_list
(
self
):
def
test_fail_safe_read_file_string_list
(
self
):
test_file_path
=
os
.
path
.
join
(
self
.
get_directory_of_current_file
(),
"data"
,
"multiline_test.txt"
)
test_file_path
=
os
.
path
.
join
(
self
.
get_directory_of_current_file
(),
"data"
,
"multiline_test.txt"
)
...
@@ -94,7 +98,8 @@ class Test_FailSafeFileOperations(unittest.TestCase):
...
@@ -94,7 +98,8 @@ class Test_FailSafeFileOperations(unittest.TestCase):
result
=
get_files_in_dir
(
test_dir_path
)
result
=
get_files_in_dir
(
test_dir_path
)
self
.
assertIn
(
os
.
path
.
join
(
test_dir_path
,
"read_test"
),
result
,
"file in root folder not found"
)
self
.
assertIn
(
os
.
path
.
join
(
test_dir_path
,
"read_test"
),
result
,
"file in root folder not found"
)
self
.
assertIn
(
os
.
path
.
join
(
test_dir_path
,
"test_folder/generic_test_file"
),
result
,
"file in sub folder not found"
)
self
.
assertIn
(
os
.
path
.
join
(
test_dir_path
,
"test_folder/generic_test_file"
),
result
,
"file in sub folder not found"
)
self
.
assertEqual
(
len
(
result
),
3
,
"number of found files not correct"
)
print
(
result
)
self
.
assertEqual
(
len
(
result
),
4
,
"number of found files not correct"
)
def
test_get_files_in_dir_error
(
self
):
def
test_get_files_in_dir_error
(
self
):
result
=
get_files_in_dir
(
"/none_existing/dir"
)
result
=
get_files_in_dir
(
"/none_existing/dir"
)
...
...
tests/test_file_functions.py
View file @
c561df1c
import
unit
test
import
py
test
from
common_helper_files
import
human_readable_file_size
import
os
class
Test_file_functions
(
unittest
.
TestCase
):
from
common_helper_files
import
human_readable_file_size
,
read_in_chunks
,
get_directory_for_filename
def
test_human_readable_file_size
(
self
):
TEST_DATA_DIR
=
os
.
path
.
join
(
get_directory_for_filename
(
__file__
),
'data'
)
self
.
assertEqual
(
human_readable_file_size
(
1024
),
'1.00 KiB'
)
self
.
assertEqual
(
human_readable_file_size
(
5000
),
'4.88 KiB'
)
@pytest.mark.parametrize
(
'input_data, expected'
,
[
(
1000
,
'1000.00 Byte'
),
(
1024
,
'1.00 KiB'
),
(
1024
*
1024
,
'1.00 MiB'
),
(
1234.1234
,
'1.21 KiB'
),
])
def
test_human_readable_file_size
(
input_data
,
expected
):
assert
human_readable_file_size
(
input_data
)
==
expected
def
test_read_in_chunks
():
fp
=
open
(
TEST_DATA_DIR
+
'/read_test'
,
'rb'
)
test_buffer
=
b
''
for
chunk
in
read_in_chunks
(
fp
):
test_buffer
+=
chunk
assert
test_buffer
==
b
'this is a test'
tests/test_git_functions.py
0 → 100644
View file @
c561df1c
from
common_helper_files
import
get_version_string_from_git
def
test_get_version_string_from_git
():
result
=
get_version_string_from_git
(
'.'
)
assert
type
(
result
)
==
str
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