Exemplo n.º 1
0
 def test_simple_case_twice_with_append(self):
     converter = CSVConverter(config_file_name=os.path.join(fo, 'valid-simple-header-change.json'), append_mode=True)
     output = converter.convert(input_file_name=os.path.join(fo, 'valid-simple.csv'))
     with open(os.path.join(fo, 'valid-simple-new.csv')) as output_file:
         self.assertEqual(output_file.read(), output.replace('\r\n', '\n'))
     output = converter.convert(input_file_name=os.path.join(fo, 'valid-simple-two.csv'))
     with open(os.path.join(fo, 'valid-simple-appended.csv')) as output_file:
         self.assertEqual(output_file.read(), output.replace('\r\n', '\n'))
Exemplo n.º 2
0
class Window(Frame):
	def __init__(self, master = None):
		Frame.__init__(self, master)
		self.__master = master
		self.__init_window()
		self.__selected_file: str = ''
		self.__converter = CSVConverter()

	def __init_window(self):
		self.__master.title('KML Conversion Tool')
		self.__master.geometry('300x100')
		self.pack(fill = BOTH, expand = 1)

		self.__file_name = Label(self, text = 'No file has been selected yet', font = ('Roboto', 12))
		self.__file_name.grid(padx = 20, pady = 20)
		self.__file_name.pack()

		select_file_button = Button(self, text = 'Select File', command = lambda: self.__open_file_dialog())
		select_file_button.pack(fill = X)

		convert_button = Button(self, text = 'Convert File', command = lambda: self.__convert_file())
		convert_button.pack(fill = X)

	def __open_file_dialog(self):
		self.__selected_file = filedialog.askopenfilename(initialdir = "/", title = "Select file",
														  filetypes = (("kml files", "*.kml"), ("all files", "*.*")))

		messagebox.showinfo('Selected File', 'You selected {}'.format(self.__selected_file))

		prefix = self.__selected_file.rfind('/')
		file = self.__selected_file[prefix + 1:] if prefix != -1 else self.__selected_file
		self.__file_name['text'] = file

	def __convert_file(self):
		if not self.__selected_file:
			messagebox.showwarning('Error Converting File', 'Select a file first before converting it')
		else:
			self.__converter.convert(self.__selected_file)
Exemplo n.º 3
0
 def test_xlsx_simple_case_with_junk_before_heading(self):
     converter = CSVConverter(config_file_name=os.path.join(fo, 'valid-simple-header-change-with-hints.json'))
     output = converter.convert(input_file_name=os.path.join(fo, 'valid-simple-with-junk-before-heading.xlsx'))
     with open(os.path.join(fo, 'valid-simple-new.csv')) as output_file:
         self.assertEqual(output_file.read(), output.replace('\r\n', '\n'))
Exemplo n.º 4
0
 def test_xlsx_simple(self):
     converter = CSVConverter(config_file_name=os.path.join(fo, 'valid-simple-header-change.json'))
     output = converter.convert(input_file_name=os.path.join(fo, 'valid-simple.xlsx'))
     with open(os.path.join(fo, 'valid-simple-new.csv')) as output_file:
         self.assertEqual(output_file.read(), output.replace('\r\n', '\n'))
Exemplo n.º 5
0
 def test_append_two_simple(self):
     converter = CSVConverter(config_file_name=os.path.join(fo, 'valid-simple-header-change.json'))
     output = converter.convert(input_file_name=[os.path.join(fo, 'valid-simple.csv'),
                                                 os.path.join(fo, 'valid-simple-two.csv')])
     with open(os.path.join(fo, 'valid-simple-appended.csv')) as correct_file:
         self.assertEqual(correct_file.read(), output.replace('\r\n', '\n'))
Exemplo n.º 6
0
 def test_simple_with_funlinks(self):
     converter = CSVConverter(config_file_name=os.path.join(fo, 'valid-simple-with-funlink.json'))
     output = converter.convert(input_file_name=os.path.join(fo, 'valid-simple.csv'))
     with open(os.path.join(fo, 'valid-simple-double-digits.csv')) as correct_file:
         self.assertEqual(correct_file.read(), output.replace('\r\n', '\n'))
Exemplo n.º 7
0
 def test_simple_with_lambda(self):
     converter = CSVConverter(config_file_name=os.path.join(fo, 'valid-simple-with-lambda.json'))
     output = converter.convert(input_file_name=os.path.join(fo, 'valid-simple.csv'))
     with open(os.path.join(fo, 'valid-simple-to-lower.csv')) as output_file:
         self.assertEqual(output_file.read(), output.replace('\r\n', '\n'))
Exemplo n.º 8
0
 def test_simple_with_defaults(self):
     converter = CSVConverter(config_file_name=os.path.join(fo, 'valid-simple-with-defaults.json'))
     output = converter.convert(input_file_name=os.path.join(fo, 'valid-simple-with-missing.csv'))
     with open(os.path.join(fo, 'valid-simple-with-defaults.csv')) as output_file:
         self.assertEqual(output_file.read(), output.replace('\r\n', '\n'))