From 9bd3bd0760cf9690ea5428bb0c2a4ef304fe2d84 Mon Sep 17 00:00:00 2001
From: moeslinged94 <Feststelltaste1>
Date: Tue, 15 Jun 2021 16:45:02 +0200
Subject: [PATCH] Do NOT use this version TST: Additional Information in
 progress_view.py for commands and verification, re-arranged the test-command
 file (steps now easier visible), version/description bug in log file fix

---
 Tst/progress_view/progress_view.py            |  5 +-
 Tst/test_specs/test.json                      | 58 +++++++++++++++++++
 Tst/testing_library/testlib/report.py         |  8 +--
 Tst/tst/generator.py                          |  8 +--
 .../generator_templates/co_post_condition.py  | 36 ++++++++++++
 .../generator_templates/co_pre_condition.py   | 23 ++++++++
 Tst/tst/generator_templates/co_step.py        | 21 ++-----
 7 files changed, 133 insertions(+), 26 deletions(-)
 create mode 100644 Tst/test_specs/test.json

diff --git a/Tst/progress_view/progress_view.py b/Tst/progress_view/progress_view.py
index 95257a1..5331bed 100644
--- a/Tst/progress_view/progress_view.py
+++ b/Tst/progress_view/progress_view.py
@@ -230,7 +230,7 @@ class TestProgressView(Gtk.ApplicationWindow):
         self.view.append_column(column_type)
 
         # column 4
-        renderer_cmd_version = Gtk.CellRendererText()
+        renderer_cmd_version = Gtk.CellRendererText(xalign=0.5)
         column_cmd_version = Gtk.TreeViewColumn('Version', renderer_cmd_version, text=3, background=7)
         column_cmd_version.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
         column_cmd_version.set_resizable(True)
@@ -603,6 +603,7 @@ class TestProgressView(Gtk.ApplicationWindow):
         return row
 
     def add_detailed_row(self, inner_row_iter, tree_store):
+
         detailed_info=[]
         for count, item in enumerate(tree_store[inner_row_iter]):
             if count in [0,7,9]:  # Stepnumber, colour, colour
@@ -624,7 +625,6 @@ class TestProgressView(Gtk.ApplicationWindow):
                 detailed_info.append('')
 
         new_row_iter = tree_store.append(inner_row_iter, detailed_info)
-        new_row = tree_store[new_row_iter]
 
 
     def load_json(self, filepath):
@@ -844,6 +844,7 @@ class TestProgressView(Gtk.ApplicationWindow):
                         else:
                             self.build_row_list(row=new_row,
                                                 result=False)
+                    self.add_detailed_row(new_row_iter, tree_store)
         self.restore_expanded_states(tree_store)
 
 
diff --git a/Tst/test_specs/test.json b/Tst/test_specs/test.json
new file mode 100644
index 0000000..91c21b9
--- /dev/null
+++ b/Tst/test_specs/test.json
@@ -0,0 +1,58 @@
+{
+ "_name": "test",
+ "_description": "Testing the TST",
+ "_version": "2",
+ "_primary_counter_locked": false,
+ "_precon": "",
+ "_postcon": "",
+ "sequences": [
+  {
+   "_sequence": 0,
+   "_name": "",
+   "_description": "",
+   "_version": "",
+   "_primary_counter_locked": false,
+   "steps": [
+    {
+     "_primary_counter": 1,
+     "_secondary_counter": 0,
+     "_step_number": "1.0",
+     "_description": "Increase the HK Frequncy",
+     "_comment": "",
+     "_command_code": "cfl.Tcsend_DB('SASW ModHkPeriodCmd', 1, 8, pool_name='new_tmtc_pool')\n",
+     "_verification_code": "print('Verification')",
+     "_is_active": true,
+     "_verified_item": [],
+     "_start_sequence": null,
+     "_stop_sequence": null
+    },
+    {
+     "_primary_counter": 2,
+     "_secondary_counter": 0,
+     "_step_number": "2.0",
+     "_description": "This is supposed to be a very long text just to seeeeee how the Progress Viewer View will handle something like this, definetly do not read any further, these are just some random words, the person reading is just wasting time. Now we reached the end. Tahnks for listening",
+     "_comment": "",
+     "_command_code": "print('A Lot of code')\nprint('Just some lines')\nprint('get some lines in here')\nprint('There we go')\nprint(' This line is not needed')\nprint('senseless line')\nprint(' This is a verrrrrrrrry long line that doesnt make any sense execept to see how the progress viewer will show this, thanks for reading')\n",
+     "_verification_code": "print('Verification')\nprint('A Lot of code')\nprint('Just some lines')\nprint('get some lines in here')\nprint('There we go')\nprint(' This line is not needed')\nprint('senseless line')",
+     "_is_active": true,
+     "_verified_item": [],
+     "_start_sequence": null,
+     "_stop_sequence": null
+    },
+    {
+     "_primary_counter": 3,
+     "_secondary_counter": 0,
+     "_step_number": "3.0",
+     "_description": "Duration Test, Is Progress Viewer automatically updating?",
+     "_comment": "",
+     "_command_code": "import time\ntime.sleep(30)",
+     "_verification_code": "print('Test is working, Progress Viewer is updating')\n",
+     "_is_active": true,
+     "_verified_item": [],
+     "_start_sequence": null,
+     "_stop_sequence": null
+    }
+   ]
+  }
+ ]
+}
\ No newline at end of file
diff --git a/Tst/testing_library/testlib/report.py b/Tst/testing_library/testlib/report.py
index ef1dd48..b08ddb0 100644
--- a/Tst/testing_library/testlib/report.py
+++ b/Tst/testing_library/testlib/report.py
@@ -174,11 +174,11 @@ def write_log_step_footer(step_param, step_result):
 
 def write_log_test_header(test, pool_name):
     logger.info('-------------------------------------------------------------------------------')
