diff options
| author | John Estabrook <jestabro@vyos.io> | 2026-06-24 14:17:19 -0500 |
|---|---|---|
| committer | John Estabrook <jestabro@vyos.io> | 2026-06-24 15:30:08 -0500 |
| commit | 5b52dbea7e780809ddc9b0d086c49849336f3259 (patch) | |
| tree | bebaabfca1cbfc48b0615b7244bee988499c2693 | |
| parent | 054fda56ef8da2bb2b0c1f9749914189d13e3d07 (diff) | |
| download | vyos-1x-5b52dbea7e780809ddc9b0d086c49849336f3259.tar.gz vyos-1x-5b52dbea7e780809ddc9b0d086c49849336f3259.zip | |
T9015: add nosetest
| -rw-r--r-- | src/tests/test_config_tree.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/tests/test_config_tree.py b/src/tests/test_config_tree.py index d6339c570..ba25537ed 100644 --- a/src/tests/test_config_tree.py +++ b/src/tests/test_config_tree.py @@ -14,7 +14,10 @@ # # +import os import json +import time +import threading import unittest from unittest import TestCase @@ -29,6 +32,20 @@ class TestInitialSetup(TestCase): config_str = f.read() self.ct = ConfigTree(config_str) + self.thread_exception = None + self.orig_excepthook = threading.excepthook + + def custom_hook(args): + self.thread_exception = args.exc_value + + threading.excepthook = custom_hook + + def tearDown(self): + threading.excepthook = self.orig_excepthook + + if self.thread_exception: + raise self.thread_exception + def test_subtree_from_partial(self): reftree = ReferenceTree(cache_file='data/reftree.cache') @@ -43,6 +60,30 @@ class TestInitialSetup(TestCase): self.assertEqual(self.ct, reassemble) + def test_cache_io(self): + config_cache = '/tmp/config.cache' + + self.ct.write_cache(config_cache) + ct_cached = ConfigTree(internal=config_cache) + os.unlink(config_cache) + + self.assertEqual(self.ct, ct_cached) + + def test_cache_io_thread(self): + config_cache = '/tmp/config.cache' + + def task(): + time.sleep(0.1) + self.ct.write_cache(config_cache) + ct_cached = ConfigTree(internal=config_cache) + os.unlink(config_cache) + + self.assertEqual(self.ct, ct_cached) + + t = threading.Thread(target=task) + t.start() + t.join() + if __name__ == '__main__': unittest.main() |
