def test_METAR_replacer(self):
     # Creates a backup copy to work on
     template_temp_name = self.template_file_name[:-6] + '_temp.ipynb'
     copyfile(self.template_file_path + self.template_file_name,
              self.template_file_path + template_temp_name)
     # Generates content
     content = metar_processing.contents_opener(self.template_file_path,
                                                template_temp_name)
     # Check that # METAR REPLACER is present in the content
     metar_information_present = check_str_in_content("# METAR REPLACER",
                                                      content)
     self.assertEqual(1, metar_information_present)
     # Run the METAR_replacer
     metar_processing.metar_replacer(self.template_file_path,
                                     template_temp_name,
                                     'EGHE', '2019', '01', '23',
                                     '01', '23', '9', '10', 0,
                                     self.base_path)
     # Check information was replaced correctly
     # Re-reads content
     content = metar_processing.contents_opener(self.template_file_path,
                                                template_temp_name)
     # Checks that the METAR data is present
     expected_content = 'time: Wed Jan 23 09'
     metar_in_content = check_str_in_content(expected_content, content)
     # NOTE: also replaces the content of the METAR_INFORMATION cell, hence
     # 2 instances are present in this test. This is also only relevant to
     # the test template.
     self.assertEqual(4, metar_in_content)
     # Removes the generated document
     generated_file_name = self.template_file_path + template_temp_name
     if os.path.exists(generated_file_name):
         os.remove(generated_file_name)
Exemple #2
0
    def test_METAR_returner(self):
        # Generate content
        content = metar_processing.contents_opener(self.template_file_path,
                                                   self.template_file_name)

        # Check that METAR_INFORMATION is present in the content
        metar_information_present = check_str_in_content(
            "METAR_INFORMATION", content)
        self.assertEqual(1, metar_information_present)
        # Gets METAR data
        metar_data = metar_processing.metar_finder('EGHE', '2019', '01', '23',
                                                   '01', '23', '9', '10',
                                                   self.base_path)
        # Runs METAR returner
        content = metar_processing.metar_returner(metar_data,
                                                  content, [1], [2019],
                                                  1,
                                                  replace_key="METAR_"
                                                  "INFORMATION")
        # Assigns expected metar information
        metar_information = "type: routine report, cycle 9 (automatic report)"
        # Checks that the expected metar information is present
        metar_information_present = check_str_in_content(
            metar_information, content)
        self.assertEqual(1, metar_information_present)
 def test_flight_log_graph_contents_replacer(self):
     # Function being tested is expected to replace all fields with
     # single axis graphs.
     # Generates content.
     contents = text_manipulation.contents_opener(self.template_file_path,
                                                  self.template_file_name)
     # Runs the flight_log_content_replacer
     contents = text_manipulation.flight_log_graph_contents_replacer(contents)
     # Checks for values replaced by the function
     check_x_lim = check_str_in_content('x_limits', contents)
     check_y_lim = check_str_in_content('y_limits', contents)
     check_graph_plotter = check_str_in_content('graph_plotter', contents)
     self.assertEqual(26, check_x_lim)
     self.assertEqual(26, check_y_lim)
     self.assertEqual(13, check_graph_plotter)
