Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
HOTMapper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
HOTMapper
HOTMapper
Commits
00252030
Commit
00252030
authored
6 years ago
by
jvfpw18
Browse files
Options
Downloads
Patches
Plain Diff
Fix update_from_file when columns are not specified
parent
4a733659
No related branches found
No related tags found
2 merge requests
!13
v1.1.0
,
!5
Add test update from file
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
database/actions.py
+1
-1
1 addition, 1 deletion
database/actions.py
tests/database_test.py
+25
-16
25 additions, 16 deletions
tests/database_test.py
with
26 additions
and
17 deletions
database/actions.py
+
1
−
1
View file @
00252030
...
...
@@ -112,7 +112,7 @@ def update_from_file(file_name, table, year, columns=None,
raise
MissingTableError
(
table
.
name
)
if
columns
is
None
:
columns
=
[]
columns
=
[
c
.
name
for
c
in
table
.
columns
]
with
ENGINE
.
connect
()
as
connection
:
trans
=
connection
.
begin
()
...
...
This diff is collapsed.
Click to expand it.
tests/database_test.py
+
25
−
16
View file @
00252030
...
...
@@ -62,6 +62,18 @@ def compare_columns(table, verify_csv, error_string):
str
(
c
.
type
),
verify_columns_df
[
verify_columns_df
[
'
name
'
]
==
c
.
name
][
'
type
'
])
print
(
c
.
name
,
c
.
type
)
def
compare_data
(
table
,
verify_csv
,
error_string
):
print
(
"
Executing fetchall query:
"
)
with
ENGINE
.
connect
()
as
connection
:
sel
=
select
([
table
]).
order_by
(
table
.
c
.
id
)
result
=
connection
.
execute
(
sel
)
content
=
result
.
fetchall
()
print
(
'
Initializing data verification:
\n
'
)
verify_table
=
pd
.
read_csv
(
verify_csv
,
sep
=
'
|
'
)
verify_content
=
list
(
verify_table
.
itertuples
(
index
=
False
,
name
=
None
))
if
verify_content
!=
content
:
raise
VerificationFailed
(
'
Something went wrong, please rerun in debug mode.
'
+
error_string
)
def
test_creation
():
if
not
ENGINE
.
dialect
.
has_table
(
ENGINE
,
'
test_reference
'
):
database
.
actions
.
execute_sql_script
(
'
test_reference.sql
'
)
...
...
@@ -84,22 +96,10 @@ def test_creation():
def
test_insert
():
print
(
'
Testing insert of data
'
,
csvpath
)
database
.
actions
.
insert
(
csvpath
,
table_test
,
'
2018
'
,
delimiters
=
[
'
,
'
,
'
\\
n
'
,
'"'
],
null
=
''
)
print
(
"
Executing fetchall query:
"
)
with
ENGINE
.
connect
()
as
connection
:
table
=
Table
(
table_test
,
META
,
autoload
=
True
,
autoload_with
=
ENGINE
)
sel
=
select
([
table
]).
order_by
(
table
.
c
.
id
)
result
=
connection
.
execute
(
sel
)
content
=
result
.
fetchall
()
if
content
:
print
(
'
Initializing data verification:
\n
'
)
verify_table
=
pd
.
read_csv
(
'
./tests/database_test_data/verify_data_insert.csv
'
,
sep
=
'
|
'
)
verify_content
=
list
(
verify_table
.
itertuples
(
index
=
False
,
name
=
None
))
if
verify_content
==
content
:
compare_data
(
table
,
'
./tests/database_test_data/verify_data_insert.csv
'
,
'
INSERTION VERIFICATION FAILED
'
)
print
(
'
INSERTION SUCCESS!
\n\n
'
)
else
:
raise
VerificationFailed
(
'
Something went wrong, Verification failed during insert
'
)
else
:
raise
VerificationFailed
(
"
Something went wrong. Please rerun in DEBUG mod. INSERTION FAILED
"
)
def
test_remap_without_changes
():
print
(
'
Testing a remap without changes:
'
)
...
...
@@ -130,6 +130,14 @@ def test_remap_with_all_changes():
mapping_df_original
.
to_csv
(
protocol_path
)
print
(
'
REMAP WITH ALL POSSIBLE CHANGES CHANGES SUCCESS!
\n\n
'
)
def
test_update_from_file
():
print
(
'
\n
Testing an update from file:
'
)
database
.
actions
.
update_from_file
(
csvpath
,
table_test
,
'
2018
'
,
delimiters
=
[
'
,
'
,
'
\\
n
'
,
'"'
])
table
=
Table
(
table_test
,
META
,
autoload
=
True
,
autoload_with
=
ENGINE
)
compare_data
(
table
,
'
./tests/database_test_data/verify_data_insert.csv
'
,
'
UPDATE FROM FILE VERIFICATION FAILED
'
)
print
(
'
UPDATE FROM FILE SUCCESS!
\n\n
'
)
def
test_drop
():
print
(
"
Dropping table
"
,
table_test
)
database
.
actions
.
drop
(
table_test
)
...
...
@@ -153,6 +161,7 @@ def test_all():
@manager.command
()
def
remap_all
():
test_remap_with_all_changes
()
test_update_from_file
()
test_drop
()
...
...
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