예제 #1
0
    def test_classes_and_functions_defined(self):
        """ test all specified classes and functions defined correctly """
        a3 = AttributeGuesser.get_wrapped_object(self.a3)

        self.aggregate(self.assertDefined, a3, 'TASK_ONE')
        if self.aggregate(self.assertClassDefined, a3, 'BoardModel'):
            self.aggregate(self.assertFunctionDefined, a3.BoardModel,
                           '__init__', 3)

        if self.aggregate(self.assertClassDefined, a3, 'BoardView'):
            self.aggregate(self.assertFunctionDefined, a3.BoardView,
                           '__init__', 6)
            self.aggregate(self.assertIsSubclass,
                           a3.BoardView,
                           tk.Canvas,
                           tag='BoardView.Canvas')

        if self.aggregate(self.assertClassDefined,
                          a3,
                          'PokemonGame',
                          tag='PokemonGame'):
            self.aggregate(self.assertFunctionDefined, a3.PokemonGame,
                           '__init__', 5)

        if self.aggregate(self.assertDefined, a3, 'TASK_TWO'):
            if self.aggregate(self.assertClassDefined, a3, 'StatusBar'):
                self.aggregate(self.assertIsSubclass, a3.StatusBar, tk.Frame)

            if self.aggregate(self.assertClassDefined, a3, 'ImageBoardView'):
                self.aggregate(self.assertIsSubclass, a3.ImageBoardView,
                               a3.BoardView)

        self.aggregate(self.assertFunctionDefined, a3, 'main', 0)
        self.aggregate_tests()
예제 #2
0
    def test_simple_prediction_defined(self):
        """ test SimplePrediction class and methods defined correctly """
        prediction = AttributeGuesser.get_wrapped_object(self.prediction)
        self.aggregate(self.assertClassDefined,
                       prediction,
                       'SimplePrediction',
                       tag='defined')

        self.aggregate(self.assertIsSubclass,
                       self.event_decision.SimplePrediction,
                       self.event_decision.WeatherPrediction)

        self.aggregate(self.assertFunctionDefined,
                       self.prediction.SimplePrediction, '__init__', 3)
        self.aggregate(self.assertFunctionDefined,
                       self.prediction.SimplePrediction, 'get_number_days', 1)
        self.aggregate(self.assertFunctionDefined,
                       self.prediction.SimplePrediction, 'chance_of_rain', 1)
        self.aggregate(self.assertFunctionDefined,
                       self.prediction.SimplePrediction, 'high_temperature', 1)
        self.aggregate(self.assertFunctionDefined,
                       self.prediction.SimplePrediction, 'low_temperature', 1)
        self.aggregate(self.assertFunctionDefined,
                       self.prediction.SimplePrediction, 'humidity', 1)
        self.aggregate(self.assertFunctionDefined,
                       self.prediction.SimplePrediction, 'cloud_cover', 1)
        self.aggregate(self.assertFunctionDefined,
                       self.prediction.SimplePrediction, 'wind_speed', 1)

        self.aggregate_tests()
예제 #3
0
    def test_doc_strings(self):
        """ test all classes and functions have documentation strings """
        a2 = AttributeGuesser.get_wrapped_object(self.a2)
        ignored = frozenset(('__str__', '__repr__'))
        for func_name, func in inspect.getmembers(
                a2, predicate=inspect.isfunction):
            if not self._is_a2_object(func):
                continue

            if func_name == 'main':
                continue

            self.aggregate(self.assertDocString, func)

        for cls_name, cls in inspect.getmembers(a2, predicate=inspect.isclass):
            if not self._is_a2_object(cls):
                continue

            self.aggregate(self.assertDocString, cls)
            defined = vars(cls)
            for func_name, func in inspect.getmembers(
                    cls, predicate=inspect.isfunction):
                if func_name not in ignored and func_name in defined:
                    self.aggregate(self.assertDocString, func)

        self.aggregate_tests()
예제 #4
0
    def test_doc_strings(self):
        """ test all functions have documentation strings """
        a1 = AttributeGuesser.get_wrapped_object(self.a1)
        for attr_name, _ in inspect.getmembers(a1, predicate=inspect.isfunction):
            self.aggregate(self.assertDocString, a1, attr_name)

        self.aggregate_tests()
예제 #5
0
    def test_functions_defined(self):
        """ test all functions are defined correctly """
        a1 = AttributeGuesser.get_wrapped_object(self.a1)
        for func_name, func in inspect.getmembers(A1, predicate=inspect.isfunction):
            num_params = len(inspect.signature(func).parameters)
            self.aggregate(self.assertFunctionDefined, a1, func_name, num_params, tag=func_name)

        self.aggregate_tests()
예제 #6
0
    def test_classes_defined_correctly(self):
        """ test all specified classes are defined correctly """
        a2 = AttributeGuesser.get_wrapped_object(self.a2)

        card_defined = self.aggregate(self.assertClassDefined, a2, 'Card', tag='Card')
        if card_defined:
            self.aggregate(self.assertFunctionDefined, a2.Card, 'play', 3, tag='Card.play')
            self.aggregate(self.assertFunctionDefined, a2.Card, 'action', 4, tag='Card.action')
            self.aggregate(self.assertFunctionDefined, a2.Card, '__str__', 1, tag='Card.__str__')
            self.aggregate(self.assertFunctionDefined, a2.Card, '__repr__', 1, tag='Card.__repr__')

        if self.aggregate(self.assertClassDefined, a2, 'NumberCard', tag='NumberCard'):
            self.aggregate(self.assertFunctionDefined, a2.NumberCard, 'get_number', 1, tag='NumberCard.get_number')
            if card_defined:
                self.aggregate(self.assertIsSubclass, a2.NumberCard, a2.Card, tag='NumberCard')

        if self.aggregate(self.assertClassDefined, a2, 'CoderCard', tag='CoderCard'):
            self.aggregate(self.assertFunctionDefined, a2.CoderCard, 'get_name', 1, tag='CoderCard.get_name')
            if card_defined:
                self.aggregate(self.assertIsSubclass, a2.CoderCard, a2.Card, tag='CoderCard')

        if self.aggregate(self.assertClassDefined, a2, 'TutorCard', tag='TutorCard'):
            self.aggregate(self.assertFunctionDefined, a2.TutorCard, 'get_name', 1, tag='TutorCard.get_name')
            if card_defined:
                self.aggregate(self.assertIsSubclass, a2.TutorCard, a2.Card, tag='TutorCard')

        if self.aggregate(self.assertClassDefined, a2, 'KeyboardKidnapperCard', tag='KeyboardKidnapperCard'):
            if card_defined:
                self.aggregate(self.assertIsSubclass, a2.KeyboardKidnapperCard, a2.Card, tag='KeyboardKidnapperCard')

        if self.aggregate(self.assertClassDefined, a2, 'AllNighterCard', tag='AllNighterCard'):
            if card_defined:
                self.aggregate(self.assertIsSubclass, a2.AllNighterCard, a2.Card, tag='AllNighterCard')

        if self.aggregate(self.assertClassDefined, a2, 'Deck', tag='Deck'):
            self.aggregate(self.assertFunctionDefined, a2.Deck, 'get_cards', 1, tag='Deck.get_cards')
            self.aggregate(self.assertFunctionDefined, a2.Deck, 'get_card', 2, tag='Deck.get_card')
            self.aggregate(self.assertFunctionDefined, a2.Deck, 'top', 1, tag='Deck.top')
            self.aggregate(self.assertFunctionDefined, a2.Deck, 'remove_card', 2, tag='Deck.remove_card')
            self.aggregate(self.assertFunctionDefined, a2.Deck, 'get_amount', 1, tag='Deck.get_amount')
            self.aggregate(self.assertFunctionDefined, a2.Deck, 'shuffle', 1, tag='Deck.shuffle')
            self.aggregate(self.assertFunctionDefined, a2.Deck, 'pick', 2, tag='Deck.pick')
            self.aggregate(self.assertFunctionDefined, a2.Deck, 'add_card', 2, tag='Deck.add_card')
            self.aggregate(self.assertFunctionDefined, a2.Deck, 'add_cards', 2, tag='Deck.add_cards')
            self.aggregate(self.assertFunctionDefined, a2.Deck, 'copy', 2, tag='Deck.copy')
            self.aggregate(self.assertFunctionDefined, a2.Deck, '__str__', 1, tag='Deck.__str__')
            self.aggregate(self.assertFunctionDefined, a2.Deck, '__repr__', 1, tag='Deck.__repr__')

        if self.aggregate(self.assertClassDefined, a2, 'Player', tag='Player'):
            self.aggregate(self.assertFunctionDefined, a2.Player, 'get_name', 1, tag='Player.get_name')
            self.aggregate(self.assertFunctionDefined, a2.Player, 'get_hand', 1, tag='Player.get_hand')
            self.aggregate(self.assertFunctionDefined, a2.Player, 'get_coders', 1, tag='Player.get_coders')
            self.aggregate(self.assertFunctionDefined, a2.Player, 'has_won', 1, tag='Player.has_won')
            self.aggregate(self.assertFunctionDefined, a2.Player, '__str__', 1, tag='Deck.__str__')
            self.aggregate(self.assertFunctionDefined, a2.Player, '__repr__', 1, tag='Deck.__repr__')

        self.aggregate_tests()
예제 #7
0
    def test_classes_and_functions_defined(self):
        """ test all specified classes and functions defined correctly """
        a2 = AttributeGuesser.get_wrapped_object(self.a2)

        self._aggregate_class_and_functions_defined(a2, Entity)
        self._aggregate_class_and_functions_defined(a2, Wall, 'Entity')
        self._aggregate_class_and_functions_defined(a2, Item, 'Entity')
        self._aggregate_class_and_functions_defined(a2, Key, 'Item')
        self._aggregate_class_and_functions_defined(a2, MoveIncrease, 'Item')
        self._aggregate_class_and_functions_defined(a2, Door, 'Entity')
        self._aggregate_class_and_functions_defined(a2, Player, 'Entity')
        self._aggregate_class_and_functions_defined(a2, GameLogic)
        self._aggregate_class_and_functions_defined(a2, GameApp)

        self.aggregate_tests()
예제 #8
0
    def test_classes_and_functions_defined(self):
        """ test all specified classes and functions defined correctly """
        a2 = AttributeGuesser(self.a2, fail=False)

        self._aggregate_class_and_functions_defined(a2, Tile)
        self._aggregate_class_and_functions_defined(a2, Pipe, Tile)
        self._aggregate_class_and_functions_defined(a2, SpecialPipe, Pipe,
                                                    Tile)
        self._aggregate_class_and_functions_defined(a2, StartPipe, SpecialPipe,
                                                    Pipe, Tile)
        self._aggregate_class_and_functions_defined(a2, EndPipe, SpecialPipe,
                                                    Pipe, Tile)
        self._aggregate_class_and_functions_defined(a2, PipeGame)

        self.aggregate_tests()
예제 #9
0
    def test_doc_strings(self):
        """ test all classes and functions have documentation strings """
        a2 = AttributeGuesser.get_wrapped_object(self.a2)
        for func_name, func in inspect.getmembers(a2, predicate=inspect.isfunction):
            if func_name != 'main':
                self.aggregate(self.assertDocString, func)

        for cls_name, cls in inspect.getmembers(a2, predicate=inspect.isclass):
            self.aggregate(self.assertDocString, cls)
            for func_name, func in inspect.getmembers(cls, predicate=inspect.isfunction):
                if func_name.startswith('__') and func_name.endswith('__') and func_name != '__init__':
                    continue
                self.aggregate(self.assertDocString, func)

        self.aggregate_tests()
예제 #10
0
    def test_event_decision_defined(self):
        """ test EventDecision class and methods defined correctly """
        event_decision = AttributeGuesser.get_wrapped_object(
            self.event_decision)
        self.aggregate(self.assertClassDefined,
                       event_decision,
                       'EventDecision',
                       tag='defined')

        self.aggregate(self.assertFunctionDefined,
                       self.event_decision.EventDecision, '__init__', 3)
        self.aggregate(self.assertFunctionDefined,
                       self.event_decision.EventDecision,
                       '_temperature_factor', 1)
        self.aggregate(self.assertFunctionDefined,
                       self.event_decision.EventDecision, '_rain_factor', 1)
        self.aggregate(self.assertFunctionDefined,
                       self.event_decision.EventDecision, 'advisability', 1)

        self.aggregate_tests()
예제 #11
0
    def test_event_defined(self):
        """ test Event class and methods defined correctly """
        event_decision = AttributeGuesser.get_wrapped_object(
            self.event_decision)
        self.aggregate(self.assertClassDefined,
                       event_decision,
                       'Event',
                       tag='defined')

        self.aggregate(self.assertFunctionDefined, self.event_decision.Event,
                       '__init__', 5)
        self.aggregate(self.assertFunctionDefined, self.event_decision.Event,
                       'get_name', 1)
        self.aggregate(self.assertFunctionDefined, self.event_decision.Event,
                       'get_time', 1)
        self.aggregate(self.assertFunctionDefined, self.event_decision.Event,
                       'get_outdoors', 1)
        self.aggregate(self.assertFunctionDefined, self.event_decision.Event,
                       'get_cover_available', 1)
        self.aggregate(self.assertFunctionDefined, self.event_decision.Event,
                       '__str__', 1)

        self.aggregate_tests()
예제 #12
0
    def test_user_interaction_defined(self):
        """ test UserInteraction class and methods defined correctly """
        event_decision = AttributeGuesser.get_wrapped_object(
            self.event_decision)
        self.aggregate(self.assertClassDefined,
                       event_decision,
                       'UserInteraction',
                       tag='defined')

        self.aggregate(self.assertFunctionDefined,
                       self.event_decision.UserInteraction, '__init__', 1)
        self.aggregate(self.assertFunctionDefined,
                       self.event_decision.UserInteraction,
                       'get_event_details', 1)
        self.aggregate(self.assertFunctionDefined,
                       self.event_decision.UserInteraction,
                       'get_prediction_model', 2)
        self.aggregate(self.assertFunctionDefined,
                       self.event_decision.UserInteraction,
                       'output_advisability', 2)
        self.aggregate(self.assertFunctionDefined,
                       self.event_decision.UserInteraction, 'another_check', 1)

        self.aggregate_tests()
예제 #13
0
    def test_classes_defined(self):
        """ test all specified classes defined """
        a2 = AttributeGuesser(self.a2, fail=False)

        if self.aggregate(self.assertIsNotNone, a2.Card, tag='Card'):
            Card = AttributeGuesser(self.a2.Card, fail=False)

            if self.aggregate(self.assertIsNotNone, Card.play, tag='Card.play'):
                self.aggregate(self.assertFunctionDefined, Card, 'play', 3, tag='Card.play')

            if self.aggregate(self.assertIsNotNone, Card.action, tag='Card.action'):
                self.aggregate(self.assertFunctionDefined, Card, 'action', 4, tag='Card.action')

        if self.aggregate(self.assertIsNotNone, a2.NumberCard, tag='NumberCard'):
            NCard = AttributeGuesser(self.a2.NumberCard, fail=False)

            self.aggregate(self.assertFunctionDefined, a2.NumberCard, '__init__', 2, tag='NumberCard.__init__')
            if self.aggregate(self.assertIsNotNone, NCard.play, tag='NumberCard.get_number'):
                self.aggregate(self.assertFunctionDefined, NCard, 'get_number', 1, tag='NumberCard.get_number')

        if self.aggregate(self.assertIsNotNone, a2.CoderCard, tag='CoderCard'):
            CCard = AttributeGuesser(self.a2.CoderCard, fail=False)

            self.aggregate(self.assertFunctionDefined, a2.CoderCard, '__init__', 2, tag='CoderCard.__init__')
            if self.aggregate(self.assertIsNotNone, CCard.get_name, tag='CoderCard.get_name'):
                self.aggregate(self.assertFunctionDefined, CCard, 'get_name', 1, tag='CoderCard.get_name')

        if self.aggregate(self.assertIsNotNone, a2.TutorCard, tag='TutorCard'):
            TCard = AttributeGuesser(self.a2.TutorCard, fail=False)

            self.aggregate(self.assertFunctionDefined, a2.TutorCard, '__init__', 2, tag='TutorCard.__init__')
            if self.aggregate(self.assertIsNotNone, TCard.get_name, tag='TutorCard.get_name'):
                self.aggregate(self.assertFunctionDefined, TCard, 'get_name', 1, tag='TutorCard.get_name')

        self.aggregate(self.assertIsNotNone, a2.KeyboardKidnapperCard, tag='KeyboardKidnapperCard')
        self.aggregate(self.assertIsNotNone, a2.AllNighterCard, tag='AllNighterCard')

        if self.aggregate(self.assertIsNotNone, a2.Deck, tag='Deck'):
            Deck = AttributeGuesser(self.a2.Deck, fail=False)
            if self.aggregate(self.assertFunctionDefined, Deck, '__init__', 2, tag='Deck.__init__'):
                params = inspect.signature(a2.Deck.__init__).parameters
                if self.aggregate(self.assertEqual, 'starting_cards', list(params)[1],
                                  msg="parameter name should be `starting_cards` in Deck.__init__",
                                  tag='Deck.__init__.starting_cards'):
                    self.aggregate(self.assertIsNone, params['starting_cards'].default,
                                   msg="`starting_cards` should default to `None`",
                                   tag='Deck.__init__.starting_cards=None')

            if self.aggregate(self.assertIsNotNone, Deck.get_cards, tag='Deck.get_cards'):
                self.aggregate(self.assertFunctionDefined, Deck, 'get_cards', 1, tag='Deck.get_cards')

            if self.aggregate(self.assertIsNotNone, Deck.get_card, tag='Deck.get_card'):
                self.aggregate(self.assertFunctionDefined, Deck, 'get_card', 2, tag='Deck.get_card')

            if self.aggregate(self.assertIsNotNone, Deck.top, tag='Deck.top'):
                self.aggregate(self.assertFunctionDefined, Deck, 'top', 1, tag='Deck.top')

            if self.aggregate(self.assertIsNotNone, Deck.remove_card, tag='Deck.remove_card'):
                self.aggregate(self.assertFunctionDefined, Deck, 'remove_card', 2, tag='Deck.remove_card')

            if self.aggregate(self.assertIsNotNone, Deck.get_amount, tag='Deck.get_amount'):
                self.aggregate(self.assertFunctionDefined, Deck, 'get_amount', 1, tag='Deck.get_amount')

            if self.aggregate(self.assertIsNotNone, Deck.shuffle, tag='Deck.shuffle'):
                self.aggregate(self.assertFunctionDefined, Deck, 'shuffle', 1, tag='Deck.shuffle')

            if self.aggregate(self.assertIsNotNone, Deck.pick, tag='Deck.pick'):
                if self.aggregate(self.assertFunctionDefined, Deck, 'pick', 2, tag='Deck.pick'):
                    params = inspect.signature(a2.Deck.pick).parameters
                    if self.aggregate(self.assertEqual, 'amount', list(params)[1],
                                      msg="parameter name should be `amount` in Deck.pick",
                                      tag='Deck.pick.amount'):
                        self.aggregate(self.assertEqual, params['amount'].default, 1,
                                       msg="`starting_cards` should default to `None`",
                                       tag='Deck.pick.amount=1')

            if self.aggregate(self.assertIsNotNone, Deck.add_card, tag='Deck.add_card'):
                self.aggregate(self.assertFunctionDefined, Deck, 'add_card', 2, tag='Deck.add_card')

            if self.aggregate(self.assertIsNotNone, Deck.add_cards, tag='Deck.add_cards'):
                self.aggregate(self.assertFunctionDefined, Deck, 'add_cards', 2, tag='Deck.add_cards')

            if self.aggregate(self.assertIsNotNone, Deck.copy, tag='Deck.copy'):
                self.aggregate(self.assertFunctionDefined, Deck, 'copy', 2, tag='Deck.copy')

        if self.aggregate(self.assertIsNotNone, a2.Player, tag='Player'):
            Player = AttributeGuesser(self.a2.Player, fail=False)
            self.aggregate(self.assertFunctionDefined, Player, '__init__', 2, tag='Player.__init__')

            if self.aggregate(self.assertIsNotNone, Player.get_name, tag='Player.get_name'):
                self.aggregate(self.assertFunctionDefined, Player, 'get_name', 1, tag='Player.get_name')

            if self.aggregate(self.assertIsNotNone, Player.get_hand, tag='Player.get_hand'):
                self.aggregate(self.assertFunctionDefined, Player, 'get_hand', 1, tag='Player.get_hand')

            if self.aggregate(self.assertIsNotNone, Player.get_coders, tag='Player.get_coders'):
                self.aggregate(self.assertFunctionDefined, Player, 'get_coders', 1, tag='Player.get_coders')

            if self.aggregate(self.assertIsNotNone, Player.has_won, tag='Player.has_won'):
                self.aggregate(self.assertFunctionDefined, Player, 'has_won', 1, tag='Player.has_won')

        self.aggregate_tests()