If PurePath.match(pattern) does
Match this path against the provided glob-style pattern. Return True if matching is successful, False otherwise
and Path.glob(pattern) will
Glob the given pattern in the directory represented by this path, yielding all matching files (of any kind):
Question-1
Then why the below assertion fails?
query_files = Path('../').glob("sql-queries/**/*.sql")
filtered_files = [fname for fname in query_files if fname.match("sql-queries/**/*.sql")]
assert query_files == filtered_files # This assertion fails?
Question-2
How can we modify the PurePath.match
pattern, to ensure the assertion does not fail.
NB The recursive pattern fails to Path.match
the files under base path which are matched and returned by Path.glob
. This seems to be the observable discrepancies between the two APIs.
QnA
Q: Can you give an example of a specific path that appears in query_files but not filtered_files?
A:
query_files = <class 'list'>: [
PosixPath('../sql-queries/combined_gv.sql'),
PosixPath('../sql-queries/gv_with_merchant.sql'),
PosixPath('../sql-queries/merchant_dimension.sql'),
PosixPath('../sql-queries/gen_test_data/combined_gv.sql'),
PosixPath('../sql-queries/gen_test_data/merchant_dimension.sql')]
filtered_files = <class 'list'>: [
PosixPath('../sql-queries/gen_test_data/combined_gv.sql'),
PosixPath('../sql-queries/gen_test_data/merchant_dimension.sql')]