Exemplo n.º 1
0
 def setUp(self):
     self.output_connections = [1, 2, 3, 4, 5]
     # delete pre-existing output data
     for connection_num in self.output_connections:
         deleteFile(outputFilename(connection_num))
     # create a pandas dataframe to write out
     self.data = read("#1")
 def setUp(self):
     self.filepath = 'delete_test_1.txt'
     # delete the file to start with clean slate
     deleteFile(self.filepath)
     # create new file in its place
     with open(self.filepath, 'w') as file:
         file.write('test')
     try:
         fileExists(self.filepath, throw_error=True)
     except:
         self.fail("deleteFile() raised an error unexpectedly!")
Exemplo n.º 3
0
 def __exit__(self, type, value, traceback):
     self.closeConnection()
     # if temporary file, attempt to clean up on exit
     if self.temporary:
         try:
             deleteFile(self.filepath, debug=self.debug)
         except:
             # (this is not the end of the world)
             if self.debug:
                 print("".join([
                     "Unable to delete temp file (will be cleanded up later",
                     "by asset manager) -- {}".format(self.filepath),
                 ]))
Exemplo n.º 4
0
    def __returnConnection(self):
        error_msg = "Unable to connect to input data"
        try:
            # if file exists, and not creating a new db, then throw error
            if self.create_new:
                if os.path.isfile(self.filepath):
                    try:
                        deleteFile(self.filepath, debug=self.debug)
                    except:
                        raise PermissionError(
                            "unable to delete file: {}".format(self.filepath))

                    if not os.access(os.path.dirname(self.filepath), os.W_OK):
                        raise PermissionError(
                            "unable to write to filepath: {}".format(
                                self.filepath))
                    return None

            elif fileExists(self.filepath,
                            throw_error=not (self.create_new),
                            msg=error_msg):
                # open connection and attempt to read one row
                # to confirm that it is a valid file

                if self.fileformat.filetype == "sqlite":
                    connection = sqlite3.connect(self.filepath)
                    connection.execute("select * from sqlite_master limit 1")
                elif self.fileformat.filetype == "yxdb":
                    connection = pyxdb.AlteryxYXDB()
                    connection.open(self.filepath)
                    # test that its a real yxdb file
                    connection.get_num_records()
                else:
                    self.__formatNotSupportedYet()
                return connection
        except:
            try:
                connection.close()
            except:
                pass
            raise ConnectionError(fileErrorMsg(error_msg, self.filepath))
 def testWriteDeleteWriteDelete(self):
     # delete the file to start with clean slate
     deleteFile(self.filepath)
     # does file exist?
     result = fileExists(self.filepath)
     self.assertFalse(result)
Exemplo n.º 6
0
 def tearDown(self):
     deleteFile(self.filename)
Exemplo n.º 7
0
 def setUp(self):
     self.connection = 5
     self.filename = outputFilename(self.connection)
     self.data = read("#2")
     deleteFile(self.filename)
     self.test = True
Exemplo n.º 8
0
 def tearDown(self):
     for connection_num in self.output_connections:
         deleteFile(outputFilename(connection_num))