コード例 #1
0
ファイル: test_hdfs_hook.py プロジェクト: zlosim/airflow-fs
    def test_exists(self, remote_mock_dir):
        """Tests the `exists` method."""

        with HdfsHook() as hook:
            assert hook.exists(posixpath.join(remote_mock_dir, "subdir"))
            assert hook.exists(posixpath.join(remote_mock_dir, "test.txt"))
            assert not hook.exists(posixpath.join(remote_mock_dir, "non-existing.txt"))
コード例 #2
0
ファイル: test_hdfs_hook.py プロジェクト: zlosim/airflow-fs
    def test_walk(self, client, remote_mock_dir, mock_data_dir):
        """Tests the `walk` method."""

        with HdfsHook() as hook:
            entries = list(hook.walk(remote_mock_dir))

        pytest.helpers.assert_walk_equal(entries, os.walk(mock_data_dir))
コード例 #3
0
ファイル: test_hdfs_hook.py プロジェクト: zlosim/airflow-fs
    def test_open_read(self, remote_mock_dir):
        """Tests reading of a file using the `open` method."""

        file_path = posixpath.join(remote_mock_dir, "test.txt")
        with HdfsHook() as hook:
            with hook.open(file_path) as file_:
                content = file_.read()
            assert content == b"Test file\n"
コード例 #4
0
ファイル: test_hdfs_hook.py プロジェクト: zlosim/airflow-fs
    def test_makedirs(self, client, remote_temp_dir):
        """Tests the `mkdir` method with mode parameter."""

        dir_path = posixpath.join(remote_temp_dir, "some", "nested", "dir")

        with HdfsHook() as hook:
            hook.makedirs(dir_path, mode=0o750)

        assert client.exists(dir_path)
        assert client.info(dir_path)["permissions"] == 0o750
コード例 #5
0
ファイル: test_hdfs_hook.py プロジェクト: zlosim/airflow-fs
    def test_rmtree(self, client, remote_mock_dir):
        """Tests the `rmtree` method."""

        dir_path = posixpath.join(remote_mock_dir, "subdir")
        assert client.exists(dir_path)

        with HdfsHook() as hook:
            hook.rmtree(dir_path)

        assert not client.exists(dir_path)
コード例 #6
0
ファイル: test_hdfs_hook.py プロジェクト: zlosim/airflow-fs
    def test_rm(self, client, remote_mock_dir):
        """Tests the `rm` method."""

        file_path = posixpath.join(remote_mock_dir, "test.txt")
        assert client.exists(file_path)

        with HdfsHook() as hook:
            hook.rm(file_path)

        assert not client.exists(file_path)
コード例 #7
0
ファイル: test_hdfs_hook.py プロジェクト: zlosim/airflow-fs
    def test_open_write(self, client, remote_temp_dir):
        """Tests writing of a file using the `open` method."""

        file_path = posixpath.join(remote_temp_dir, "test2.txt")
        assert not client.exists(file_path)

        with HdfsHook() as hook:
            with hook.open(file_path, "wb") as file_:
                file_.write(b"Test file\n")

        assert client.exists(file_path)
コード例 #8
0
ファイル: test_hdfs_hook.py プロジェクト: zlosim/airflow-fs
    def test_makedirs_exists(self, client, remote_temp_dir):
        """Tests the `mkdir` method with exists_ok parameter."""

        dir_path = posixpath.join(remote_temp_dir, "some", "nested", "dir")

        with HdfsHook() as hook:
            hook.makedirs(dir_path, exist_ok=False)

            with pytest.raises(IOError):
                hook.makedirs(dir_path, exist_ok=False)

            hook.makedirs(dir_path, exist_ok=True)
コード例 #9
0
ファイル: test_hdfs_hook.py プロジェクト: zlosim/airflow-fs
    def test_mkdir_exists(self, client, remote_temp_dir):
        """Tests the `mkdir` method with the exists_ok parameter."""

        dir_path = posixpath.join(remote_temp_dir, "subdir")
        assert not client.exists(dir_path)

        with HdfsHook() as hook:
            hook.mkdir(dir_path, exist_ok=False)

            with pytest.raises(IOError):
                hook.mkdir(dir_path, exist_ok=False)

            hook.mkdir(dir_path, exist_ok=True)
コード例 #10
0
ファイル: test_hdfs_hook.py プロジェクト: zlosim/airflow-fs
    def test_listdir(self, remote_mock_dir, mock_data_dir):
        """Tests the `listdir` method."""

        with HdfsHook() as hook:
            assert set(hook.listdir(remote_mock_dir)) == set(os.listdir(mock_data_dir))
コード例 #11
0
ファイル: test_hdfs_hook.py プロジェクト: zlosim/airflow-fs
    def test_isdir(self, remote_mock_dir):
        """Tests the `isdir` method."""

        with HdfsHook() as hook:
            assert hook.isdir(posixpath.join(remote_mock_dir, "subdir"))
            assert not hook.isdir(posixpath.join(remote_mock_dir, "test.txt"))