-    logger.info('Running test {} version {}\n\t\t\t\t\tpoolname = {}\n\t\t\t\t\tCUC-timestamp of test '
+    logger.info('Running test {}\n\t\t\t\t\tversion {}\n\t\t\t\t\tpoolname = {}\n\t\t\t\t\tCUC-timestamp of test '
              'start = {}\n\t\t\t\t\tlocal time = {}'
              .format(test.id, test.version, pool_name, cfl.get_last_pckt_time(pool_name=pool_name, string=False),
                      datetime.datetime.now().isoformat()))
-    logger.info('Description:\n\t\t\t\t\t {}'.format(test.description))
+    logger.info('#Description: {} \n'.format(test.description))
     if test.comment:
         logger.info('Comment: {}'.format(test.comment))
 
@@ -206,9 +206,9 @@ def write_log_test_footer(test):
                 logger.info('{} step {} OK'.format(test.id, item.step))
     logger.info('~~~~~~~~~~~~~~~~~~~~~~~~~')
     if test.test_passed is not False and successful_steps == test.number_of_steps:
-        logger.info('Test {} OK {}/{} steps successful'.format(test.id, successful_steps, test.number_of_steps))
+        logger.info('Test {} OK {}/{} steps ran sucessfully'.format(test.id, successful_steps, test.number_of_steps))
     else:
-        logger.info('Test {} FAILED! {}/{} steps successful'.format(test.id, successful_steps, test.number_of_steps))
+        logger.info('Test {} FAILED! {}/{} steps ran sucessfully'.format(test.id, successful_steps, test.number_of_steps))
     logger.info('-------------------------------------------------------------------------------\n\n\n')
     return successful_steps
 
diff --git a/Tst/tst/generator.py b/Tst/tst/generator.py
index 0511beb..ef39a6a 100644
--- a/Tst/tst/generator.py
+++ b/Tst/tst/generator.py
@@ -137,8 +137,8 @@ def make_command_script(model, model_spec):
         cls = class_str.substitute(testSpecClassName=create_class_name(model_spec.name),
                                    testSpecFileName=create_file_name(model_spec.name),
                                    testSpecName=model_spec.name,
-                                   testSpecDescription=model.description,
-                                   testSpecVersion=model.version)
+                                   testSpecDescription=model_spec.description,
+                                   testSpecVersion=model_spec.version)
         # add the header string
         content += '\n\n' + cls
 
@@ -300,8 +300,8 @@ def make_verification_script(model, model_spec):
         cls = class_str.substitute(testSpecClassName=create_class_name(model_spec.name),
                                    testSpecFileName=create_file_name(model_spec.name),
                                    testSpecName=model_spec.name,
-                                   testSpecDescription=model.description,
-                                   testSpecVersion=model.version)
+                                   testSpecDescription=model_spec.description,
+                                   testSpecVersion=model_spec.version)
         # add the header string
         content += '\n\n' + cls
 
