def test_update_new_problem(self):
        problem4 = Problem(id=4,
                           RIC=RIC(1, 1, 1),
                           grade=Grade('green', 'easy'),
                           colour='green',
                           sector='tower r',
                           styles=('s', ),
                           set_by='s',
                           set_date=datetime.date(2021, 2, 16),
                           strip_date=None)
        problem5 = Problem(id=4,
                           RIC=RIC(1, 2, 1),
                           grade=Grade('green', 'mid'),
                           colour='green',
                           sector='tower r',
                           styles=('s', ),
                           set_by='s',
                           set_date=datetime.date(2021, 2, 16),
                           strip_date=None)
        self.editor.add_new_problem(problem4)
        self.editor.add_new_problem(problem5)
        problems = self.editor.problems
        problem = self.editor.get_problem_by_id(4)

        self.assertEqual(len(problems), 4)
        self.assertEqual(problem, problem5)
示例#2
0
    def test_from_str(self):
        result = Grade.from_str(' purple hard ')
        grade_2 = Grade.from_str(' Purple hard ')

        self.assertEqual(result.range, 'purple')
        self.assertEqual(result.difficulty, 'hard')
        self.assertEqual(grade_2.range, 'purple')
    def __init__(self):

        self.problems = (Problem(id=1,
                                 RIC=RIC(4, 4, 3),
                                 grade=Grade('red', 'mid'),
                                 colour='red',
                                 sector='arch l',
                                 styles=('toe hook', 'pop'),
                                 set_by='Thara',
                                 set_date=datetime.date(2021, 1, 2),
                                 strip_date=None),
                         Problem(id=2,
                                 RIC=RIC(5, 2, 3),
                                 grade=Grade('black', 'mid'),
                                 colour='orange',
                                 sector='arch l',
                                 styles=('run', 'press'),
                                 set_by='Aaron',
                                 set_date=datetime.date(2021, 2, 2),
                                 strip_date=None),
                         Problem(id=3,
                                 RIC=RIC(1, 1, 1),
                                 grade=Grade('green', 'easy'),
                                 colour='green',
                                 sector='tower r',
                                 styles=('s', ),
                                 set_by='s',
                                 set_date=datetime.date(2021, 2, 16),
                                 strip_date=None))
        self._next_id = 4
    def test_undo_then_backup(self):
        problem4 = Problem(id=4, RIC=RIC(1, 1, 1), grade=Grade('green', 'easy'), colour='green', sector='tower r', styles=('s',), set_by='s', set_date=datetime.date(2021, 2, 16), strip_date=None)
        problem5 = Problem(id=4, RIC=RIC(1, 1, 1), grade=Grade('green', 'easy'), colour='orange', sector='tower r', styles=('s',), set_by='s', set_date=datetime.date(2021, 2, 16), strip_date=None)
        self.editor.add_new_problem(problem4)
        self.history.backup()
        self.history.undo()
        self.editor.add_new_problem(problem5)
        self.history.backup()
        problem  = self.editor.get_problem_by_id(4)

        self.assertEqual(len(self.editor.problems), 4)
        self.assertEqual(self.editor.next_id, 5)
        self.assertEqual(problem.colour, "orange")
    def test_swap_row(self):
        style0 = GradeStyle(Grade('yellow', 'mid'), 1, 4,
                            Colour(142, 255, 255), Colour(0, 0, 0),
                            Colour(197, 240, 255))
        style1 = GradeStyle(Grade('yellow', 'hard'), 0, 1,
                            Colour(91, 212, 255), Colour(0, 0, 0),
                            Colour(142, 225, 255))
        styles = (style0, style1)
        self.parser.set_data(styles)
        setting = self.parser.get_data()
        grade0 = setting.get_grade(0)
        grade1 = setting.get_grade(1)

        self.assertEqual(grade0, Grade('yellow', 'hard'))
        self.assertEqual(grade1, Grade('yellow', 'mid'))
示例#6
0
 def setUp(self):
     self.problem = Problem(2, RIC(1, 2, 3), Grade('purple',
                                                   'mid'), 'purple',
                            'cave l', ['pop', 'layback', 'power'], 'Thara',
                            date.today(), 'on')
     self.builder = ProblemCellDataBuilder(GradeDict(), ColourDict(),
                                           SectorDict())
示例#7
0
class MockFileIO():

    data = tuple([
        Problem(id=12,
                RIC=RIC(1, 1, 1),
                grade=Grade('purple', 'mid'),
                colour='purple',
                sector='mid',
                styles=('pop', ),
                set_by='d',
                set_date=datetime.date(2021, 2, 25),
                strip_date=datetime.date(2021, 2, 26)),
        Problem(id=11,
                RIC=RIC(1, 1, 1),
                grade=Grade('purple', 'mid'),
                colour='red',
                sector='mid',
                styles=('dyno', 'pop'),
                set_by='d',
                set_date=datetime.date(2021, 2, 25),
                strip_date=datetime.date(2021, 2, 26)),
        Problem(id=10,
                RIC=RIC(1, 1, 1),
                grade=Grade('purple', 'mid'),
                colour='purple',
                sector='mid',
                styles=('glide', ),
                set_by='d',
                set_date=datetime.date(2021, 2, 25),
                strip_date=datetime.date(2021, 2, 26)),
        Problem(id=9,
                RIC=RIC(1, 1, 1),
                grade=Grade('purple', 'mid'),
                colour='red',
                sector='front',
                styles=('dyno', ),
                set_by='d',
                set_date=datetime.date(2021, 2, 25),
                strip_date=datetime.date(2021, 2, 26))
    ])

    def get_all_problems(self):
        return self.data

    def filter_problems_by(self, predicate) -> tuple[Problem, ...]:
        return tuple([p for p in self.data if predicate(p)])
