예제 #1
0
 def test_contents_opener(self):
     contents = text_manipulation.contents_opener(self.template_file_path,
                                                  self.template_file_name)
     test_string = (contents[370:430])
     test_string_true = 'o view images, place the images in a folder' +\
         ' called images (a'
     self.assertEqual(test_string_true, test_string)
예제 #2
0
def metar_replacer(file_path, file_name, location, year, month, day, month_end,
                   day_end, start_time_hours, end_time_hours, flight,
                   metar_file_path):
    """This will replace the code with the METAR data if available."""
    # TODO: Known bug: if only one metar_replacer is run in the workbook when multiple are present, the un-run cells
    #  will be removed without any metar information being entered.
    # Finds metar data.
    metar_data = metar_finder(location, year, month, day, month_end, day_end,
                              start_time_hours, end_time_hours,
                              metar_file_path)
    if len(metar_data) == 0:
        return "No METAR data found."
    if metar_data[0] == "Quota limit reached.":
        return "Sorry, Quota limit has been reached, try again later."
    # Opens contents
    contents = contents_opener(file_path, file_name)
    # Splits contents into lines
    lines = contents.split("\n")
    # Creates an index
    index = 0
    # Creates an index showing where the last open curly bracket was.
    bracket_index = 0
    for line in lines:
        if "# METAR REPLACER{}".format(flight) in line:
            break
        if line == "  {":
            # Records position of last bracket.
            bracket_index = index
        index += 1
    lines = cell_remover(contents,
                         "# METAR REPLACER{}".format(flight)).split("\n")
    # Lines for the METAR_returner code to replace.
    metar_information = "\n  {\n " + \
                        "  \"cell_type\": \"markdown\",\n" + \
                        "   \"metadata\": {},\n" + \
                        "   \"source\": [\n" + \
                        "    \"METAR_INFORMATION\"\n" + \
                        "   ]\n" + \
                        "  },"
    # Inserts metar_information into lines at the point where the curly bracket
    # was for the code.
    # Test
    lines.insert(bracket_index, metar_information)
    contents = ""
    # Reassembles contents from lines
    for line in lines:
        contents += line + "\n"
    contents = metar_returner(metar_data,
                              contents, [int(month)], [int(year)],
                              1,
                              replace_key="METAR_INFORMATION")
    file = open(file_path + os.sep + file_name, "w+")
    # Extracts contents.
    file.write(contents)
    # Closes the file.
    file.close()
    return ("METAR data successfully included, please press save then reload" +
            " and the METAR data should appear in place of this cell.")
예제 #3
0
    def test_contents_opener(self):
        """Tests the contents_opener()"""
        # Assigns variables
        file_path = self.base_path
        file_name1 = "test_data_sources.txt"
        file_name2 = "METAR_EGHE_20190123_20190123_9_9.txt"

        # Assigns outputs
        expected_output1 = "Data Sources specified here will be placed in the excel document\nGPS\nAOA\nCTUN\n" \
                           "RCIN\nARSP\nBARO\nATT\nVIBE"
        expected_output2 = "METAR EGHE 230950Z 34017KT 9999 SCT025 08/03 Q1007\nMETAR EGHE 230920Z 34017KT 9999" \
                           " SCT022 08/02 Q1006\nhttps://www.ogimet.com/display_metars2.php?lang=en&lugar=EGHE&t" \
                           "ipo=ALL&ord=REV&nil=SI&fmt=html&ano=2019&mes=01&day=23&hora=9&anof=2019&mesf=01&dayf=" \
                           "23&horaf=9&minf=59&send=send"

        # Runs method
        output1 = text_manipulation.contents_opener(file_path, file_name1)
        output2 = text_manipulation.contents_opener(file_path, file_name2)

        # Checks results match
        self.assertEqual(output1, expected_output1)
        self.assertEqual(output2, expected_output2)
 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)
 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)
예제 #6
0
 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)