예제 #1
0
    def test_create_file(self):
        """ Tests the method that creates a file."""

        self.assertFalse(Common.create_file(''))
        self.assertFalse(Common.create_file(None))
        # Create the file
        self.assertTrue(Common.create_file(self.test_data_root + 'Z.txt'))
        # Delete the file
        self.assertTrue(Common.delete_file(self.test_data_root + 'Z.txt'))
        # Now check file was deleted
        self.assertFalse(Common.file_exists(self.test_data_root + 'Z.txt'))
예제 #2
0
    def test_append_to_file(self):
        """ Tests the methods that appends text to a file."""

        # Create the file
        self.assertTrue(Common.create_file(self.test_data_root + 'Z.txt'))

        Common.append_to_file(self.test_data_root + 'Z.txt', '1,2,3,4,5')

        # Now check contents are as expected
        self.assertEqual(Common.read_file_as_string(self.test_data_root + 'Z.txt'), '1,2,3,4,5')

        # Delete the file
        self.assertTrue(Common.delete_file(self.test_data_root + 'Z.txt'))
        # Now check file was deleted
        self.assertFalse(Common.file_exists(self.test_data_root + 'Z.txt'))
예제 #3
0
    def test_file_exists(self):
        """ Tests the methods that checks if a file exists."""

        self.assertTrue(Common.file_exists(self.file_b))
        self.assertTrue(Common.file_exists(self.file_c))
        self.assertTrue(Common.file_exists(self.file_d))
        self.assertTrue(Common.file_exists(self.file_e))

        self.assertFalse(Common.file_exists(self.dir_a))
        self.assertFalse(Common.file_exists(self.test_data_root + "FAKE/X.txt" + os.pathsep + "A.txt"))
        self.assertFalse(Common.file_exists(self.test_data_root + "FAKE/Y.txt" + os.pathsep + "A.zip"))
        self.assertFalse(Common.file_exists(self.test_data_root + "FAKE/Z.txt" + os.pathsep + "A.a"))
        self.assertFalse(Common.file_exists(self.test_data_root + "FAKE/X.txt" + os.pathsep + "b.txt"))
        self.assertFalse(Common.file_exists(self.test_data_root + "FAKE/Y.txt" + os.pathsep + "a_b.txt"))
        self.assertFalse(Common.file_exists(self.test_data_root + "FAKE/Z.txt" + os.pathsep + "a.txt"))