diff --git a/Tst/tst/generator_templates/co_post_condition.py b/Tst/tst/generator_templates/co_post_condition.py
index 907ad73..eaf7c8a 100644
--- a/Tst/tst/generator_templates/co_post_condition.py
+++ b/Tst/tst/generator_templates/co_post_condition.py
@@ -1,3 +1,39 @@
+    # VERIFY EVERY STEP ------------------------------------------------------------------------------------------------
+    def step_verification(self, pool_name, step_start_cuc, param, summary, tc_id, ver_file, ver_class, ver_func):
+        """
+        This functions does the verification for every step
+        :param pool_name: str
+            Name of the datapool for TM/TCs in the database
+        :param step_start_cuc: time
+            Time when the step started
+        :param param: list
+            Includes the parameters of the step
+        :param summary: report.StepSummary class object
+            Containes a summary of the test
+        :param tc_id:
+        :param ver_instance: class Instance definition
+            If called the verification class is initialized
+        :param ver_instance: func
+            If called the verification function is called
+        :return: summary :report.StepSummary class object
+            Containes a summary of the test
+        """
+        if self.do_verification:
+            # execute the verification function for this step from the verification script
+            logger.info('Doing verification for step {}'.format(param['step_no']))
+            try:
+                ver_instance_call = getattr(ver_file, ver_class)
+                instance = ver_instance_call()
+                ver_func_call = getattr(instance, ver_func)
+                success = ver_func_call(pool_name, start_cuc=step_start_cuc, tc_id=tc_id)
+                summary.result = success
+            except:
+                logger.exception('Exception in the Verification for Step {}'.format(param['step_no']))
+            finally:
+                testing_logger.cmd_log_handler(__name__)
+
+        return summary
+
     # POST-CONDITION ---------------------------------------------------------------------------------------------------
     def post_condition(self, pool_name):
         """
diff --git a/Tst/tst/generator_templates/co_pre_condition.py b/Tst/tst/generator_templates/co_pre_condition.py
index 5ac3524..390bca5 100644
--- a/Tst/tst/generator_templates/co_pre_condition.py
+++ b/Tst/tst/generator_templates/co_pre_condition.py
@@ -16,3 +16,26 @@
         logger.info('establishing preconditions finished')
         report.write_precondition_outcome(success)
         return success
+
+    # INITIALIZE every step --------------------------------------------------------------------------------------------
+    def begin_steps(self, pool_name, param):
+        """
+        This functions initializes every step, the step itself is done in the step functions
+        :param pool_name: str
+            Name of the datapool for TM/TCs in the database
+        :param param: list
+            Includes the parameters of the step
+        :return: step_start_cuc: time
+            Time of the last incomming package before the step is started/ used as time of step start
+        :return: summary: report.StepSummary class object
+            Containes a summary of the test
+        :return: tc_id:
+        """
+        testing_logger.cmd_log_handler(__name__)
+        step_start_cuc = cfl.get_last_pckt_time(pool_name=pool_name, string=False)
+        report.command_step_begin(step_param=param, script_version=self.version(), pool_name=pool_name,
+                                  step_start_cuc=step_start_cuc)
+
+        summary = report.StepSummary(step_number=param['step_no'])
+        tc_id = None
+        return step_start_cuc, summary, tc_id
diff --git a/Tst/tst/generator_templates/co_step.py b/Tst/tst/generator_templates/co_step.py
index 14cd6c8..81e6629 100644
--- a/Tst/tst/generator_templates/co_step.py
+++ b/Tst/tst/generator_templates/co_step.py
@@ -1,16 +1,12 @@
     # STEP ${testStepNumber} --------------------------------------------------------------------------------------------------------
     def step_${testStepNumber}(self, pool_name):
-        testing_logger.cmd_log_handler(__name__)
         param = {
             'step_no': '$testStepNumber',
             'msg': '$testStepDescription',
             'comment': '$testStepComment'
         }
-        step_start_cuc = cfl.get_last_pckt_time(pool_name=pool_name, string=False)
-        report.command_step_begin(step_param=param, script_version=self.version(), pool_name=pool_name, step_start_cuc=step_start_cuc)
+        step_start_cuc, summary, tc_id = self.begin_steps(pool_name=pool_name, param=param)
 
-        summary = report.StepSummary(step_number=param['step_no'])
-        tc_id = None
         try:
             ########---The defined step starts here---########
 
@@ -26,15 +22,8 @@
             step_end_cuc = cfl.get_last_pckt_time(pool_name=pool_name, string=False)
             report.command_step_end(step_param=param, step_end_cuc=step_end_cuc)
 
-        if self.do_verification:
-            # execute the verification function for this step from the verification script
-            logger.info('Doing verification for step {}'.format(param['step_no']))
-            try:
-                instance = ${testSpecFileName}_verification.${testSpecClassName}Verification()
-                success = instance.step_${testStepNumber}(pool_name, start_cuc=step_start_cuc, tc_id=tc_id)
-                summary.result = success
-            except:
-                logger.exception('Exception in the Verification for Step {}'.format(param['step_no']))
-            finally:
-                testing_logger.cmd_log_handler(__name__)
+        summary =self.step_verification(pool_name=pool_name, step_start_cuc=step_start_cuc, param=param, tc_id=tc_id,
+                                        summary=summary, ver_file=${testSpecFileName}_verification,
+                                        ver_class="${testSpecClassName}Verification", ver_func="step_${testStepNumber}")
+
         return summary
-- 
GitLab