def test_task11_module3():

    ax_set_title_found = False
    correct_value = False

    try:
        for x in load_ast_tree('budget/BudgetList.py').body:
            if (isinstance(x, ast.FunctionDef) and
                    x.name == 'main'):
                for y in x.body:
                    if (isinstance(y, ast.Expr) and 
                        isinstance(y.value, ast.Call)):
                        if(hasattr(y.value.func, 'value') and
                                y.value.func.value.id == 'ax' and
                                y.value.func.attr == 'set_title'):
                            ax_set_title_found = True
                            call = utils.get_calls_from_child(x)
                            if ('ax:set_title:Your total expenses vs. total budget' in call):
                                correct_value = True


    except Exception as e:
            # print('set_title e = ' + str(e))
            pass

    assert ax_set_title_found, 'Did you call `ax.set_title()`?'
    assert correct_value, 'Did you call `ax.bar()` with the following parameter: `\'Your total expenses vs. total budget\'`?'
def test_task7_module3():

    fig_ax_tuple_found = False
    plt_subplots_call_found = False

    try:
        for x in load_ast_tree('budget/BudgetList.py').body:
            if (isinstance(x, ast.FunctionDef) and
                    x.name == 'main'):
                for y in x.body:
                    if (isinstance(y, ast.Assign) and 
                        isinstance(y.targets[0], ast.Tuple)):
                        if (y.targets[0].elts[0].id == 'fig' and 
                        y.targets[0].elts[1].id == 'ax'):
                            fig_ax_tuple_found = True

                            calls = utils.get_calls_from_child(y)
                            print("calls = " + str(calls))
                            if ('plt:subplots' in calls):
                                plt_subplots_call_found = True

    except Exception as e:
            # print('for print e = ' + str(e))
            pass
    
    assert fig_ax_tuple_found and plt_subplots_call_found, 'Did you call assign a Tuple `fig,ax` to `plt.subplots`?'
def test_task10_module3():

    ax_bar_found = False
    correct_values = False

    try:
        for x in load_ast_tree('budget/BudgetList.py').body:
            if (isinstance(x, ast.FunctionDef) and
                    x.name == 'main'):
                for y in x.body:
                    if (isinstance(y, ast.Expr) and 
                        isinstance(y.value, ast.Call)):
                        if (hasattr(y.value.func, 'value') and
                            y.value.func.value.id == 'ax' and
                            y.value.func.attr == 'bar'):
                            ax_bar_found = True
                            call = utils.get_calls_from_child(x)
                            if ('ax:bar:labels:values:color:green:red:blue' in call):
                                correct_values = True


    except Exception as e:
            # print('ax.bar() e = ' + str(e))
            pass

    assert ax_bar_found, 'Did you call `ax.bar()`?'
    assert correct_values, "Did you call `ax.bar()` with the following parameters: `labels, values, color=['green','red','blue']`?"
def test_task10_module5():

    ax_pie_found = False
    correct_values = False

    try:
        for x in load_ast_tree('budget/ExpenseCategories.py').body:
            if (isinstance(x, ast.FunctionDef) and x.name == 'main'):
                for y in x.body:
                    if (isinstance(y, ast.Expr)
                            and isinstance(y.value, ast.Call)):
                        if (hasattr(y.value.func, 'value')
                                and y.value.func.value.id == 'ax'
                                and y.value.func.attr == 'pie'):
                            ax_pie_found = True
                            call = utils.get_calls_from_child(y)
                            print("call = " + str(call))
                            if ('ax:pie:divided_expenses_sum:labels:labels:autopct:%1.1f%%'
                                    in call):
                                correct_values = True

    except Exception as e:
        print('ax.bar() e = ' + str(e))
        # pass

    assert ax_pie_found, 'Did you call `ax.pie()`?'
    assert correct_values, 'Did you call `ax.pie()` with the following parameters: `divided_expenses_sum, labels=labels, autopct=\'%1.1f%%\'`?'
def test_task5_module2():

    append_def_found = False
    # else body
    sum_over_inc_found = False
    over_append_item_found = False

    try:
        for x in load_ast_tree('budget/BudgetList.py').body:
            if isinstance(x, ast.ClassDef):
                if x.name == 'BudgetList':
                    for y in x.body:
                        if (isinstance(y, ast.FunctionDef)
                                and y.name == 'append'
                                and y.args.args[0].arg == 'self'
                                and y.args.args[1].arg == 'item'):
                            append_def_found = True
                            # print("y.body = " + str(y.body))
                            for z in y.body:
                                if_statements = utils.get_if_statements_from_child(
                                    z)
                                # print("if_statements = " + str(if_statements))
                                if (isinstance(z, ast.If)):
                                    for item in z.orelse:
                                        aug_assign = utils.get_augassignments_from_child(
                                            item)
                                        func_call = utils.get_calls_from_child(
                                            item)
                                        assign = utils.get_assignments_from_child(
                                            item)

                                        if ('self:sum_overages:item'
                                                in aug_assign or
                                                'self:sum_overages:self:sum_overages:item'
                                                in assign):
                                            sum_over_inc_found = True
                                        if ('self:overages:append:item'
                                                in func_call):
                                            over_append_item_found = True
    except Exception as e:
        # print('append e = ' + str(e))
        pass

    assert append_def_found, 'Did you define the method `def append(self, item)`?'
    assert over_append_item_found, 'Inside the else statement, did you call `self.overages.append(item)`?'
    assert sum_over_inc_found, 'Inside the else statement, did you call `self.sum_overages+=item`?'
