Repository: Naruno/Naruno (language: python)

Issue:
tests: Adding unit test for perpetualTimer class



Discussion / hints:

Fix patch:
diff --git a/.gitignore b/.gitignore
index f5421468..ac3bf831 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,9 @@ bin/
 #export
 *.csv
 
+#test
+*.txt
+
 decentra_network/db/blocs/*
 decentra_network/db/pending_transactions/*
 decentra_network/db/test_SaveBlockstoBlockchainDB_GetBlockstoBlockchainDB/*


Test patch:
diff --git a/tests/unit_tests/test_lib.py b/tests/unit_tests/test_lib.py
index a9e1366b..2a1f10f3 100644
--- a/tests/unit_tests/test_lib.py
+++ b/tests/unit_tests/test_lib.py
@@ -23,6 +23,7 @@
     TEMP_BLOCK_PATH, TEMP_BLOCKSHASH_PART_PATH, TEMP_BLOCKSHASH_PATH,
     UNL_NODES_PATH)
 from decentra_network.lib.clean_up import CleanUp_tests
+from decentra_network.lib.config_system import get_config
 from decentra_network.lib.export import export_the_transactions
 from decentra_network.lib.mix.mixlib import (banner_maker, ended_text_centered,
                                              menu_maker, menu_seperator,
@@ -30,6 +31,7 @@
                                              printcentertext, question_maker,
                                              quit_menu_maker,
                                              starting_text_centered)
+from decentra_network.lib.perpetualtimer import perpetualTimer
 from decentra_network.lib.safety import safety_check
 from decentra_network.lib.settings_system import (d_mode_settings,
                                                   save_settings,
@@ -39,6 +41,18 @@
 from decentra_network.node.unl import Unl
 
 
+def perpetual_time_test():
+    os.chdir(get_config()["main_folder"])
+    with open("test_perpetual_time_test.txt", "w") as f:
+        f.write("Hello World")
+
+
+def perpetual_time_test_t_0():
+    os.chdir(get_config()["main_folder"])
+    with open("test_perpetual_time_test_t_0.txt", "w") as f:
+        f.write("Hello World")
+
+
 class pywall_none:
 
     def __init__(self):
@@ -586,5 +600,23 @@ def test_d_mode_settings(self):
 
         t_mode_settings(temp_settings["debug_mode"])
 
+    def test_perpetualTimer_0(self):
+        the_timer = perpetualTimer(
+            0,
+            perpetual_time_test_t_0,
+        )
+        time.sleep(2.5)
+        self.assertFalse(os.path.exists("test_perpetual_time_test_t_0.txt"))
+        the_timer.cancel()
+
+    def test_perpetualTimer(self):
+        the_timer = perpetualTimer(
+            1,
+            perpetual_time_test,
+        )
+        time.sleep(2.5)
+        self.assertTrue(os.path.exists("test_perpetual_time_test.txt"))
+        the_timer.cancel()
+
 
 unittest.main(exit=False)