test_pattern.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. import io
  2. import sys
  3. import pytest
  4. from flexmock import flexmock
  5. from borgmatic.actions import pattern as module
  6. from borgmatic.borg.pattern import Pattern, Pattern_source, Pattern_style, Pattern_type
  7. @pytest.mark.parametrize(
  8. 'pattern_line,expected_pattern',
  9. (
  10. ('R /foo', Pattern('/foo', source=Pattern_source.CONFIG)),
  11. ('P sh', Pattern('sh', Pattern_type.PATTERN_STYLE, source=Pattern_source.CONFIG)),
  12. ('+ /foo*', Pattern('/foo*', Pattern_type.INCLUDE, source=Pattern_source.CONFIG)),
  13. (
  14. '+ sh:/foo*',
  15. Pattern(
  16. '/foo*', Pattern_type.INCLUDE, Pattern_style.SHELL, source=Pattern_source.CONFIG
  17. ),
  18. ),
  19. ),
  20. )
  21. def test_parse_pattern_transforms_pattern_line_to_instance(pattern_line, expected_pattern):
  22. module.parse_pattern(pattern_line) == expected_pattern
  23. def test_parse_pattern_with_invalid_pattern_line_errors():
  24. with pytest.raises(ValueError):
  25. module.parse_pattern('/foo')
  26. def test_collect_patterns_converts_source_directories():
  27. assert module.collect_patterns({'source_directories': ['/foo', '/bar']}) == (
  28. Pattern('/foo', source=Pattern_source.CONFIG),
  29. Pattern('/bar', source=Pattern_source.CONFIG),
  30. )
  31. def test_collect_patterns_parses_config_patterns():
  32. flexmock(module).should_receive('parse_pattern').with_args('R /foo').and_return(Pattern('/foo'))
  33. flexmock(module).should_receive('parse_pattern').with_args('# comment').never()
  34. flexmock(module).should_receive('parse_pattern').with_args('').never()
  35. flexmock(module).should_receive('parse_pattern').with_args(' ').never()
  36. flexmock(module).should_receive('parse_pattern').with_args('R /bar').and_return(Pattern('/bar'))
  37. assert module.collect_patterns({'patterns': ['R /foo', '# comment', '', ' ', 'R /bar']}) == (
  38. Pattern('/foo'),
  39. Pattern('/bar'),
  40. )
  41. def test_collect_patterns_converts_exclude_patterns():
  42. assert module.collect_patterns({'exclude_patterns': ['/foo', '/bar', 'sh:**/baz']}) == (
  43. Pattern(
  44. '/foo', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH, source=Pattern_source.CONFIG
  45. ),
  46. Pattern(
  47. '/bar', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH, source=Pattern_source.CONFIG
  48. ),
  49. Pattern(
  50. '**/baz', Pattern_type.NO_RECURSE, Pattern_style.SHELL, source=Pattern_source.CONFIG
  51. ),
  52. )
  53. def test_collect_patterns_reads_config_patterns_from_file():
  54. builtins = flexmock(sys.modules['builtins'])
  55. builtins.should_receive('open').with_args('file1.txt').and_return(io.StringIO('R /foo'))
  56. builtins.should_receive('open').with_args('file2.txt').and_return(
  57. io.StringIO('R /bar\n# comment\n\n \nR /baz')
  58. )
  59. flexmock(module).should_receive('parse_pattern').with_args('R /foo').and_return(Pattern('/foo'))
  60. flexmock(module).should_receive('parse_pattern').with_args('# comment').never()
  61. flexmock(module).should_receive('parse_pattern').with_args('').never()
  62. flexmock(module).should_receive('parse_pattern').with_args(' ').never()
  63. flexmock(module).should_receive('parse_pattern').with_args('R /bar').and_return(Pattern('/bar'))
  64. flexmock(module).should_receive('parse_pattern').with_args('R /baz').and_return(Pattern('/baz'))
  65. assert module.collect_patterns({'patterns_from': ['file1.txt', 'file2.txt']}) == (
  66. Pattern('/foo'),
  67. Pattern('/bar'),
  68. Pattern('/baz'),
  69. )
  70. def test_collect_patterns_errors_on_missing_config_patterns_from_file():
  71. builtins = flexmock(sys.modules['builtins'])
  72. builtins.should_receive('open').with_args('file1.txt').and_raise(FileNotFoundError)
  73. flexmock(module).should_receive('parse_pattern').never()
  74. with pytest.raises(ValueError):
  75. module.collect_patterns({'patterns_from': ['file1.txt', 'file2.txt']})
  76. def test_collect_patterns_reads_config_exclude_from_file():
  77. builtins = flexmock(sys.modules['builtins'])
  78. builtins.should_receive('open').with_args('file1.txt').and_return(io.StringIO('/foo'))
  79. builtins.should_receive('open').with_args('file2.txt').and_return(
  80. io.StringIO('/bar\n# comment\n\n \n/baz')
  81. )
  82. flexmock(module).should_receive('parse_pattern').with_args(
  83. '! /foo', default_style=Pattern_style.FNMATCH
  84. ).and_return(Pattern('/foo', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH))
  85. flexmock(module).should_receive('parse_pattern').with_args(
  86. '! /bar', default_style=Pattern_style.FNMATCH
  87. ).and_return(Pattern('/bar', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH))
  88. flexmock(module).should_receive('parse_pattern').with_args('# comment').never()
  89. flexmock(module).should_receive('parse_pattern').with_args('').never()
  90. flexmock(module).should_receive('parse_pattern').with_args(' ').never()
  91. flexmock(module).should_receive('parse_pattern').with_args(
  92. '! /baz', default_style=Pattern_style.FNMATCH
  93. ).and_return(Pattern('/baz', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH))
  94. assert module.collect_patterns({'exclude_from': ['file1.txt', 'file2.txt']}) == (
  95. Pattern('/foo', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH),
  96. Pattern('/bar', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH),
  97. Pattern('/baz', Pattern_type.NO_RECURSE, Pattern_style.FNMATCH),
  98. )
  99. def test_collect_patterns_errors_on_missing_config_exclude_from_file():
  100. builtins = flexmock(sys.modules['builtins'])
  101. builtins.should_receive('open').with_args('file1.txt').and_raise(OSError)
  102. flexmock(module).should_receive('parse_pattern').never()
  103. with pytest.raises(ValueError):
  104. module.collect_patterns({'exclude_from': ['file1.txt', 'file2.txt']})
  105. def test_expand_directory_with_basic_path_passes_it_through():
  106. flexmock(module.os.path).should_receive('expanduser').and_return('foo')
  107. flexmock(module.glob).should_receive('glob').and_return([])
  108. paths = module.expand_directory('foo', None)
  109. assert paths == ['foo']
  110. def test_expand_directory_with_glob_expands():
  111. flexmock(module.os.path).should_receive('expanduser').and_return('foo*')
  112. flexmock(module.glob).should_receive('glob').and_return(['foo', 'food'])
  113. paths = module.expand_directory('foo*', None)
  114. assert paths == ['foo', 'food']
  115. def test_expand_directory_strips_off_working_directory():
  116. flexmock(module.os.path).should_receive('expanduser').and_return('foo')
  117. flexmock(module.glob).should_receive('glob').with_args('/working/dir/foo').and_return([]).once()
  118. paths = module.expand_directory('foo', working_directory='/working/dir')
  119. assert paths == ['foo']
  120. def test_expand_directory_globs_working_directory_and_strips_it_off():
  121. flexmock(module.os.path).should_receive('expanduser').and_return('foo*')
  122. flexmock(module.glob).should_receive('glob').with_args('/working/dir/foo*').and_return(
  123. ['/working/dir/foo', '/working/dir/food']
  124. ).once()
  125. paths = module.expand_directory('foo*', working_directory='/working/dir')
  126. assert paths == ['foo', 'food']
  127. def test_expand_directory_with_slashdot_hack_globs_working_directory_and_strips_it_off():
  128. flexmock(module.os.path).should_receive('expanduser').and_return('./foo*')
  129. flexmock(module.glob).should_receive('glob').with_args('/working/dir/./foo*').and_return(
  130. ['/working/dir/./foo', '/working/dir/./food']
  131. ).once()
  132. paths = module.expand_directory('./foo*', working_directory='/working/dir')
  133. assert paths == ['./foo', './food']
  134. def test_expand_directory_with_working_directory_matching_start_of_directory_does_not_strip_it_off():
  135. flexmock(module.os.path).should_receive('expanduser').and_return('/working/dir/foo')
  136. flexmock(module.glob).should_receive('glob').with_args('/working/dir/foo').and_return(
  137. ['/working/dir/foo']
  138. ).once()
  139. paths = module.expand_directory('/working/dir/foo', working_directory='/working/dir')
  140. assert paths == ['/working/dir/foo']
  141. def test_expand_patterns_flattens_expanded_directories():
  142. flexmock(module).should_receive('expand_directory').with_args('~/foo', None).and_return(
  143. ['/root/foo']
  144. )
  145. flexmock(module).should_receive('expand_directory').with_args('bar*', None).and_return(
  146. ['bar', 'barf']
  147. )
  148. paths = module.expand_patterns((Pattern('~/foo'), Pattern('bar*')))
  149. assert paths == (Pattern('/root/foo'), Pattern('bar'), Pattern('barf'))
  150. def test_expand_patterns_with_working_directory_passes_it_through():
  151. flexmock(module).should_receive('expand_directory').with_args('foo', '/working/dir').and_return(
  152. ['/working/dir/foo']
  153. )
  154. patterns = module.expand_patterns((Pattern('foo'),), working_directory='/working/dir')
  155. assert patterns == (Pattern('/working/dir/foo'),)
  156. def test_expand_patterns_does_not_expand_skip_paths():
  157. flexmock(module).should_receive('expand_directory').with_args('/foo', None).and_return(['/foo'])
  158. flexmock(module).should_receive('expand_directory').with_args('/bar*', None).never()
  159. patterns = module.expand_patterns((Pattern('/foo'), Pattern('/bar*')), skip_paths=('/bar*',))
  160. assert patterns == (Pattern('/foo'), Pattern('/bar*'))
  161. def test_expand_patterns_considers_none_as_no_patterns():
  162. assert module.expand_patterns(None) == ()
  163. def test_expand_patterns_expands_tildes_and_globs_in_root_patterns():
  164. flexmock(module.os.path).should_receive('expanduser').never()
  165. flexmock(module).should_receive('expand_directory').and_return(
  166. ['/root/foo/one', '/root/foo/two']
  167. )
  168. paths = module.expand_patterns((Pattern('~/foo/*'),))
  169. assert paths == (Pattern('/root/foo/one'), Pattern('/root/foo/two'))
  170. def test_expand_patterns_expands_only_tildes_in_non_root_patterns():
  171. flexmock(module).should_receive('expand_directory').never()
  172. flexmock(module.os.path).should_receive('expanduser').and_return('/root/bar/*')
  173. paths = module.expand_patterns((Pattern('~/bar/*', Pattern_type.INCLUDE),))
  174. assert paths == (Pattern('/root/bar/*', Pattern_type.INCLUDE),)
  175. def test_get_existent_path_or_parent_passes_through_existent_path():
  176. flexmock(module.os.path).should_receive('exists').and_return(True)
  177. assert module.get_existent_path_or_parent('/foo/bar/baz') == '/foo/bar/baz'
  178. def test_get_existent_path_or_parent_with_non_existent_path_returns_none():
  179. flexmock(module.os.path).should_receive('exists').and_return(False)
  180. assert module.get_existent_path_or_parent('/foo/bar/baz') is None
  181. def test_get_existent_path_or_parent_with_non_existent_path_returns_existent_parent():
  182. flexmock(module.os.path).should_receive('exists').with_args('/foo/bar/baz*').and_return(False)
  183. flexmock(module.os.path).should_receive('exists').with_args('/foo/bar').and_return(True)
  184. flexmock(module.os.path).should_receive('exists').with_args('/foo').never()
  185. flexmock(module.os.path).should_receive('exists').with_args('/').never()
  186. assert module.get_existent_path_or_parent('/foo/bar/baz*') == '/foo/bar'
  187. def test_get_existent_path_or_parent_with_non_existent_path_returns_existent_grandparent():
  188. flexmock(module.os.path).should_receive('exists').with_args('/foo/bar/baz*').and_return(False)
  189. flexmock(module.os.path).should_receive('exists').with_args('/foo/bar').and_return(False)
  190. flexmock(module.os.path).should_receive('exists').with_args('/foo').and_return(True)
  191. flexmock(module.os.path).should_receive('exists').with_args('/').never()
  192. assert module.get_existent_path_or_parent('/foo/bar/baz*') == '/foo'
  193. def test_get_existent_path_or_parent_with_end_to_end_test_prefix_returns_none():
  194. flexmock(module.os.path).should_receive('exists').never()
  195. assert module.get_existent_path_or_parent('/e2e/foo/bar/baz') is None
  196. def test_device_map_patterns_gives_device_id_per_path():
  197. flexmock(module).should_receive('get_existent_path_or_parent').replace_with(lambda path: path)
  198. flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
  199. flexmock(module.os).should_receive('stat').with_args('/bar').and_return(flexmock(st_dev=66))
  200. device_map = module.device_map_patterns(
  201. (
  202. Pattern('/foo'),
  203. Pattern('^/bar', type=Pattern_type.INCLUDE, style=Pattern_style.REGULAR_EXPRESSION),
  204. )
  205. )
  206. assert device_map == (
  207. Pattern('/foo', device=55),
  208. Pattern(
  209. '^/bar', type=Pattern_type.INCLUDE, style=Pattern_style.REGULAR_EXPRESSION, device=66
  210. ),
  211. )
  212. def test_device_map_patterns_with_missing_path_does_not_error():
  213. flexmock(module).should_receive('get_existent_path_or_parent').with_args('/foo').and_return(
  214. '/foo'
  215. )
  216. flexmock(module).should_receive('get_existent_path_or_parent').with_args('/bar').and_return(
  217. None
  218. )
  219. flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
  220. flexmock(module.os).should_receive('stat').with_args('/bar').never()
  221. device_map = module.device_map_patterns((Pattern('/foo'), Pattern('/bar')))
  222. assert device_map == (
  223. Pattern('/foo', device=55),
  224. Pattern('/bar'),
  225. )
  226. def test_device_map_patterns_uses_working_directory_to_construct_path():
  227. flexmock(module).should_receive('get_existent_path_or_parent').replace_with(lambda path: path)
  228. flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
  229. flexmock(module.os).should_receive('stat').with_args('/working/dir/bar').and_return(
  230. flexmock(st_dev=66)
  231. )
  232. device_map = module.device_map_patterns(
  233. (Pattern('/foo'), Pattern('bar')), working_directory='/working/dir'
  234. )
  235. assert device_map == (
  236. Pattern('/foo', device=55),
  237. Pattern('bar', device=66),
  238. )
  239. def test_device_map_patterns_with_existing_device_id_does_not_overwrite_it():
  240. flexmock(module).should_receive('get_existent_path_or_parent').replace_with(lambda path: path)
  241. flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
  242. flexmock(module.os).should_receive('stat').with_args('/bar').and_return(flexmock(st_dev=100))
  243. device_map = module.device_map_patterns((Pattern('/foo'), Pattern('/bar', device=66)))
  244. assert device_map == (
  245. Pattern('/foo', device=55),
  246. Pattern('/bar', device=66),
  247. )
  248. @pytest.mark.parametrize(
  249. 'patterns,expected_patterns,one_file_system',
  250. (
  251. ((Pattern('/', device=1), Pattern('/root', device=1)), (Pattern('/', device=1),), False),
  252. ((Pattern('/', device=1), Pattern('/root/', device=1)), (Pattern('/', device=1),), False),
  253. (
  254. (Pattern('/', device=1), Pattern('/root', device=2)),
  255. (Pattern('/', device=1),),
  256. False,
  257. ),
  258. ((Pattern('/root', device=1), Pattern('/', device=1)), (Pattern('/', device=1),), False),
  259. (
  260. (Pattern('/root', device=1), Pattern('/root/foo', device=1)),
  261. (Pattern('/root', device=1),),
  262. False,
  263. ),
  264. (
  265. (Pattern('/root/', device=1), Pattern('/root/foo', device=1)),
  266. (Pattern('/root/', device=1),),
  267. False,
  268. ),
  269. (
  270. (Pattern('/root', device=1), Pattern('/root/foo/', device=1)),
  271. (Pattern('/root', device=1),),
  272. False,
  273. ),
  274. (
  275. (Pattern('/root', device=1), Pattern('/root/foo', device=2)),
  276. (Pattern('/root', device=1),),
  277. False,
  278. ),
  279. (
  280. (Pattern('/root/foo', device=1), Pattern('/root', device=1)),
  281. (Pattern('/root', device=1),),
  282. False,
  283. ),
  284. (
  285. (Pattern('/root', device=None), Pattern('/root/foo', device=None)),
  286. (Pattern('/root'), Pattern('/root/foo')),
  287. False,
  288. ),
  289. (
  290. (
  291. Pattern('/root', device=1),
  292. Pattern('/etc', device=1),
  293. Pattern('/root/foo/bar', device=1),
  294. ),
  295. (Pattern('/root', device=1), Pattern('/etc', device=1)),
  296. False,
  297. ),
  298. (
  299. (
  300. Pattern('/root', device=1),
  301. Pattern('/root/foo', device=1),
  302. Pattern('/root/foo/bar', device=1),
  303. ),
  304. (Pattern('/root', device=1),),
  305. False,
  306. ),
  307. (
  308. (Pattern('/dup', device=1), Pattern('/dup', device=1)),
  309. (Pattern('/dup', device=1),),
  310. False,
  311. ),
  312. (
  313. (Pattern('/foo', device=1), Pattern('/bar', device=1)),
  314. (Pattern('/foo', device=1), Pattern('/bar', device=1)),
  315. False,
  316. ),
  317. (
  318. (Pattern('/foo', device=1), Pattern('/bar', device=2)),
  319. (Pattern('/foo', device=1), Pattern('/bar', device=2)),
  320. False,
  321. ),
  322. ((Pattern('/root/foo', device=1),), (Pattern('/root/foo', device=1),), False),
  323. (
  324. (Pattern('/', device=1), Pattern('/root', Pattern_type.INCLUDE, device=1)),
  325. (Pattern('/', device=1), Pattern('/root', Pattern_type.INCLUDE, device=1)),
  326. False,
  327. ),
  328. (
  329. (Pattern('/root', Pattern_type.INCLUDE, device=1), Pattern('/', device=1)),
  330. (Pattern('/root', Pattern_type.INCLUDE, device=1), Pattern('/', device=1)),
  331. False,
  332. ),
  333. ((Pattern('/', device=1), Pattern('/root', device=1)), (Pattern('/', device=1),), True),
  334. ((Pattern('/', device=1), Pattern('/root/', device=1)), (Pattern('/', device=1),), True),
  335. (
  336. (Pattern('/', device=1), Pattern('/root', device=2)),
  337. (Pattern('/', device=1), Pattern('/root', device=2)),
  338. True,
  339. ),
  340. ((Pattern('/root', device=1), Pattern('/', device=1)), (Pattern('/', device=1),), True),
  341. (
  342. (Pattern('/root', device=1), Pattern('/root/foo', device=1)),
  343. (Pattern('/root', device=1),),
  344. True,
  345. ),
  346. (
  347. (Pattern('/root/', device=1), Pattern('/root/foo', device=1)),
  348. (Pattern('/root/', device=1),),
  349. True,
  350. ),
  351. (
  352. (Pattern('/root', device=1), Pattern('/root/foo/', device=1)),
  353. (Pattern('/root', device=1),),
  354. True,
  355. ),
  356. (
  357. (Pattern('/root', device=1), Pattern('/root/foo', device=2)),
  358. (Pattern('/root', device=1), Pattern('/root/foo', device=2)),
  359. True,
  360. ),
  361. (
  362. (Pattern('/root/foo', device=1), Pattern('/root', device=1)),
  363. (Pattern('/root', device=1),),
  364. True,
  365. ),
  366. (
  367. (Pattern('/root', device=None), Pattern('/root/foo', device=None)),
  368. (Pattern('/root'), Pattern('/root/foo')),
  369. True,
  370. ),
  371. (
  372. (
  373. Pattern('/root', device=1),
  374. Pattern('/etc', device=1),
  375. Pattern('/root/foo/bar', device=1),
  376. ),
  377. (Pattern('/root', device=1), Pattern('/etc', device=1)),
  378. True,
  379. ),
  380. (
  381. (
  382. Pattern('/root', device=1),
  383. Pattern('/root/foo', device=1),
  384. Pattern('/root/foo/bar', device=1),
  385. ),
  386. (Pattern('/root', device=1),),
  387. True,
  388. ),
  389. (
  390. (Pattern('/dup', device=1), Pattern('/dup', device=1)),
  391. (Pattern('/dup', device=1),),
  392. True,
  393. ),
  394. (
  395. (Pattern('/foo', device=1), Pattern('/bar', device=1)),
  396. (Pattern('/foo', device=1), Pattern('/bar', device=1)),
  397. True,
  398. ),
  399. (
  400. (Pattern('/foo', device=1), Pattern('/bar', device=2)),
  401. (Pattern('/foo', device=1), Pattern('/bar', device=2)),
  402. True,
  403. ),
  404. ((Pattern('/root/foo', device=1),), (Pattern('/root/foo', device=1),), True),
  405. (
  406. (Pattern('/', device=1), Pattern('/root', Pattern_type.INCLUDE, device=1)),
  407. (Pattern('/', device=1), Pattern('/root', Pattern_type.INCLUDE, device=1)),
  408. True,
  409. ),
  410. (
  411. (Pattern('/root', Pattern_type.INCLUDE, device=1), Pattern('/', device=1)),
  412. (Pattern('/root', Pattern_type.INCLUDE, device=1), Pattern('/', device=1)),
  413. True,
  414. ),
  415. ),
  416. )
  417. def test_deduplicate_patterns_omits_child_paths_based_on_device_and_one_file_system(
  418. patterns, expected_patterns, one_file_system
  419. ):
  420. assert (
  421. module.deduplicate_patterns(patterns, {'one_file_system': one_file_system})
  422. == expected_patterns
  423. )
  424. def test_process_patterns_includes_patterns():
  425. flexmock(module).should_receive('deduplicate_patterns').and_return(
  426. (Pattern('foo'), Pattern('bar'))
  427. )
  428. flexmock(module).should_receive('device_map_patterns').and_return({})
  429. flexmock(module).should_receive('expand_patterns').with_args(
  430. (Pattern('foo'), Pattern('bar')),
  431. working_directory='/working',
  432. skip_paths=set(),
  433. ).and_return(()).once()
  434. assert module.process_patterns(
  435. (Pattern('foo'), Pattern('bar')),
  436. config={},
  437. working_directory='/working',
  438. ) == [Pattern('foo'), Pattern('bar')]
  439. def test_process_patterns_skips_expand_for_requested_paths():
  440. skip_paths = {flexmock()}
  441. flexmock(module).should_receive('deduplicate_patterns').and_return(
  442. (Pattern('foo'), Pattern('bar'))
  443. )
  444. flexmock(module).should_receive('device_map_patterns').and_return({})
  445. flexmock(module).should_receive('expand_patterns').with_args(
  446. (Pattern('foo'), Pattern('bar')),
  447. working_directory='/working',
  448. skip_paths=skip_paths,
  449. ).and_return(()).once()
  450. assert module.process_patterns(
  451. (Pattern('foo'), Pattern('bar')),
  452. config={},
  453. working_directory='/working',
  454. skip_expand_paths=skip_paths,
  455. ) == [Pattern('foo'), Pattern('bar')]