~veebers/autopilot/fix_1178014

« back to all changes in this revision

Viewing changes to tests/test_compiz_key_translate.py

  • Committer: Thomi Richards
  • Date: 2012-05-06 22:45:27 UTC
  • Revision ID: thomi.richards@canonical.com-20120506224527-xh6wixqiw0rarkmh
Imported code from unity.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
# Copyright 2012 Canonical
 
3
# Author: Thomi Richards
 
4
#
 
5
# This program is free software: you can redistribute it and/or modify it
 
6
# under the terms of the GNU General Public License version 3, as published
 
7
# by the Free Software Foundation.
 
8
 
 
9
from testscenarios import TestWithScenarios
 
10
from testtools import TestCase
 
11
from testtools.matchers import raises, Equals
 
12
 
 
13
from autopilot.keybindings import _translate_compiz_keystroke_string as translate_func
 
14
 
 
15
class KeyTranslateArgumentTests(TestWithScenarios, TestCase):
 
16
    """Tests that the compizconfig keycode translation routes work as advertised."""
 
17
 
 
18
    scenarios = [
 
19
        ('bool', {'input': True}),
 
20
        ('int', {'input': 42}),
 
21
        ('float', {'input': 0.321}),
 
22
        ('none', {'input': None}),
 
23
    ]
 
24
 
 
25
    def test_requires_string_instance(self):
 
26
        """Function must raise TypeError unless given an instance of basestring."""
 
27
        self.assertThat(lambda: translate_func(self.input), raises(TypeError))
 
28
 
 
29
 
 
30
class TranslationTests(TestWithScenarios, TestCase):
 
31
    """Test that we get the result we expect, with the given input."""
 
32
 
 
33
    scenarios = [
 
34
        ('empty string', dict(input='', expected='')),
 
35
        ('single simpe letter', dict(input='a', expected='a')),
 
36
        ('trailing space', dict(input='d   ', expected='d')),
 
37
        ('only whitespace', dict(input='\t\n   ', expected='')),
 
38
        ('special key: Ctrl', dict(input='<Control>', expected='Ctrl')),
 
39
        ('special key: Primary', dict(input='<Primary>', expected='Ctrl')),
 
40
        ('special key: Alt', dict(input='<Alt>', expected='Alt')),
 
41
        ('special key: Shift', dict(input='<Shift>', expected='Shift')),
 
42
        ('direction key up', dict(input='Up', expected='Up')),
 
43
        ('direction key down', dict(input='Down', expected='Down')),
 
44
        ('direction key left', dict(input='Left', expected='Left')),
 
45
        ('direction key right', dict(input='Right', expected='Right')),
 
46
        ('Ctrl+a', dict(input='<Control>a', expected='Ctrl+a')),
 
47
        ('Primary+a', dict(input='<Control>a', expected='Ctrl+a')),
 
48
        ('Shift+s', dict(input='<Shift>s', expected='Shift+s')),
 
49
        ('Alt+d', dict(input='<Alt>d', expected='Alt+d')),
 
50
        ('Super+w', dict(input='<Super>w', expected='Super+w')),
 
51
        ('Ctrl+Up', dict(input='<Control>Up', expected='Ctrl+Up')),
 
52
        ('Primary+Down', dict(input='<Control>Down', expected='Ctrl+Down')),
 
53
        ('Alt+Left', dict(input='<Alt>Left', expected='Alt+Left')),
 
54
        ('Shift+F3', dict(input='<Shift>F3', expected='Shift+F3')),
 
55
        ('duplicate keys Ctrl+Ctrl', dict(input='<Control><Control>', expected='Ctrl')),
 
56
        ('duplicate keys Ctrl+Primary', dict(input='<Control><Primary>', expected='Ctrl')),
 
57
        ('duplicate keys Ctrl+Primary', dict(input='<Primary><Control>', expected='Ctrl')),
 
58
        ('duplicate keys Alt+Alt', dict(input='<Alt><Alt>', expected='Alt')),
 
59
        ('duplicate keys Ctrl+Primary+left', dict(input='<Control><Primary>Left', expected='Ctrl+Left')),
 
60
        ('first key wins', dict(input='<Control><Alt>Down<Alt>', expected='Ctrl+Alt+Down')),
 
61
        ('Getting silly now', dict(input='<Control><Primary><Shift><Shift><Alt>Left', expected='Ctrl+Shift+Alt+Left')),
 
62
    ]
 
63
 
 
64
    def test_translation(self):
 
65
        self.assertThat(translate_func(self.input), Equals(self.expected))
 
66
 
 
67