aboutsummaryrefslogtreecommitdiff
path: root/tests/test_search.py
diff options
context:
space:
mode:
authorChristian Cleberg <hello@cleberg.net>2025-08-02 19:49:41 -0500
committerChristian Cleberg <hello@cleberg.net>2025-08-02 19:49:41 -0500
commit5032dd4aff82f1deceae11269f8973e89945b893 (patch)
treea86dd7e141e0e168504b73b75f7f0634498b3e97 /tests/test_search.py
parent532e20db6ebef5e4257f437b3ab7429fa18637b3 (diff)
downloadcrumb-5032dd4aff82f1deceae11269f8973e89945b893.tar.gz
crumb-5032dd4aff82f1deceae11269f8973e89945b893.tar.bz2
crumb-5032dd4aff82f1deceae11269f8973e89945b893.zip
feat: add testsHEADmain
Diffstat (limited to 'tests/test_search.py')
-rw-r--r--tests/test_search.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_search.py b/tests/test_search.py
new file mode 100644
index 0000000..f2c003c
--- /dev/null
+++ b/tests/test_search.py
@@ -0,0 +1,34 @@
+import unittest
+from unittest.mock import patch
+from search import search_log
+
+class TestSearchLog(unittest.TestCase):
+
+ @patch('search.LOG_PATH', 'test_log_path')
+ def test_search_log_with_match(self, mock_log_path):
+ query = 'crumb'
+ # Create a dummy log file (for testing)
+ with open('test_log_path', 'w') as f:
+ f.write("* Example Entry\n")
+ f.write(":PROPERTIES:\n")
+ f.write(":URL: http://example.com\n")
+ f.write(":TIMESTAMP: 2023-10-27 10:00:00\n")
+
+ search_log(query)
+ # Assert that the function prints the expected output
+ with open('test_log_path', 'r') as f:
+ output = f.read()
+ self.assertIn("* Example Entry\n", output)
+
+ @patch('search.LOG_PATH', 'test_log_path')
+ def test_search_log_no_match(self, mock_log_path):
+ query = 'nonexistent'
+ with open('test_log_path', 'w') as f:
+ f.write("* Example Entry\n")
+ f.write(":PROPERTIES:\n")
+ f.write(":URL: http://example.com\n")
+ f.write(":TIMESTAMP: 2023-10-27 10:00:00\n")
+ search_log(query)
+ with open('test_log_path', 'r') as f:
+ output = f.read()
+ self.assertNotIn("* Example Entry\n", output)