Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
E
ES Subset Generator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ChEMBL
C
ChEMBL
Main Web Interface
ES Subset Generator
Commits
99a4ac1a
Commit
99a4ac1a
authored
Aug 13, 2020
by
David Mendez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more tests for chunk generation function
parent
19957e55
Pipeline
#92116
passed with stages
in 2 minutes and 37 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
2 deletions
+47
-2
app/es_subset_generator/test/test_utils_functions.py
app/es_subset_generator/test/test_utils_functions.py
+24
-2
app/es_subset_generator/utils.py
app/es_subset_generator/utils.py
+23
-0
No files found.
app/es_subset_generator/test/test_utils_functions.py
View file @
99a4ac1a
...
...
@@ -17,12 +17,11 @@ class TestUtilFunctions(unittest.TestCase):
"""
list_size
=
100
original_list
=
list
(
range
(
0
,
list_size
))
original_list_size
=
len
(
original_list
)
for
chunk_size
in
range
(
1
,
list_size
+
10
):
chunks_obtained
=
list
(
utils
.
get_list_chunks
(
chunk_size
,
original_list
))
total_size_obtained
=
sum
([
len
(
chunk
)
for
chunk
in
chunks_obtained
])
self
.
assertTrue
(
total_size_obtained
==
original_
list_size
,
self
.
assertTrue
(
total_size_obtained
==
list_size
,
msg
=
'The total size of the chunks do not match the size of the original list!'
)
items_found
=
set
()
...
...
@@ -33,3 +32,26 @@ class TestUtilFunctions(unittest.TestCase):
for
item
in
original_list
:
self
.
assertIn
(
item
,
items_found
,
msg
=
f'The item
{
item
}
is missing in the chunks!'
)
def
test_list_chunk_fails_with_nonsense_numbers
(
self
):
"""
Tests that the chunks function fails when nonsense numbers are given (negative and zero)
"""
list_size
=
100
original_list
=
list
(
range
(
0
,
list_size
))
with
self
.
assertRaises
(
utils
.
ChunkSizeNonSenseError
,
msg
=
'It should raise an error with a nonsense chunk size!'
):
utils
.
get_list_chunks
(
0
,
original_list
)
utils
.
get_list_chunks
(
-
1
,
original_list
)
def
test_list_chunk_works_with_empty_list
(
self
):
"""
test chunks function works with an empty list. It should create an empty chunk list
"""
list_size
=
0
original_list
=
list
(
range
(
0
,
list_size
))
chunks_obtained
=
list
(
utils
.
get_list_chunks
(
10
,
original_list
))
self
.
assertEqual
(
chunks_obtained
,
[],
msg
=
f'No chunks must have been produced!'
)
app/es_subset_generator/utils.py
View file @
99a4ac1a
...
...
@@ -3,12 +3,35 @@ Utils functions for handling the subset creation
"""
class
ChunkSizeNonSenseError
(
Exception
):
"""
Error raised when the chunk size does not make sense
"""
def
get_list_chunks
(
chunk_size
,
original_list
):
"""
:param chunk_size: size of chunk to obtain
:param original_list: list to split
:return: a generator object with the chunks of the original list with the given size
"""
if
chunk_size
<=
0
:
raise
ChunkSizeNonSenseError
(
f'A chunk size of
{
chunk_size
}
does not make sense!'
)
if
len
(
original_list
)
==
0
:
return
[]
return
prepare_list_chunks_generator
(
chunk_size
,
original_list
)
def
prepare_list_chunks_generator
(
chunk_size
,
original_list
):
"""
Prepares the generator to get the list chunks
:param chunk_size: size of chunk to obta
:param original_list: list to split
:return: a generator object with the chunks of the original list with the given size
"""
start_index
=
0
end_index
=
chunk_size
original_list_size
=
len
(
original_list
)
...
...
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