16db28be2006574b6a5eb868cfa14f9ad01f0f3a
[librarian.git] / tests / utils.py
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright © 2008,2009,2010 Fundacja Nowoczesna Polska  
4 #
5 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
6 # For full license text see COPYING or <http://www.gnu.org/licenses/agpl.html>
7 #
8 from __future__ import with_statement
9 from os.path import realpath, join, dirname
10 import glob
11 import os
12
13 def get_fixture_dir(dir_name):
14     """Returns path to fixtures directory dir_name."""
15     return realpath(join(dirname(__file__), 'files', dir_name))
16
17
18 def get_fixture(dir_name, file_name):
19     """Returns path to fixture file_name in directory dir_name."""
20     return join(get_fixture_dir(dir_name), file_name)
21
22
23 def get_all_fixtures(dir_name, glob_pattern='*'):
24     """Returns list of paths for fixtures in directory dir_name matching the glob_pattern."""
25     return [get_fixture(dir_name, file_name) for file_name in glob.glob(join(get_fixture_dir(dir_name), glob_pattern))]
26
27
28 def remove_output_file(dir_name, file_name):
29     try:
30         os.remove(get_fixture(dir_name, file_name))
31     except:
32         pass