exception handling unit tests
@@ -3,6 +3,8 @@ import unittest
import tempfile
import pandas as pd
from kgtk.cli_entry import cli_entry
+from kgtk.cli.filter import run
+from kgtk.exceptions import KGTKException
class TestKGTKFilter(unittest.TestCase):
@@ -86,3 +88,24 @@ class TestKGTKFilter(unittest.TestCase):
df_r = pd.read_csv(f'{self.temp_dir}/reject.tsv', sep='\t')
self.assertEqual(len(df_r), len(df))
+
+ def test_kgtk_filter_long_filter_pattern(self):
+ with self.assertRaises(KGTKException):
+ run(input_file=self.file_path, output_file=f'{self.temp_dir}/one_row.tsv',
+ reject_file=None, pattern="Q65695069;P577;^2019-07-19T00:00:00Z/11;bla",
+ subj_col=None, pred_col=None, obj_col=None, or_pattern=False,
+ invert=False, show_version=False)
+
+ def test_kgtk_filter_no_filter_pattern(self):
+ with self.assertRaises(KGTKException):
+ run(input_file=self.file_path, output_file=f'{self.temp_dir}/one_row.tsv',
+ reject_file=None, pattern=";;",
+ subj_col=None, pred_col=None, obj_col=None, or_pattern=False,
+ invert=False, show_version=False)
+
+ def test_kgtk_filter_missing_columns(self):
+ with self.assertRaises(KGTKException):
+ run(input_file=self.file_path2, output_file=f'{self.temp_dir}/one_row.tsv',
+ reject_file=None, pattern=";;",
+ subj_col='1', pred_col='2', obj_col='3', or_pattern=False,
+ invert=False, show_version=False)
