Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 50 improve logging #333

Merged
merged 8 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions METdbLoad/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import pymysql
from pathlib import Path
from unittest.mock import MagicMock

from METdataio.METdbLoad.ush.run_sql import RunSql
from METdataio.METdbLoad.test.utils import (
Expand Down Expand Up @@ -124,3 +125,8 @@ def load_and_read_xml(
return XML_LOADFILE

return load_and_read_xml


@pytest.fixture
def mock_logger():
return MagicMock()
2 changes: 1 addition & 1 deletion METdbLoad/test/test_load_specification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</connection>

<folder_tmpl>/METdataio/METreformat/test/data/point_stat</folder_tmpl>
<verbose>false</verbose>
<verbose>true</verbose>
<insert_size>1</insert_size>
<stat_header_db_check>true</stat_header_db_check>
<mode_header_db_check>false</mode_header_db_check>
Expand Down
3 changes: 3 additions & 0 deletions METdbLoad/test/test_met_db_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def test_met_db_table_counts(
"xmlfile": str(get_xml_test_file(tmp_path, met_data_dir, met_tool)),
"index": "true",
"tmpdir": [str(tmp_path)],
"loglevel": None,
}
)

Expand Down Expand Up @@ -160,6 +161,7 @@ def test_met_db_indexes(
),
"index": "false",
"tmpdir": [str(tmp_path)],
"loglevel": None
}
)

Expand Down Expand Up @@ -240,6 +242,7 @@ def test_local_in_file(emptyDB, testRunSql, tmp_path, met_data_dir, met_tool, ex
"xmlfile": str(get_xml_test_file(tmp_path, met_data_dir, met_tool, local_infile=local_infile)),
"index": "false",
"tmpdir": [str(tmp_path)],
"loglevel": None,
}
)

Expand Down
15 changes: 8 additions & 7 deletions METdbLoad/test/test_run_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ def populate_some_data(
),
"index": "true",
"tmpdir": [str(tmp_path)],
"loglevel": "DEBUG"
}
)
load_main(test_args)


def test_get_file_name(tmp_path, emptyDB, testRunSql):
file_name = testRunSql.get_file_name(1, testRunSql.cur)
def test_get_file_name(tmp_path, emptyDB, testRunSql, mock_logger):
file_name = testRunSql.get_file_name(1, testRunSql.cur, mock_logger)
assert file_name == None

populate_some_data(tmp_path)

file_name = testRunSql.get_file_name(1, testRunSql.cur)
file_name = testRunSql.get_file_name(1, testRunSql.cur, mock_logger)
assert file_name == "grid_stat_GTG_latlon_060000L_20130827_180000V.stat"

# check for a nonexistant id
file_name = testRunSql.get_file_name(9999999, testRunSql.cur)
file_name = testRunSql.get_file_name(9999999, testRunSql.cur, mock_logger)
assert file_name == None


Expand All @@ -47,10 +48,10 @@ def test_get_file_name(tmp_path, emptyDB, testRunSql):
[False, CN.CREATE_INDEXES_QUERIES],
),
)
def test_apply_indexes(testRunSql, drop, cmds):
def test_apply_indexes(testRunSql, drop, cmds, mock_logger):

mock_cursor = mock.MagicMock()
testRunSql.apply_indexes(drop, mock_cursor)
testRunSql.apply_indexes(drop, mock_cursor, mock_logger)

# Check the correct commands were executed
assert len(mock_cursor.execute.call_args_list) == len(cmds)
Expand All @@ -59,4 +60,4 @@ def test_apply_indexes(testRunSql, drop, cmds):

# check no exception is raised on pymysql error
mock_cursor.execute.side_effect = OperationalError
testRunSql.apply_indexes(drop, mock_cursor)
testRunSql.apply_indexes(drop, mock_cursor, mock_logger)
1 change: 1 addition & 0 deletions METdbLoad/ush/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DEFAULT_LOGLEVEL = "INFO"
Loading
Loading