def test_task11_module2():
    print_call_found = False

    try:
        for x in load_ast_tree('budget/BudgetList.py').body:
            if (isinstance(x, ast.FunctionDef) and x.name == 'main'):
                for y in x.body:
                    if (isinstance(y, ast.Expr)
                            and isinstance(y.value, ast.Call)
                            and hasattr(y.value.func, 'id')
                            and y.value.func.id == 'print'):
                        calls = utils.get_calls_from_child(y)
                        # print("print calls = " + str(calls))
                        if 'print:The count of all expenses: :str:len:myBudgetList' in calls:
                            print_call_found = True

    except Exception as e:
        # print('for_loop e = ' + str(e))
        pass

    assert print_call_found, 'Did you print `\'The count of all expenses: \'` concatenated with `str(len(myBudgetList))`?'
def test_task5_module3():

    for_mybudgetlist_found = False
    print_call_found = False

    try:
        for x in load_ast_tree('budget/BudgetList.py').body:
            if (isinstance(x, ast.FunctionDef) and x.name == 'main'):
                for y in x.body:
                    if (isinstance(y, ast.For)
                            and isinstance(y.iter, ast.Name)
                            and y.iter.id == 'myBudgetList'):
                        for_mybudgetlist_found = True
                        calls = utils.get_calls_from_child(y)
                        print("iterable calls = " + str(calls))
                        if 'print:entry' in calls:
                            print_call_found = True
    except Exception as e:
        # print('for print e = ' + str(e))
        pass

    assert for_mybudgetlist_found, 'Did you create a for loop that iterates `myBudgetList`, with `entry` as the name of the iterator?'
    assert print_call_found, 'Did you call `print(entry)`?'
def test_task9_module2():

    expenses_assign_found = False
    read_expenses_call_found = False

    try:
        for x in load_ast_tree('budget/BudgetList.py').body:
            if (isinstance(x, ast.FunctionDef) and x.name == 'main'):
                for y in x.body:
                    assignments = utils.get_assignments_from_child(y)
                    calls = utils.get_calls_from_child(y)

                    if 'expenses:Expense:Expenses' in assignments:
                        expenses_assign_found = True
                    if 'expenses:read_expenses:data/spending_data.csv' in calls:
                        read_expenses_call_found = True

    except Exception as e:
        # print('next e = ' + str(e))
        pass

    assert expenses_assign_found, 'Did you define an `expenses` variable assigned to `Expense.Expenses()`?'
    assert read_expenses_call_found, 'Did you call `read_expenses(\'data/spending_data.csv\')` on `expenses`?'
def test_task10_module2():

    for_expenses_found = False
    append_call_found = False

    try:
        for x in load_ast_tree('budget/BudgetList.py').body:
            if (isinstance(x, ast.FunctionDef) and x.name == 'main'):
                for y in x.body:
                    if (isinstance(y, ast.For)
                            and isinstance(y.iter, ast.Attribute)
                            and y.iter.value.id == 'expenses'
                            and y.iter.attr == 'list'):
                        for_expenses_found = True
                        calls = utils.get_calls_from_child(y)
                        if 'myBudgetList:append:expense:amount' in calls:
                            append_call_found = True

    except Exception as e:
        # print('for_loop e = ' + str(e))
        pass

    assert for_expenses_found, 'Did you create a for loop that iterates `expenses.list`?'
    assert append_call_found, 'Did you call `append(n.amount)` on `myBudgetList`?'
def test_task4_module2():

    append_def_found = False
    # if (self.sum_expenses+item < self.budget):
    self_found = False
    sum_expenses_found = False
    op_add_found = False
    lt_found = False
    self_budget_found = False

    # if body
    sum_exp_inc_found = False
    exp_append_item_found = False

    try:
        for x in load_ast_tree('budget/BudgetList.py').body:
            if isinstance(x, ast.ClassDef):
                if x.name == 'BudgetList':
                    for y in x.body:
                        if (isinstance(y, ast.FunctionDef)
                                and y.name == 'append'
                                and y.args.args[0].arg == 'self'
                                and y.args.args[1].arg == 'item'):
                            append_def_found = True
                            # print("y.body = " + str(y.body))
                            for z in y.body:
                                if_statements = utils.get_if_statements_from_child(
                                    z)
                                # print("if_statements = " + str(if_statements))
                                if (isinstance(z, ast.If)):
                                    # test = Compare() part
                                    if (z.test.left.left.value.id == 'self'):
                                        self_found = True
                                    if (z.test.left.left.attr == 'sum_expenses'
                                        ):
                                        sum_expenses_found = True
                                    if (isinstance(z.test.left.op, ast.Add)):
                                        op_add_found = True
                                    if (isinstance(z.test.ops[0], ast.Lt)):
                                        lt_found = True
                                    if (z.test.comparators[0].value.id
                                            == 'self'
                                            and z.test.comparators[0].attr
                                            == 'budget'):
                                        self_budget_found = True
                                    # for each in body = Compare() part

                                    for item in z.body:
                                        aug_assign = utils.get_augassignments_from_child(
                                            item)
                                        func_call = utils.get_calls_from_child(
                                            item)

                                        if ('self:sum_expenses:item'
                                                in aug_assign):
                                            sum_exp_inc_found = True
                                        if ('self:expenses:append:item'
                                                in func_call):
                                            exp_append_item_found = True

    except Exception as e:
        # print('append e = ' + str(e))
        pass

    assert append_def_found, 'Did you define the method `def append(self, item)`?'
    assert self_found and sum_expenses_found and op_add_found and lt_found and self_budget_found, 'Add an `if` statement that checks if `self.sum_expenses+item < self.budget`.'
    assert sum_exp_inc_found, 'Inside the if statement, did you call `self.sum_expenses += item`?'
    assert exp_append_item_found, 'Inside the if statement, did you call `self.expenses.append(item)`?'