Skip to content
Snippets Groups Projects
Commit 4fd30a97 authored by Lan Dam's avatar Lan Dam
Browse files

Merge branch 'print_traceback_error' into 'master'

Print traceback error's info

See merge request !44
parents 1f712d31 96b176e5
No related branches found
No related tags found
1 merge request!44Print traceback error's info
Pipeline #1929 passed with stage
in 5 minutes and 23 seconds
"""
Function that ignite from MainWindow, Dialogs to read data files for data,
Function that ignite from main_window, Dialogs to read data files for data,
channels, datatype
"""
import os
import json
import re
import traceback
from pathlib import Path
from obspy.core import read as read_ms
......@@ -39,9 +40,11 @@ def loadData(dataType, tracking_box, listOfDir, reqWFChans=[], reqSOHChans=[],
dataType, tracking_box, d,
reqWFChans=reqWFChans, reqSOHChans=reqSOHChans,
readStart=readStart, readEnd=readEnd)
except Exception as e:
msg = f"Dir {d} can't be read due to error: {str(e)}"
except Exception:
fmt = traceback.format_exc()
msg = f"Dir {d} can't be read due to error: {str(fmt)}"
displayTrackingInfo(tracking_box, msg, "Warning")
# if dataObject.hasData():
# continue
# If no data can be read from the first dir, throw exception
......
......@@ -3,6 +3,8 @@ from pathlib import Path
from unittest import TestCase
from unittest.mock import patch
from contextlib import redirect_stdout
import io
from sohstationviewer.controller.processing import (
loadData,
......@@ -121,6 +123,30 @@ class TestLoadDataAndReadChannels(TestCase):
self.assertIsNone(
loadData(self.mseed_dtype, self.widget_stub, [rt130_dir]))
def test_load_data_data_traceback_error(self):
"""
Test basic functionality of loadData - when there is an error
on loading data, the traceback info will be printed out
"""
f = io.StringIO()
with redirect_stdout(f):
self.assertIsNone(loadData('RT130', None, [q330_dir]))
output = f.getvalue()
self.assertIn(
f"Warning: Dir {q330_dir} "
f"can't be read due to error: Traceback",
output
)
with redirect_stdout(f):
self.assertIsNone(
loadData(self.mseed_dtype, None, [rt130_dir]))
output = f.getvalue()
self.assertIn(
f"Warning: Dir {rt130_dir} "
f"can't be read due to error: Traceback",
output
)
def test_read_channels_mseed_dir(self):
"""
Test basic functionality of loadData - the given directory contains
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment