8
8
import pytest
9
9
from docker .utils .build import PatternMatcher
10
10
11
- from flytekit .tools .ignore import DockerIgnore , GitIgnore , IgnoreGroup , StandardIgnore
11
+ from flytekit .tools .ignore import DockerIgnore , GitIgnore , IgnoreGroup , StandardIgnore , FlyteIgnore
12
12
13
13
14
14
def make_tree (root : Path , tree : Dict ):
@@ -102,6 +102,19 @@ def all_ignore(tmp_path):
102
102
return tmp_path
103
103
104
104
105
+ @pytest .fixture
106
+ def simple_flyteignore (tmp_path ):
107
+ tree = {
108
+ "sub" : {"some.bar" : "" },
109
+ "test.foo" : "" ,
110
+ "keep.foo" : "" ,
111
+ ".flyteignore" : "\n " .join (["*.foo" , "!keep.foo" , "# A comment" , "sub" ]),
112
+ }
113
+
114
+ make_tree (tmp_path , tree )
115
+ return tmp_path
116
+
117
+
105
118
def test_simple_gitignore (simple_gitignore ):
106
119
gitignore = GitIgnore (simple_gitignore )
107
120
assert gitignore .is_ignored (str (simple_gitignore / "test.foo" ))
@@ -219,7 +232,7 @@ def test_all_ignore(all_ignore):
219
232
220
233
def test_all_ignore_tar_filter (all_ignore ):
221
234
"""Test tar_filter method of all ignores grouped together"""
222
- ignore = IgnoreGroup (all_ignore , [GitIgnore , DockerIgnore , StandardIgnore ])
235
+ ignore = IgnoreGroup (all_ignore , [GitIgnore , DockerIgnore , StandardIgnore , FlyteIgnore ])
223
236
assert ignore .tar_filter (TarInfo (name = "sub" )).name == "sub"
224
237
assert ignore .tar_filter (TarInfo (name = "sub/some.bar" )).name == "sub/some.bar"
225
238
assert not ignore .tar_filter (TarInfo (name = "sub/__pycache__/" ))
@@ -232,4 +245,23 @@ def test_all_ignore_tar_filter(all_ignore):
232
245
assert ignore .tar_filter (TarInfo (name = "keep.foo" )).name == "keep.foo"
233
246
assert ignore .tar_filter (TarInfo (name = ".gitignore" )).name == ".gitignore"
234
247
assert ignore .tar_filter (TarInfo (name = ".dockerignore" )).name == ".dockerignore"
248
+ assert ignore .tar_filter (TarInfo (name = ".flyteignore" )).name == ".flyteignore"
235
249
assert not ignore .tar_filter (TarInfo (name = ".git" ))
250
+
251
+
252
+ def test_flyteignore_parse (simple_flyteignore ):
253
+ """Test .flyteignore file parsing"""
254
+ flyteignore = FlyteIgnore (simple_flyteignore )
255
+ assert flyteignore .pm .matches ("whatever.foo" )
256
+ assert not flyteignore .pm .matches ("keep.foo" )
257
+ assert flyteignore .pm .matches ("sub" )
258
+ assert flyteignore .pm .matches ("sub/stuff.txt" )
259
+
260
+
261
+ def test_simple_flyteignore (simple_flyteignore ):
262
+ flyteignore = FlyteIgnore (simple_flyteignore )
263
+ assert flyteignore .is_ignored (str (simple_flyteignore / "test.foo" ))
264
+ assert flyteignore .is_ignored (str (simple_flyteignore / "sub" ))
265
+ assert flyteignore .is_ignored (str (simple_flyteignore / "sub" / "some.bar" ))
266
+ assert not flyteignore .is_ignored (str (simple_flyteignore / "keep.foo" ))
267
+ assert not flyteignore .is_ignored (str (simple_flyteignore / ".flyteignore" ))
0 commit comments