def test_detect_cmd_match(self): cmd = '[ -f %s ]' % (self.bn, ) s = fzsl.SimpleScanner('test', 'echo', detect_cmd=cmd) self.assertTrue(s.is_suitable(TESTDIR)) self.assertFalse(s.is_suitable('%s/../' % (TESTDIR, ))) cmd = '[ -f thisfileisnothere ]' s2 = fzsl.SimpleScanner('test', 'echo', detect_cmd=cmd) self.assertFalse(s2.is_suitable(TESTDIR))
def test_sort(self): s1 = fzsl.SimpleScanner('test', 'echo', priority=1) s2 = fzsl.SimpleScanner('test', 'echo', priority=2) l = [s2, s1] l.sort() self.assertEqual(l[0], s1) self.assertEqual(l[1], s2)
def test_detect_cmd_match(testdir, basename): cmd = "[ -f %s ]" % (basename,) s = fzsl.SimpleScanner("test", "echo", detect_cmd=cmd) assert s.is_suitable(testdir) assert not s.is_suitable("%s/../" % (testdir,)) cmd = "[ -f thisfileisnothere ]" s2 = fzsl.SimpleScanner("test", "echo", detect_cmd=cmd) assert not s2.is_suitable(testdir)
def test_cmd(self): cmd = 'find . -name %s' % (self.bn, ) s = fzsl.SimpleScanner('test', cmd) self.assertIn('./' + self.bn, s.scan(TESTDIR)) self.assertNotIn('.git' + self.bn, s.scan(TESTDIR)) self.assertEqual(0, len(s.scan('%s/../bin' % (TESTDIR, ))))
def test_cmd(testdir, basename): cmd = "find . -name %s" % (basename,) s = fzsl.SimpleScanner("test", cmd) assert "./" + basename in s.scan(testdir) assert ".git" + basename not in s.scan(testdir) assert not s.scan("%s/../bin" % (testdir,))
def test_scanner(self): cache = tempfile.NamedTemporaryFile(dir=TESTDIR, mode='w') with open(os.path.join(TESTDIR, 'files'), 'r') as src: cache.write(u'\n'.join(src.read().split())) cache.flush() s = fzsl.SimpleScanner('test', 'echo hi', cache=cache.name) results = s.scan() self.assertEqual(len(results), 49168) results = s.scan(rescan=True) self.assertEqual(len(results), 1) self.assertEqual(results[0], 'hi')
def test_scanner(testdir, tmpdir): cache = os.path.join(tmpdir, "cache") with open(cache, "w") as tp: with open(os.path.join(testdir, "files"), "r") as src: tp.write("\n".join(src.read().split())) s = fzsl.SimpleScanner("test", "echo hi", cache=cache) results = s.scan() assert len(results) == 49168 results = s.scan(rescan=True) assert len(results) == 1 assert results[0] == "hi"
def test_fallthrough(self): s = fzsl.SimpleScanner('test', 'echo') self.assertTrue(s.is_suitable(TESTDIR))
def test_root_path_match(self): s = fzsl.SimpleScanner('test', 'echo', root_path=TESTDIR) self.assertTrue(s.is_suitable(TESTDIR)) self.assertTrue(s.is_suitable('%s/test/stuff' % (TESTDIR, ))) self.assertFalse(s.is_suitable(os.path.dirname(TESTDIR))) self.assertFalse(s.is_suitable('%s/../' % (TESTDIR, )))
def setUp(self): self._scanner = fzsl.SimpleScanner("test", cmd="cat %s/files" % (TESTDIR, ), priority=1)
def test_fallthrough(testdir): s = fzsl.SimpleScanner("test", "echo") assert s.is_suitable(testdir)
def test_root_path_cmd(testdir): s = fzsl.SimpleScanner( "test", "echo", root_path="!echo %s" % (testdir,), detect_cmd="true" ) assert s.is_suitable(testdir)
def test_root_path_match(testdir): s = fzsl.SimpleScanner("test", "echo", root_path=testdir) assert s.is_suitable(testdir) assert s.is_suitable("%s/test/stuff" % (testdir,)) assert not s.is_suitable(os.path.dirname(testdir)) assert not s.is_suitable("%s/../" % (testdir,))
def test_sort(): s1 = fzsl.SimpleScanner("test", "echo", priority=1) s2 = fzsl.SimpleScanner("test", "echo", priority=2) assert [s1, s2] == sorted([s2, s1])
def setUp(self): self._scanner = fzsl.SimpleScanner('test', cmd='cat %s/files' % (TESTDIR, ), priority=1)