|
| 1 | +import sys |
1 | 2 | import typing as ty
|
2 | 3 | import pytest
|
3 | 4 | from fileformats.generic import Directory, DirectoryOf, SetOf
|
@@ -70,3 +71,36 @@ def test_set_optional_contents():
|
70 | 71 | sample_set = SetOf[ty.Optional[MyFormatGz]](my_format)
|
71 | 72 | assert sample_set.contents == [my_format]
|
72 | 73 | assert list(sample_set.required_paths()) == [my_format.fspath]
|
| 74 | + |
| 75 | + |
| 76 | +@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher") |
| 77 | +def test_directory_optional_contents_pep604(tmp_path): |
| 78 | + my_format = MyFormatGz.sample(dest_dir=tmp_path) |
| 79 | + sample_dir = DirectoryOf[MyFormatGz](tmp_path) |
| 80 | + EncodedText.sample(dest_dir=tmp_path) |
| 81 | + assert sample_dir.contents == [my_format] |
| 82 | + |
| 83 | + optional_dir = DirectoryOf[MyFormatGz, YourFormat | None](sample_dir) |
| 84 | + assert optional_dir.contents == [my_format] |
| 85 | + |
| 86 | + your_format = YourFormat.sample(dest_dir=tmp_path) |
| 87 | + optional_dir = DirectoryOf[MyFormatGz, YourFormat | None](sample_dir) |
| 88 | + assert optional_dir.contents == [my_format, your_format] |
| 89 | + |
| 90 | + |
| 91 | +@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher") |
| 92 | +def test_set_optional_contents_pep604(): |
| 93 | + my_format = MyFormatGz.sample() |
| 94 | + your_format = YourFormat.sample() |
| 95 | + |
| 96 | + sample_set = SetOf[MyFormatGz, YourFormat | None](my_format) |
| 97 | + assert sample_set.contents == [my_format] |
| 98 | + assert list(sample_set.required_paths()) == [my_format.fspath] |
| 99 | + |
| 100 | + sample_set = SetOf[MyFormatGz, YourFormat | None](my_format, your_format) |
| 101 | + assert sample_set.contents == [my_format, your_format] |
| 102 | + assert set(sample_set.required_paths()) == {my_format.fspath, your_format.fspath} |
| 103 | + |
| 104 | + sample_set = SetOf[MyFormatGz | None](my_format) |
| 105 | + assert sample_set.contents == [my_format] |
| 106 | + assert list(sample_set.required_paths()) == [my_format.fspath] |
0 commit comments