Example #1
0
    def test_file_write_append_not_exists(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act
        with fs.mock():
            with open('/dir1/filenameY', 'a') as f:
                f.write(u'content 1 to filename Y in dir1')

        # Assert
        with fs.mock():
            with open('/dir1/filenameY') as f:
                self.assertTrue(os.path.exists('/dir1/filenameY'))
                self.assertEqual(f.read(), u'content 1 to filename Y in dir1')
Example #2
0
    def test_expanduser(self):
        # Arrange
        fs = FileSystem({}, user = "******")

        # Act & Assert
        with fs.mock():
            self.assertEqual(os.path.expanduser('~/teve'), '/home/douglas/teve')
Example #3
0
    def test_getcwd(self):
        # Arrange
        fs = FileSystem({}, cwd = '/dir42')

        # Act & Assert
        with fs.mock():
            self.assertEqual(os.getcwd(), '/dir42')
Example #4
0
    def test_file_write(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act
        with fs.mock():
            with open('/dir1/filename3', 'w') as f:
                f.write(u'content 1 to filename 3 in dir1\n')
                f.write(u'content 2 to filename 3 in dir1\n')

        # Assert
        with fs.mock():
            self.assertTrue(os.path.exists('/dir1/filename3'))
            with open('/dir1/filename3') as f:
                self.assertEqual(f.read(), u'content 1 to filename 3 in dir1\ncontent 2 to filename 3 in dir1\n')
Example #5
0
    def test_abspath(self):
        # Arrange
        fs = FileSystem({}, cwd = '/dir1')

        # Act & Assert
        with fs.mock():
            self.assertEqual(os.path.abspath('teve'), '/dir1/teve')
            self.assertEqual(os.path.abspath('/teve'), '/teve')
Example #6
0
    def test_is_file_exists(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act & Assert
        with fs.mock():
            self.assertEqual(os.path.exists('filename1'), True)
Example #7
0
    def test_is_file_with_file(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act & Assert
        with fs.mock():
            self.assertTrue(os.path.isfile('filename1'))
            self.assertFalse(os.path.isfile('filename2'))
Example #8
0
    def test_is_path_exists_with_dir(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act & Assert
        with fs.mock():
            self.assertTrue(os.path.exists('dir1'))
            self.assertFalse(os.path.exists('dir2'))
Example #9
0
    def test_file_open_not_exists(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act & Assert
        with fs.mock():
            with self.assertRaises(FileNotFoundError):
                open('filename2')
Example #10
0
    def test_file_open(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act & Assert
        with fs.mock():
            with open('filename1') as f:
                self.assertEqual(f.read(), data['filename1'])
Example #11
0
    def test_mkdir_in_not_existing_dir(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act & Assert
        with fs.mock():
            with self.assertRaises(FileNotFoundError):
                os.mkdir('/dirX/dir3/')
Example #12
0
    def test_mkdir(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act & Assert
        with fs.mock():
            os.mkdir('/dir1/dir3')
            self.assertTrue(os.path.exists('/dir1/dir3/'))
Example #13
0
    def test_mode_w_not_readable(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act & Assert
        with fs.mock():
            with open('/dir1/filenameZ', 'w') as f, self.assertRaises(UnsupportedOperation):
                f.read()
Example #14
0
    def test_mode_r_not_writable(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act & Assert
        with fs.mock():
            with open('/dir1/dir2/filename2', 'r') as f, self.assertRaises(UnsupportedOperation):
                f.write('test')
Example #15
0
    def test_file_write_dir_not_exists(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act & Assert
        with fs.mock():
            with self.assertRaises(FileNotFoundError):
                open('/dirX/filenameX', 'w')
Example #16
0
    def test_mkdir_existing(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act & Assert
        with fs.mock():
            with self.assertRaises(FileExistsError):
                os.mkdir('/dir1/dir2/')
            self.assertTrue(os.path.exists('/dir1/dir2/filename2'))