示例#8
0
    def from_json(self, data: dict) -> GradeStyle:
        grade = Grade.from_json(data['grade'])
        row = int(data['row'])
        aim = int(data['aim'])
        bg_colour = Colour.from_json(data['bg_colour'])
        text_colour = Colour.from_json(data['text_colour'])
        hover_colour = Colour.from_json(data['hover_colour'])

        return GradeStyle(grade, row, aim, bg_colour, text_colour,
                          hover_colour)
    def test_set_single_data(self):
        # When set_data, it is expected to check for duplicates, and get rid of them.
        # Then set the new data, and lastly check if data.keys() is a list from 0 to n.
        # In this scenario:
        #  - style saved to row "6"
        #  - style to row "0" is deleted due to duplication
        #  - => raise ValueError

        style = GradeStyle(Grade('yellow', 'mid'), 6, 3, Colour(0, 1, 2),
                           Colour(3, 4, 5), Colour(6, 7, 8))
        with self.assertRaises(ValueError):
            self.parser.set_data(style)
 def test_add_incorrect_problem(self):
     problem5 = Problem(id=5,
                        RIC=RIC(1, 1, 1),
                        grade=Grade('green', 'easy'),
                        colour='green',
                        sector='tower r',
                        styles=('s', ),
                        set_by='s',
                        set_date=datetime.date(2021, 2, 16),
                        strip_date=None)
     with self.assertRaises(ValueError):
         self.editor.add_new_problem(problem5)
 def test_add_same_problem(self):
     # can't update the problems from previous set
     problem1 = Problem(id=1,
                        RIC=RIC(1, 1, 1),
                        grade=Grade('green', 'easy'),
                        colour='green',
                        sector='tower r',
                        styles=('s', ),
                        set_by='s',
                        set_date=datetime.date(2021, 2, 16),
                        strip_date=None)
     with self.assertRaises(ValueError):
         self.editor.add_new_problem(problem1)
示例#12
0
    def test_get_risks(self):
        risks = self.viewer.get_risks()
        grades = self.viewer.get_grades()
        colours = list(self.viewer.get_holds())
        colours.sort()
        colours = tuple(colours)

        styles = list(self.viewer.get_styles())
        styles.sort()
        styles = tuple(styles)
        self.assertTupleEqual(risks, (1, ))
        self.assertTupleEqual(grades, (Grade('purple', 'mid'), ))
        self.assertTupleEqual(colours, ('purple', 'red'))
        self.assertTupleEqual(styles, ('dyno', 'glide', 'pop'))
示例#13
0
    def _try_make_problem(self):

        _id = int(self.view.text_id.text())
        _r = int(self.view.dropdown_r.currentText())
        _i = int(self.view.dropdown_i.currentText())
        _c = int(self.view.dropdown_c.currentText())
        ric = RIC(_r, _i, _c)
        grade = Grade.from_str(self.view.text_grade.text())
        colour = self.view.dropdown_hold.currentText()
        sector = self.view.text_sector.text().lower()
        styles = self._get_styles_tuple()
        set_by = self.view.lineedit_set_by.text()
        set_date = date.fromisoformat(self.view.lineedit_set_date.text())
        strip_date = None

        return Problem(_id, ric, grade, colour, sector, styles, set_by,
                       set_date, strip_date)
    def test_delete_problem(self):
        problem4 = Problem(id=4,
                           RIC=RIC(1, 1, 1),
                           grade=Grade('green', 'easy'),
                           colour='green',
                           sector='tower r',
                           styles=('s', ),
                           set_by='s',
                           set_date=datetime.date(2021, 2, 16),
                           strip_date=None)
        self.editor.add_new_problem(problem4)
        self.editor.delete_problem(2)
        self.editor.delete_problem(4)
        result2 = self.editor.get_problem_by_id(2)
        result4 = self.editor.get_problem_by_id(4)

        self.assertEqual(type(result2), Problem)
        self.assertEqual(result4, None)
    def test_strip_problem(self):
        problem4 = Problem(id=4,
                           RIC=RIC(1, 1, 1),
                           grade=Grade('green', 'easy'),
                           colour='green',
                           sector='tower r',
                           styles=('s', ),
                           set_by='s',
                           set_date=datetime.date(2021, 2, 16),
                           strip_date=None)
        self.editor.add_new_problem(problem4)
        self.editor.strip_problem(2, datetime.date.today())
        with self.assertRaises(IndexError):
            self.editor.strip_problem(4, datetime.date.today())
        problems = self.editor.problems
        problem = self.editor.get_problem_by_id(2)

        self.assertEqual(len(problems), 3)
        self.assertEqual(problem, None)
示例#16
0
 def on_item_selected(self, items: list[str]) -> None:
     grades = [Grade.from_str(item) for item in items]
     if len(items) == 0:
         grades = self.viewer.get_grades()
     self.viewer.set_filter_grades(grades)
     self.viewer.filter_problems()