def test_find_primer(running_app): from task_widgets.find_in_table.find_primer import FindPrimer task = FindPrimer() task.start() count_correct = 0 for button in task.answer_widget.buttons: text = button.text print text left, right = text.split("=") if "+" in left: first, second = left.split("+") if int(first) + int(second) == int(right): count_correct += 1 else: first, second = left.split("-") if int(first) - int(second) == int(right): count_correct += 1 assert count_correct == task.SIZE for button in task.get_correct_answer_widgets(): assert not task.successful control.press(button) assert task.successful
def test_multiplication(running_app, mode): from task_widgets.calculation.multiplication import MultiplicationCalculation task = MultiplicationCalculation(mode=mode) assert task.intro_hint.title == _("Multi Super Brain") assert task.intro_hint.description == _("Calculate the result!") task.start() if mode == 0: assert task.description_widget.text == u"%s × %s = ?" % (task.first, task.second) assert task.correct_answer == task.first * task.second elif mode == 1: assert task.description_widget.text == u"? × %s = %s" % (task.second, task.result) assert task.correct_answer == task.result / task.second elif mode == 2: assert task.description_widget.text == u"%s × ? = %s" % (task.first, task.result) assert task.correct_answer == task.result / task.first assert any(button.text == unicode(task.correct_answer) for button in task.answer_widget.buttons) correct_button = task.get_correct_answer_widgets()[0] control.press(correct_button) assert task.successful
def test_time_calculation_minutes(running_app): from task_widgets.calculation.time_calculation_minutes import TimeCalculationMinutes first = datetime(2000, 1, 1, hour=1, minute=30) second = timedelta(hours=1, minutes=30) task = TimeCalculationMinutes(first=first, second=second) assert task.intro_hint.title == _("Time Machine: Last Minutes") assert task.intro_hint.description == _( "Add the interval in minutes of the\n right clock to the left one") task.start() assert task.correct_answer == task.result == task.first + task.second assert task.description_widget.left_clock.hour == first.hour assert task.description_widget.left_clock.minute == first.minute assert task.description_widget.right_clock.hour == 1 assert task.description_widget.right_clock.minute == 30 assert any(button.text == task.variant_modifier(task.correct_answer) for button in task.answer_widget.buttons) correct_button = task.get_correct_answer_widgets()[0] control.press(correct_button) assert task.successful
def test_numbers_calculation(running_app, mode): from task_widgets.calculation.numbers_calculation import NumbersCalculation task = NumbersCalculation(mode=mode) assert task.intro_hint.title == _("Super Brain") assert task.intro_hint.description == _("Calculate the result!") task.start() if mode == 0: assert task.description_widget.text == "%s + %s = ?" % (task.first, task.second) assert task.correct_answer == task.first + task.second elif mode == 1: assert task.description_widget.text == "? + %s = %s" % (task.second, task.result) assert task.correct_answer == task.result - task.second elif mode == 2: assert task.description_widget.text == "%s + ? = %s" % (task.first, task.result) assert task.correct_answer == task.result - task.first assert any(button.text == unicode(task.correct_answer) for button in task.answer_widget.buttons) correct_button = task.get_correct_answer_widgets()[0] control.press(correct_button) assert task.successful
def test_base_answer(task, tracker, google_client, mocker, vibrator): from managers.database import database_manager mocker.spy(database_manager, 'add_stat') from task_widgets.calculation.numbers_calculation import NumbersCalculation task = NumbersCalculation() task.start() correct_button = task.get_correct_answer_widgets() incorrect_button = [ button for button in task.answer_widget.buttons if button not in correct_button ][0] control.press(incorrect_button) assert task.mistakes_count == 1 assertions.assert_vibrated(vibrator, 100) correct_button = correct_button[0] control.press(correct_button) assert task.successful assertions.assert_tracker_event_sent(tracker, 'tasks', 'class', label="numbers_calculation") assertions.assert_achievement_incremented(google_client, "general_cognitive") assertions.assert_achievement_incremented(google_client, "sergeant_cognitive") assertions.assert_achievement_incremented(google_client, "major_cognitive") assertions.assert_achievement_incremented(google_client, "lieutenant_cognitive") assertions.assert_achievement_incremented(google_client, "colonel_cognitive") assert database_manager.add_stat.called
def test_reverse_sequence(running_app, task): task.start() assert any( button.text == "[color=#ccccccff]|[/color]".join(task.correct_answer) for button in task.answer_widget.buttons) correct_button = task.get_correct_answer_widgets()[0] control.press(correct_button) assert task.successful
def test_reverse_symbols_sequence(running_app): from task_widgets.reverse_sequence.reverse_symbols import ReverseSymbols task = ReverseSymbols() task.start() assert any(button.text == u"[color=#ccccccff][font=RobotoCondensed]|[/font][/color]".join( task.correct_answer) for button in task.answer_widget.buttons) correct_button = task.get_correct_answer_widgets()[0] control.press(correct_button) assert task.successful
def test_find_in_table_basic(running_app, task): task.start() assert len([ button for button in task.answer_widget.buttons if button.text == unicode(task.correct_answer) ]) == task.SIZE for button in task.get_correct_answer_widgets(): assert not task.successful control.press(button) assert task.successful
def test_tip_ball(running_app): from task_widgets.tip_ball import TipBall, Ball Ball.move_random = lambda *args, **kwargs: None task = TipBall() task.start() for i in range(task.SIZE): assert not task.successful button = task.get_correct_answer_widgets()[0] control.press(button) assert task.successful
def test_white_squares(running_app): from task_widgets.white_squares import WhiteSquares task = WhiteSquares() task.start() for i in range(task.SIZE): assert not task.successful task.show_square(None) button = task.get_correct_answer_widgets()[0] task.hide_square(None) control.press(button) assert task.successful
def test_find_color_dynamic(running_app): from task_widgets.find_in_table_dynamic.find_color_dynamic import FindColorDynamic task = FindColorDynamic() task.start() assert len([ button for button in task.answer_widget.buttons if get_hex_from_color( button.inner_color) == unicode(task.correct_answer) ]) == task.SIZE for button in task.get_correct_answer_widgets(): assert not task.successful control.press(button) assert task.successful
def test_find_figures(running_app): from task_widgets.find_in_table.find_figures import FindFigures task = FindFigures() task.start() assert len([ button for button in task.answer_widget.buttons if task.FIGURES[button.text] == button.icon_src ]) == task.SIZE for button in task.get_correct_answer_widgets(): assert not task.successful control.press(button) assert task.successful
def test_find_in_table_dynamic(running_app, task, vibrator): task.start() assert len([ button for button in task.answer_widget.buttons if button.text == unicode(task.correct_answer) ]) == task.SIZE incorrect_button = task.get_incorrect_answer_widgets()[0] control.press(incorrect_button) assertions.assert_vibrated(vibrator, 100) for button in task.get_correct_answer_widgets(): assert not task.successful control.press(button) assert task.successful
def test_remember_sequence(running_app, task, vibrator): task.start() task.on_timeout() assert task.answer_widget incorrect_button = task.get_incorrect_answer_widgets()[0] control.press(incorrect_button) assertions.assert_vibrated(vibrator, 100) for i in range(task.SIZE): assert not task.successful button = task.get_correct_answer_widgets()[0] assert button.text == unicode(task.correct_answer) control.press(button) assert task.successful
def test_day_stats_diagram_empty_cancel(empty_data, running_app, root_manager): from screens.activity.diagrams import ActivityDayStats import settings diagram = ActivityDayStats() for family in [None, settings.ANALYTICS_FAMILY, settings.ATTENTION_FAMILY, settings.REACTION_FAMILY, settings.MEMORY_FAMILY]: diagram.family = family assert diagram.color == settings.ACTIVITY_COLORS_TRANSPARENT[family] from library_widgets import OkCancelPopup assertions.assert_modal_view_shown(running_app, OkCancelPopup) popup = control.get_popups(running_app)[0] control.press(popup.cancel_button) assert root_manager.current == 'activity' assertions.assert_modal_view_not_shown(running_app, OkCancelPopup)
def test_find_contraversal(running_app): from task_widgets.find_in_table.find_contraveral import FindContraversal task = FindContraversal() task.start() correct_count = 0 for button in task.answer_widget.buttons: # text sample [color=#000000FF]GREEN[/color] match = re.match(r'\[color=(.*?)\](.*?)\[/color\]', button.text) assert match color_hex, color_name = match.groups() if task.COLORS[color_name] == color_hex: correct_count += 1 assert correct_count == task.SIZE for button in task.get_correct_answer_widgets(): assert not task.successful control.press(button) assert task.successful
def test_percents(running_app): from task_widgets.calculation.percents import PercentsCalculation task = PercentsCalculation() assert task.intro_hint.title == _("Super Brain: Percents") assert task.intro_hint.description == _("Calculate the result!") task.start() assert task.description_widget.text == _( u"%(percents)s%% of %(base)s?") % { "percents": task.second, "base": task.first } assert task.correct_answer == (task.first * task.second) / 100. assert any(button.text == task.variant_modifier(task.correct_answer) for button in task.answer_widget.buttons) correct_button = task.get_correct_answer_widgets()[0] control.press(correct_button) assert task.successful