Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
aae82b60
Commit
aae82b60
authored
10 months ago
by
Florian Spreckelsen
Browse files
Options
Downloads
Patches
Plain Diff
TST: Add test for
https://gitlab.com/linkahead/linkahead-advanced-user-tools/-/issues/63
parent
0fc89beb
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!112
Release 0.12.0
,
!111
F better csv value error
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
unittests/test_table_importer.py
+42
-0
42 additions, 0 deletions
unittests/test_table_importer.py
with
42 additions
and
0 deletions
unittests/test_table_importer.py
+
42
−
0
View file @
aae82b60
...
@@ -379,6 +379,48 @@ class CSVImporterTest(TableImporterTest):
...
@@ -379,6 +379,48 @@ class CSVImporterTest(TableImporterTest):
assert
df
[
"
int_with_gaps
"
].
dtype
==
"
Int64
"
assert
df
[
"
int_with_gaps
"
].
dtype
==
"
Int64
"
assert
df
[
"
float
"
].
dtype
==
float
assert
df
[
"
float
"
].
dtype
==
float
def
test_wrong_datatype_type_errors
(
self
):
"""
Test for
https://gitlab.com/linkahead/linkahead-advanced-user-tools/-/issues/63:
Highlight rows and columns in which type errors occur.
"""
tmpfile
=
NamedTemporaryFile
(
delete
=
False
,
suffix
=
"
.csv
"
)
with
open
(
tmpfile
.
name
,
'
w
'
)
as
tmp
:
# Wrong types in row 2, columns 1 and 2, and row 4, column 2.
tmp
.
write
(
"
int,float
\n
"
"
1,2.3
\n
"
"
4.5,word
\n
"
"
0,1.2
\n
"
"
-12,12+3j
\n
"
)
kwargs
=
{
"
datatypes
"
:
{
"
int
"
:
int
,
"
float
"
:
float
},
"
obligatory_columns
"
:
[
"
int
"
],
"
converters
"
:
{}
}
importer
=
CSVImporter
(
**
kwargs
)
with
pytest
.
raises
(
DataInconsistencyError
)
as
die
:
df
=
importer
.
read_file
(
tmpfile
.
name
)
msg
=
str
(
die
.
value
)
assert
"
Elements with wrong datatypes encountered:
\n
"
in
msg
# Errors in rows 1 and 3, no errors in 2 and 4
assert
"
* row 1:
\n
"
in
msg
assert
"
* row 2:
\n
"
not
in
msg
assert
"
* row 3:
\n
"
in
msg
assert
"
* row 4:
\n
"
not
in
msg
row_1_msgs
,
row_3_msgs
=
msg
.
split
(
"
* row 1:
\n
"
)[
1
].
split
(
"
* row 3:
\n
"
)
# exactly 2 errors in row 1, exactly 1 in row 3
assert
len
(
row_1_msgs
.
strip
().
split
(
'
\n
'
))
==
2
assert
len
(
row_3_msgs
.
strip
().
split
(
'
\n
'
))
==
1
assert
"
\t
* column
\"
int
\"
"
in
row_1_msgs
assert
"
\t
* column
\"
float
\"
"
in
row_1_msgs
assert
"
\t
* column
\"
float
\"
"
in
row_3_msgs
class
TSVImporterTest
(
TableImporterTest
):
class
TSVImporterTest
(
TableImporterTest
):
def
test_full
(
self
):
def
test_full
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment