# Path: speriment/utils.py
# def exactly_one(obj, attributes):
#     found = [attribute for attribute in attributes if hasattr(obj, attribute)]
#     if len(found) != 1:
#         raise ValueError, '''{} must have exactly one of the following attributes:
# 
# {}
# 
# but it has:
# 
# {}.'''.format(obj, attributes, found)


from component import Component
from run_if import RunIf
from collections import Counter
from speriment.utils import exactly_one
        if latin_square:
            self.latin_square = latin_square
            self._validate_latin_square()

        if pseudorandom:
            self.pseudorandom = pseudorandom

        # TODO what about mutated blocks
        if treatments:
            self.treatments = treatments
            # for (i, treatment) in enumerate(treatments):
            #     for block in treatment:
            #         block.run_if = RunIf(permutation = i)

    def _validate(self):
        self._validate_contents()
        self._validate_pseudorandom()
        self._validate_latin_square()
        self._validate_counterbalancing()

    def _validate_counterbalancing(self):
        if hasattr(self, 'counterbalance') and hasattr(self, 'treatments'):
            print '''Warning: counterbalance and treatments depend on the same
            variable, so using both in one experiment will cause
            correlations between which blocks are used and how blocks are
            ordered. If you want these to be decided independently, change
            'counterbalance' to 'exchangeable' so the order will be decided
            randomly for each participant.'''

    def _validate_contents(self):

# Path: speriment/utils.py
# def exactly_one(obj, attributes):
#     found = [attribute for attribute in attributes if hasattr(obj, attribute)]
#     if len(found) != 1:
#         raise ValueError, '''{} must have exactly one of the following attributes:
# 
# {}
# 
# but it has:
# 
# {}.'''.format(obj, attributes, found)


# Path: speriment/components/block.py
from component import Component
from run_if import RunIf
from collections import Counter
from speriment.utils import exactly_one

        if latin_square:
            self.latin_square = latin_square
            self._validate_latin_square()

        if pseudorandom:
            self.pseudorandom = pseudorandom

        # TODO what about mutated blocks
        if treatments:
            self.treatments = treatments
            # for (i, treatment) in enumerate(treatments):
            #     for block in treatment:
            #         block.run_if = RunIf(permutation = i)

    def _validate(self):
        self._validate_contents()
        self._validate_pseudorandom()
        self._validate_latin_square()
        self._validate_counterbalancing()

    def _validate_counterbalancing(self):
        if hasattr(self, 'counterbalance') and hasattr(self, 'treatments'):
            print '''Warning: counterbalance and treatments depend on the same
            variable, so using both in one experiment will cause
            correlations between which blocks are used and how blocks are
            ordered. If you want these to be decided independently, change
            'counterbalance' to 'exchangeable' so the order will be decided
            randomly for each participant.'''

    def _validate_contents(self):

        exactly_one(self, ['pages', 'groups', 'items', 'blocks'])