Exemplo n.º 1
0
def init():
    """This function will initialise program"""

    file = input('Enter path to .csv file you wanna reorganize:\n')
    new_file_name = input('Enter name of new .csv file:\n')

    if os.path.isfile(f'./processed_files/{new_file_name}.csv'
                      ):  # Change name of file to prevent overwriting

        new_file_name = 'random_' + ''.join(
            random.choice(string.ascii_uppercase + string.digits)
            for _ in range(7))  # generate random string
        print(
            colored(
                f'File with such name exist! Name of your file is changed to: {new_file_name}',
                color='yellow'))

    elif not new_file_name:  # Set default name if nothing passed
        new_file_name += 'new_file'

    process_file(file, new_file_name)
Exemplo n.º 2
0
    def test_wrong_format(self):
        """Test if function will stop in case if file with wrong format (in this case != .csv) passed"""
        file = process_file('./test_files/wrong_file_format.log', 'test_correct')

        self.assertFalse(file)
        os.remove(f'{os.getcwd()}/../processed_files/test_correct.csv')     # Remove created test_correct.csv file
Exemplo n.º 3
0
    def test_empty_file(self):
        """Test if process_file() will break after passing empty file"""
        file = process_file('./test_files/empty.csv', 'test_empty')

        self.assertFalse(file)
Exemplo n.º 4
0
    def test_file_creation_utf_16(self):
        """Test if process_file() will create file while given valid file in input (utf-16 input)"""
        process_file('./test_files/utf16_file.csv', 'test_correct')

        self.assertTrue(os.path.isfile('../processed_files/test_correct.csv'))