#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (C) 2009 Adriano Monteiro Marques.
#
# Author: Bartosz SKOWRON <getxsick at gmail dot com>
#
# This library is free software; you can redistribute it and/or modify 
# it under the terms of the GNU Lesser General Public License as published 
# by the Free Software Foundation; either version 2.1 of the License, or 
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but 
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License 
# along with this library; if not, write to the Free Software Foundation, 
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

import sys
import shutil
import tempfile
import os.path

class TestUMPAInitialization(object):
    def setup_class(cls):
        # overwrite expanduser to use our temporary directory
        def expanduser(path):
            return cls.tmp_dir
        cls.tmp_dir = tempfile.mkdtemp()
        os.path.expanduser = expanduser
        # TODO: make a test for commented lines but clean .umpa and
        # re-import umpa after creating dirs
        #os.makedirs(os.path.join(cls.tmp_dir, '.umpa'))
        #os.makedirs(os.path.join(cls.tmp_dir, '.umpa', 'umpa_plugins',
        #                                                       'protocols'))
        import umpa

    def teardown_class(cls):
        shutil.rmtree(cls.tmp_dir)

    def test_paths(self):
        def path_exist(path):
            assert os.path.isdir(path)

        home = os.path.join(os.path.expanduser('~'), '.umpa')
        dirs = ('umpa_plugins',
                os.path.join('umpa_plugins', 'protocols'),
                os.path.join('umpa_plugins', 'extensions'),
            )
        path_list = [ os.path.join(home, p) for p in dirs ]

        for path in path_list:
            yield path_exist, path

    def test_syspath(self):
        home = os.path.join(os.path.expanduser('~'), '.umpa')
        assert home in sys.path
        assert sys.path.index(home) == 0

@@ -874,16 +874,26 @@
 7 USA %0A%0A
+import os%0A
 import s
@@ -895,16 +895,16 @@
 ort sys%0A
-
 import s
@@ -928,23 +928,8 @@
 file
-%0Aimport os.path
 %0A%0Acl
@@ -1206,334 +1206,117 @@
     
-# TODO: make a test for commented lines but clean .umpa and%0A        # re-import umpa after creating dirs%0A        #os.makedirs(os.path.join(cls.tmp_dir, '.umpa'))%0A        #os.makedirs(os.path.join(cls.tmp_dir, '.umpa', 'umpa_plugins',%0A        #                                                       'protocols'))%0A        import
+import umpa%0A        # dirty hack to get possibility of reload module later%0A        globals()%5Bumpa.__name__%5D =
  ump
@@ -1997,8 +1997,254 @@
 e) == 0%0A
+%0A    def test_reconstruct_broken_directory(self):%0A        home = os.path.join(os.path.expanduser('~'), '.umpa')%0A        for dir in os.listdir(home):%0A            shutil.rmtree(os.path.join(home,dir))%0A        reload(umpa)%0A        self.test_paths()%0A

Test for broken .umpa directory (if there are some missing dirs inside).