~canonical-platform-qa/ubuntu-system-tests/qemu-build-snap

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/helpers/ubuntuuitools/_cpo/pickers.py

  • Committer: Tarmac
  • Author(s): Heber Parrucci
  • Date: 2016-11-29 20:19:17 UTC
  • mfrom: (474.4.9 uitoolkit-flake8-fixes)
  • Revision ID: tarmac-20161129201917-u9bq4eg0bvlnv11m
Fixing flake8 complexity issues intruced when removing ubuntu-ui-toolkit dependency.

Approved by platform-qa-bot, Santiago Baldassin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
class DatePicker(_common.CustomProxyObjectBase):
33
33
    """Autopilot helper for the DatePicker component."""
34
34
 
35
 
    @autopilot_logging.log_action(logger.info)  # NOQA
 
35
    @autopilot_logging.log_action(logger.info)
36
36
    def pick_date(self, date):
37
 
        # TODO: reduce complexity to avoid flake8 issues
38
37
        """Pick a date from the date picker.
39
 
 
40
38
        :parameter date: The date to pick.
41
39
        :type date: An object with year, month and day attributes, like
42
40
            python's datetime.date.
43
 
        :raises ubuntuuitoolkit.UiToolsException if the mode of the picker
 
41
        :raises ToolkitException if the mode of the picker
44
42
            doesn't let select a date.
 
43
        """
 
44
        self._assert_valid_date_mode(self.mode)
 
45
        self._select_year(date)
 
46
        self._select_month(date)
 
47
        self._select_day(date)
45
48
 
46
 
        """
47
 
        if not self._is_date_picker():
48
 
            raise _common.UiToolsException(
49
 
                "Can't pick date. The picker mode is: {!r}.".format(self.mode))
 
49
    def _select_year(self, date):
50
50
        if 'Years' in self.mode:
51
51
            self._pick_year(date.year)
52
52
            self.year.wait_for(date.year)
 
53
 
 
54
    def _select_month(self, date):
53
55
        if 'Month' in self.mode:
54
56
            # Python's date object starts at one. The model in the date picker
55
57
            # at 0.
56
58
            self._pick_month(date.month - 1)
57
59
            self.month.wait_for(date.month - 1)
 
60
 
 
61
    def _select_day(self, date):
58
62
        if 'Day' in self.mode:
59
63
            self._pick_day(date.day)
60
64
            self.day.wait_for(date.day)
61
65
 
62
 
    def _is_date_picker(self):
63
 
        mode = self.mode
64
 
        if 'Years' in mode or 'Months' in mode or 'Days' in mode:
65
 
            return True
66
 
        else:
67
 
            return False
 
66
    @staticmethod
 
67
    def _assert_valid_date_mode(mode):
 
68
        if not ('Years' in mode or 'Months' in mode or 'Days' in mode):
 
69
            raise _common.UiToolsException(
 
70
                "Can't pick date. The picker mode is: {!r}.".format(mode))
68
71
 
69
72
    @autopilot_logging.log_action(logger.info)
70
73
    def _pick_year(self, year):
113
116
        # at 0.
114
117
        return datetime.date(self.year, self.month + 1, self.day)
115
118
 
116
 
    @autopilot_logging.log_action(logger.info)  # NOQA
 
119
    @autopilot_logging.log_action(logger.info)
117
120
    def pick_time(self, time):
118
 
        # TODO: reduce complexity to avoid flake8 issues
119
121
        """Pick a time from the date picker.
120
122
 
121
123
        :parameter time: The time to pick.
122
124
        :type time: An object with hour, minute and second attributes, like
123
125
            python's datetime.time.
124
 
        :raises ubuntuuitoolkit.UiToolsException if the mode of the picker
 
126
        :raises ToolkitException if the mode of the picker
125
127
            doesn't let select a time.
126
128
 
127
129
        """
128
 
        if not self._is_time_picker():
129
 
            raise _common.UiToolsException(
130
 
                "Can't pick time. The picker mode is: {!r}.".format(self.mode))
 
130
        self._assert_valid_time_mode(self.mode)
131
131
        # Workaround https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1346669
132
 
        # By setting seconds, then minutes, then hours, erratic behavoir
 
132
        # By setting seconds, then minutes, then hours, erratic behavior
133
133
        # can be dealt with
 
134
        self._select_seconds(time)
 
135
        self._select_minutes(time)
 
136
        self._select_hours(time)
 
137
 
 
138
    def _select_seconds(self, time):
134
139
        if 'Seconds' in self.mode:
135
140
            self._pick_second(time.second)
136
141
            self.seconds.wait_for(time.second)
 
142
 
 
143
    def _select_minutes(self, time):
137
144
        if 'Minutes' in self.mode:
138
145
            self._pick_minute(time.minute)
139
146
            self.minutes.wait_for(time.minute)
 
147
 
 
148
    def _select_hours(self, time):
140
149
        if 'Hours' in self.mode:
141
150
            self._pick_hour(time.hour)
142
151
            self.hours.wait_for(time.hour)
143
152
 
144
 
    def _is_time_picker(self):
145
 
        mode = self.mode
146
 
        if 'Hours' in mode or 'Minutes' in mode or 'Seconds' in mode:
147
 
            return True
148
 
        else:
149
 
            return False
 
153
    @staticmethod
 
154
    def _assert_valid_time_mode(mode):
 
155
        if not ('Hours' in mode or 'Minutes' in mode or 'Seconds' in mode):
 
156
            raise _common.UiToolsException(
 
157
                "Can't pick time. The picker mode is: {!r}.".format(mode))
150
158
 
151
159
    @autopilot_logging.log_action(logger.info)
152
160
    def _pick_hour(self, hour):