Ejemplo n.º 1
0
    def test_expanduser(self):
        # Arrange
        fs = FileSystem({}, user = "******")

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

        # Act & Assert
        with fs.mock():
            self.assertEqual(os.getcwd(), '/dir42')
Ejemplo n.º 3
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')
Ejemplo n.º 4
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)
Ejemplo n.º 5
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()
Ejemplo n.º 6
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')
Ejemplo n.º 7
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')
Ejemplo n.º 8
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'))
Ejemplo n.º 9
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/'))
Ejemplo n.º 10
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')
Ejemplo n.º 11
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'))
Ejemplo n.º 12
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/')
Ejemplo n.º 13
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'])
Ejemplo n.º 14
0
    def test_get_data_sub_file(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act
        result = fs.get_data('/dir1/dir2/filename2')

        # Assert
        self.assertEqual(result, data['dir1']['dir2']['filename2'])
Ejemplo n.º 15
0
    def test_get_data_simple_existing_root(self):
        # Arrange
        data = copy(init_data)
        fs = FileSystem(data)

        # Act
        result = fs.get_data('/filename1')

        # Assert
        self.assertEqual(result, data['filename1'])
Ejemplo n.º 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'))
Ejemplo n.º 17
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')
Ejemplo n.º 18
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')