Exemple #4
0
 def test_flight_log_checklist(self):
     # Generates the content
     content = flight_log_code.contents_opener(self.template_file_path,
                                               self.template_file_name)
     # Creates checklist frames
     frame_list_nominal = flight_log_code.flight_data(
         self.checklist_file_path, "Checklists_nominal.xlsx")
     frame_list_emergency = flight_log_code.flight_data(
         self.checklist_file_path, "Checklists_emergency.xlsx")
     # Filters checklist for the current flight
     filtered_frame_nominal = flight_log_code.checklist_finder(
         frame_list_nominal, self.flight_number[0], self.flight_date[0])
     filtered_frame_emergency = flight_log_code.checklist_finder(
         frame_list_emergency, self.flight_number[0], self.flight_date[0])
     # Runs the flight_log_checklist code
     content = \
         flight_log_code.flight_log_checklist(filtered_frame_nominal,
                                              filtered_frame_emergency,
                                              "CHECKLIST_INFORMATION",
                                              content)[0]
     # Checks that the content has been changed
     expected_content = 'The Initial Pre-Flight was actioned by Adria' + \
                        'n Weishaeupl starting at 2019-01-23 15:31:44 an' + \
                        'd ending at 2019-01-23 15:32:58. The notes reco' + \
                        'rded on this checklist were: <i>THIS IS A TEST.'
     content_present = check_str_in_content(expected_content, content)
     self.assertEqual(1, content_present)
    def test_METAR_quota_returner(self):
        content = metar_processing.contents_opener(self.template_file_path,
                                                   self.template_file_name)

        # Check that METAR_INFORMATION is present in the content
        metar_information_present = check_str_in_content("METAR_INFORMATION",
                                                         content)
        self.assertEqual(1, metar_information_present)
        # Runs METAR_quota_returner
        content = metar_processing.metar_quota_returner(content, 'test20190123',
                                                        ['EGHE'], ['2019'], ['01'],
                                                        ['23'], ['01'], ['23'], ['9'],
                                                        ['10'], self.base_path, 1,
                                                        replace_key="METAR_INFO"
                                                        "RMATION")
        expected_content = 'metar_replacer(os.getcwd(),'
        content_present = check_str_in_content(expected_content, content)
        self.assertEqual(1, content_present)
 def test_line_remover(self):
     # Defines keys to be tested in the line remover
     keys = ['METAR_INFORMATION', 'GRAPH',
             'MULTIAXIS_GRAPH', 'GRAPH_LINE']
     for key in keys:
         # Generates content
         content = text_manipulation.contents_opener(self.template_file_path,
                                                     self.template_file_name)
         # Counts how many times the key is present
         content_count = check_str_in_content(key, content)
         # Checks that the key is present
         self.assertNotEqual(0, content_count)
         # Runs line remover
         content = text_manipulation.line_remover(content, key)
         # Counts Key occurrences
         content_count = check_str_in_content(key, content)
         # Checks that the line has been removed
         self.assertEqual(0, content_count)
    def test_no_METAR_returner(self):
        content = metar_processing.contents_opener(self.template_file_path,
                                                   self.template_file_name)

        # Check that METAR_INFORMATION is present in the content
        metar_information_present = check_str_in_content("METAR_INFORMATION",
                                                         content)
        self.assertEqual(1, metar_information_present)
        # Runs no_METAR_returner code
        content = metar_processing.no_metar_returner(['EGHE'], [20190123], [20190123], ['9'], ['10'],
                                                     content, 1, replace_key="META"
                                                     "R_INFORMATION")
        # Assigns expected content
        expected_content = 'No METARs for EGHE for the date 23/01/2019 to the date 23/01/2019 from a starting time of' \
                           ' 9:00 and an end time of 9:59.'
        # Checks that the expected content is present in the content
        information_present = check_str_in_content(expected_content,
                                                   content)
        self.assertEqual(1, information_present)
 def test_cell_remover(self):
     # Defines keys to be tested in the cell remover
     keys = [
         'METAR_INFORMATION', 'CHECKLIST_INFORMATION', 'GRAPH',
         'MULTIAXIS_GRAPH'
     ]
     for key in keys:
         # Generates content
         content = text_manipulation.contents_opener(
             self.template_file_path, self.template_file_name)
         # Counts the keys in the content
         content_count = check_str_in_content(key, content)
         # Checks that the keys are present
         self.assertNotEqual(0, content_count)
         # Runs cell remover
         content = text_manipulation.cell_remover(content, key)
         # Counts Key occurrences
         content_count = check_str_in_content(key, content)
         # Checks that the cell has been removed
         self.assertEqual(0, content_count)