code: def test_path_partition_parser_dir(fs, base_dir):
      partition_parser = PathPartitionParser.of(
          PartitionStyle.DIRECTORY,
          base_dir=base_dir,
          field_names=["foo", "bar"],
          filesystem=fs,
      )
      _verify_resolved_paths_and_filesystem(partition_parser.scheme)
      base_dir = partition_parser.scheme.normalized_base_dir
  
      # parse unpartitioned paths...
      partition_kvs = partition_parser("")
      assert partition_kvs == {}
      if base_dir:
          unpartitioned_paths = [
              "",
              "foo/1",
              "bar/2",
              "baz/3",
              posixpath.join(base_dir, "test.txt"),
          ]
          for path in unpartitioned_paths:
              assert partition_parser(path) == {}
  
      partitioned_path = posixpath.join(base_dir, "1/2/test.txt")
      assert partition_parser(partitioned_path) == {
          "foo": "1",
          "bar": "2",
      }
      partitioned_path = posixpath.join(
          base_dir, " 1  / t w o /test.txt"
      )
      assert partition_parser(partitioned_path) == {
          "foo": " 1  ",
          "bar": " t w o ",
      }
      partitioned_path = posixpath.join(base_dir, "2/1/test.txt")
      assert partition_parser(partitioned_path) == {
          "foo": "2",
          "bar": "1",
      }
      partitioned_path = posixpath.join(base_dir, "1/2/")
      assert partition_parser(partitioned_path) == {
          "foo": "1",
          "bar": "2",
      }
      partitioned_path = posixpath.join(base_dir, "1/2/3")
      assert partition_parser(partitioned_path) == {
          "foo": "1",
          "bar": "2",
      }
  
      partition_parser = PathPartitionParser.of(
          PartitionStyle.DIRECTORY,
          base_dir=base_dir,
          field_names=["bar", "foo"],
          filesystem=fs,
      )
      partitioned_path = posixpath.join(base_dir, "1/2/test")
      assert partition_parser(partitioned_path) == {
          "bar": "1",
          "foo": "2",
      }
      partitioned_path = posixpath.join(base_dir, "2/1/test")
      assert partition_parser(partitioned_path) == {
          "bar": "2",
          "foo": "1",
      }
  
      partition_parser = PathPartitionParser.of(
          PartitionStyle.DIRECTORY,
          base_dir=base_dir,
          field_names=["year", None, "country"],
          filesystem=fs,
      )
  
      partitioned_path = posixpath.join(
          base_dir, "1970/countries/fr/products.csv"
      )
      assert partition_parser(partitioned_path) == {
          "year": "1970",
          "country": "fr",
      }
  
imports: import json
  import os
  import posixpath
  from typing import Any, Callable, Dict, Iterator, List, Optional, Union
  import pandas
  import pyarrow
  import pyarrow
  import pytest
  from pyarrow.fs import FileType
  from pytest_lazyfixture import lazy_fixture
  import ray
  from ray.data.block import Block
  from ray.data.dataset import Dataset
  from ray.data.datasource import FileBasedDatasource, PathPartitionParser
  from ray.data.datasource.file_based_datasource import FileExtensionFilter, _resolve_paths_and_filesystem
  from ray.data.datasource.partitioning import Partitioning, PartitionStyle, PathPartitionFilter
  from ray.data.tests.conftest import *
  from ray.tests.conftest import *
label_desc: Use image node_id 12 for calling a global function with example usage: test_path_partition_parser_dir(fs, base_dir) without return types