Added copyright notice about AGPL. Removed setuputils in favour of plain distutils.
[librarian.git] / tests / utils.py
1 # -*- coding: utf-8 -*-
2 #
3 #    This file is part of Librarian.
4 #
5 #    Copyright © 2008,2009,2010 Fundacja Nowoczesna Polska <fundacja@nowoczesnapolska.org.pl>
6 #    
7 #    For full list of contributors see AUTHORS file. 
8 #
9 #    This program is free software: you can redistribute it and/or modify
10 #    it under the terms of the GNU Affero General Public License as published by
11 #    the Free Software Foundation, either version 3 of the License, or
12 #    (at your option) any later version.
13 #
14 #    This program is distributed in the hope that it will be useful,
15 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #    GNU Affero General Public License for more details.
18 #
19 #    You should have received a copy of the GNU Affero General Public License
20 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22 from os.path import realpath, join, dirname
23 import glob
24 import os
25
26
27 def get_fixture_dir(dir_name):
28     """Returns path to fixtures directory dir_name."""
29     return realpath(join(dirname(__file__), 'files', dir_name))
30
31
32 def get_fixture(dir_name, file_name):
33     """Returns path to fixture file_name in directory dir_name."""
34     return join(get_fixture_dir(dir_name), file_name)
35
36
37 def get_all_fixtures(dir_name, glob_pattern='*'):
38     """Returns list of paths for fixtures in directory dir_name matching the glob_pattern."""
39     return [get_fixture(dir_name, file_name) for file_name in glob.glob(join(get_fixture_dir(dir_name), glob_pattern))]
40
41
42 def remove_output_file(dir_name, file_name):
43     try:
44         os.remove(get_fixture(dir_name, file_name))
45     except:
46         pass