| 1 | """unit tests for logilab.common.shellutils""" |
|---|
| 2 | |
|---|
| 3 | import sys, os, tempfile, shutil |
|---|
| 4 | from os.path import join |
|---|
| 5 | |
|---|
| 6 | from logilab.common.testlib import TestCase, unittest_main |
|---|
| 7 | |
|---|
| 8 | from logilab.common.fileutils import * |
|---|
| 9 | |
|---|
| 10 | DATA_DIR = 'data' |
|---|
| 11 | |
|---|
| 12 | class FindTC(TestCase): |
|---|
| 13 | def test_include(self): |
|---|
| 14 | files = find(DATA_DIR, '.py') |
|---|
| 15 | self.assertSetEqual(files, |
|---|
| 16 | [join('data', f) for f in ['__init__.py', 'module.py', |
|---|
| 17 | 'module2.py', 'noendingnewline.py', |
|---|
| 18 | 'nonregr.py', join('sub', 'momo.py')]]) |
|---|
| 19 | files = find(DATA_DIR, ('.py',), blacklist=('sub',)) |
|---|
| 20 | self.assertSetEqual(files, |
|---|
| 21 | [join('data', f) for f in ['__init__.py', 'module.py', |
|---|
| 22 | 'module2.py', 'noendingnewline.py', |
|---|
| 23 | 'nonregr.py']]) |
|---|
| 24 | |
|---|
| 25 | def test_exclude(self): |
|---|
| 26 | files = find(DATA_DIR, ('.py', '.pyc'), exclude=True) |
|---|
| 27 | self.assertSetEqual(files, |
|---|
| 28 | [join('data', f) for f in ['foo.txt', |
|---|
| 29 | 'newlines.txt', |
|---|
| 30 | 'normal_file.txt', |
|---|
| 31 | 'test.ini', |
|---|
| 32 | 'test1.msg', |
|---|
| 33 | 'test2.msg', |
|---|
| 34 | 'spam.txt', |
|---|
| 35 | join('sub', 'doc.txt'), |
|---|
| 36 | 'write_protected_file.txt', |
|---|
| 37 | ]]) |
|---|
| 38 | |
|---|
| 39 | # def test_exclude_base_dir(self): |
|---|
| 40 | # self.assertEquals(files_by_ext(DATA_DIR, include_exts=('.py',), exclude_dirs=(DATA_DIR,)), |
|---|
| 41 | # []) |
|---|
| 42 | |
|---|
| 43 | if __name__ == '__main__': |
|---|
| 44 | unittest_main() |
|---|