adama / src / adama / tests /

# -*- coding: utf-8 -*-


    Unit tests for the adama library.

import unittest
import os
import sys
import shutil

from adama.commandment import QG
from adama.exceptions import AdamaError

class TestBaseOrders(unittest.TestCase):
    """Base test initializer

    def setUp(self):
        self.base_path = '/tmp/pyproject'
        self.orders_path = self.base_path + '/orders'
        self.module = 'pyproject'
        self.command = 'pyp'
        # Creating temporary directories
        # Making packages
        for path in (self.base_path, self.orders_path):
            filename = os.path.join(path, '')
            with file(filename, 'a'):
                os.utime(filename, None)

    def tearDown(self):
        # Removing temporary files
        # Removing attributes
        del self.base_path
        del self.orders_path
        del self.module
        del self.command

    def _create_orders(self, *orders):
        """Creating some empty orders module"""
        orders_template_path = os.path.join(
        with open(orders_template_path, 'r') as template:
            order =, self.command)
            for filename in orders:
                with open(os.path.join(self.orders_path, filename), 'a') \
                    as new_order:

    def _add_to_syspath(self):
        """Adds a path to sys.path"""

    def _remove_from_syspath(self):
        """Removes a path to sys.path and modules from sys.modules"""
        for mod in [mod for mod in sys.modules if mod.startswith(self.module)]:
            del sys.modules[mod]

def no_shell_printing(func):
    """No shell printing for help when lauching tests
    print_functions = (QG.explanations, AdamaError.__call__)

    def wrap(**kwargs):
        """Wrapper for the printing function"""
        for function in print_functions:
            function.im_func.func_defaults = (False, )
        result = func(**kwargs)
        for function in print_functions:
            function.im_func.func_defaults = (True, )
        return result

    return wrap

def encapsulate_test_with_syspath(*orders):
    """Creates orders, adds path to sys path before launching test
    and removes path and modules
    def wrap(func):
        """Wrapper for calling a function in a package that needs to be in
        def wrapped_f(instance, *args, **kwargs):
            """Adding in sys.path, launching func and remove from sys.path"""
            func(instance, *args, **kwargs)
        return wrapped_f
    return wrap
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.