def test_modifier_filter(): f = ModifierFilter('ModifierFlag::COMMAND_L') s = ''' <modifier_only> ModifierFlag::COMMAND_L </modifier_only> ''' util.assert_xml_equal(f, s) f = ModifierFilter('ModifierFlag::CONTROL_R', type='not') s = ''' <modifier_not> ModifierFlag::CONTROL_R </modifier_not> ''' util.assert_xml_equal(f, s)
def test_inputsource_filter(): f = InputSourceFilter('UKRAINIAN') s = ''' <inputsource_only> UKRAINIAN </inputsource_only> ''' util.assert_xml_equal(f, s) f = InputSourceFilter('SWISS_FRENCH', 'SWISS_GERMAN', type='not') s = ''' <inputsource_not> SWISS_FRENCH, SWISS_GERMAN </inputsource_not> ''' util.assert_xml_equal(f, s)
def test_windownamedef(): d = WindowName('Google_Search', ' - Google Search$', 'Search$') s = ''' <windownamedef> <name>Google_Search</name> <regex> - Google Search$</regex> <regex>Search$</regex> </windownamedef>''' util.assert_xml_equal(d, s)
def test_replacementdef(): d = Replacement('EMACS_IGNORE_APP', 'ECLIPSE', 'EMACS', 'TERMINAL', 'REMOTEDESKTOPCONNECTION', 'VI', 'X11', 'VIRTUALMACHINE', 'TERMINAL', 'SUBLIMETEXT') s = ''' <replacementdef> <replacementname>EMACS_IGNORE_APP</replacementname> <replacementvalue> ECLIPSE, EMACS, TERMINAL, REMOTEDESKTOPCONNECTION, VI, X11, VIRTUALMACHINE, TERMINAL, SUBLIMETEXT </replacementvalue> </replacementdef>''' util.assert_xml_equal(d, s)
def test_basic_filter(): f1 = Filter('GOOGLE_CHROME') s = ''' <only> GOOGLE_CHROME </only>''' util.assert_xml_equal(f1, s) f2 = ReplacementFilter('{{EMACS_IGNORE_APP}}', type='not') s = ''' <not> {{EMACS_IGNORE_APP}} </not>''' util.assert_xml_equal(f2, s) try: f1 + f2 assert(False) except: pass
def test_basic_filter(): f1 = Filter('GOOGLE_CHROME') s = ''' <only> GOOGLE_CHROME </only>''' util.assert_xml_equal(f1, s) f2 = ReplacementFilter('{{EMACS_IGNORE_APP}}', type='not') s = ''' <not> {{EMACS_IGNORE_APP}} </not>''' util.assert_xml_equal(f2, s) try: f1 + f2 assert (False) except: pass
def test_vkopenurldef(): d = VKOpenURL('KeyCode::VK_OPEN_URL_karabiner', 'https://pqrs.org/osx/karabiner/') s = ''' <vkopenurldef> <name>KeyCode::VK_OPEN_URL_karabiner</name> <url>https://pqrs.org/osx/karabiner/</url> </vkopenurldef>''' util.assert_xml_equal(d, s) d = VKOpenURL('KeyCode::VK_OPEN_URL_FINDER', '/Applications/Finder.app', background=True) s = ''' <vkopenurldef> <name>KeyCode::VK_OPEN_URL_FINDER</name> <url type="file">/Applications/Finder.app</url> <background/> </vkopenurldef>''' util.assert_xml_equal(d, s) d = VKOpenURL('KeyCode::VK_OPEN_URL_Calculator', '/Applications/Calculator.app') s = ''' <vkopenurldef> <name>KeyCode::VK_OPEN_URL_Calculator</name> <url type="file">/Applications/Calculator.app</url> </vkopenurldef>''' util.assert_xml_equal(d, s) d = VKOpenURL('KeyCode::VK_OPEN_URL_date_pbcopy', '#! /bin/date | /usr/bin/pbcopy') s = ''' <vkopenurldef> <name>KeyCode::VK_OPEN_URL_date_pbcopy</name> <url type="shell"><![CDATA[/bin/date | /usr/bin/pbcopy]]></url> </vkopenurldef>''' util.assert_xml_equal(d, s)
def test_devicedef(): d = DeviceVendor('HEWLETT_PACKARD', '0x03f0') s = ''' <devicevendordef> <vendorname>HEWLETT_PACKARD</vendorname> <vendorid>0x03f0</vendorid> </devicevendordef>''' util.assert_xml_equal(d, s) d = DeviceProduct('MY_HP_KEYBOARD', '0x0224') s = ''' <deviceproductdef> <productname>MY_HP_KEYBOARD</productname> <productid>0x0224</productid> </deviceproductdef>''' util.assert_xml_equal(d, s)
def test_appdef(): d = App('BILIBILI', 'com.typcn.Bilibili') s = ''' <appdef> <appname>BILIBILI</appname> <equal>com.typcn.Bilibili</equal> </appdef>''' util.assert_xml_equal(d, s) d = App('PQRS', 'org.pqrs.aaa', 'org.pqrs.ccc.', '.local') s = ''' <appdef> <appname>PQRS</appname> <equal>org.pqrs.aaa</equal> <prefix>org.pqrs.ccc.</prefix> <suffix>.local</suffix> </appdef>''' util.assert_xml_equal(d, s)
def test_device_filter(): f = DeviceFilter('DeviceVendor::APPLE_COMPUTER', 'DeviceProduct::ANY') s = ''' <device_only> DeviceVendor::APPLE_COMPUTER, DeviceProduct::ANY </device_only>''' util.assert_xml_equal(f, s) f = DeviceFilter('DeviceVendor::APPLE_COMPUTER', 'DeviceProduct::ANY', 'DeviceVendor::Apple_Bluetooth', 'DeviceProduct::ANY', type='not') s = ''' <device_not> DeviceVendor::APPLE_COMPUTER, DeviceProduct::ANY, DeviceVendor::Apple_Bluetooth, DeviceProduct::ANY </device_not>''' util.assert_xml_equal(f, s)
def test_inputsourcedef(): d = InputSource('AZERTY', 'com.apple.keylayout.ABC-AZERTY', 'com.apple.keylayout.French') s = ''' <inputsourcedef> <name>AZERTY</name> <inputsourceid_equal>com.apple.keylayout.ABC-AZERTY</inputsourceid_equal> <inputsourceid_equal>com.apple.keylayout.French</inputsourceid_equal> </inputsourcedef>''' util.assert_xml_equal(d, s) d = InputSource('CHINESE', 'zh-Hans', 'zh-Hant') s = ''' <inputsourcedef> <name>CHINESE</name> <languagecode>zh-Hans</languagecode> <languagecode>zh-Hant</languagecode> </inputsourcedef>''' util.assert_xml_equal(d, s) d = InputSource('DVORAK', 'com.apple.keylayout.Dvorak.', 'com.apple.keylayout.DVORAK.') s = ''' <inputsourcedef> <name>DVORAK</name> <inputsourceid_prefix>com.apple.keylayout.Dvorak</inputsourceid_prefix> <inputsourceid_prefix>com.apple.keylayout.DVORAK</inputsourceid_prefix> </inputsourcedef>''' util.assert_xml_equal(d, s) d = VKChangeInputSource('TEST_ALL', 'com.example.equal', 'com.example.prefix.', 'en-US') s = ''' <vkchangeinputsourcedef> <name>TEST_ALL</name> <inputsourceid_equal>com.example.equal</inputsourceid_equal> <inputsourceid_prefix>com.example.prefix</inputsourceid_prefix> <languagecode>en-US</languagecode> </vkchangeinputsourcedef>''' util.assert_xml_equal(d, s)
def test_uielementrole(): d = UIElementRole('AXTextField') s = '''<uielementroledef> AXTextField </uielementroledef>''' util.assert_xml_equal(d, s)
def test_uielementrole_filter(): f = UIElementRoleFilter('AXTextField', 'AXTextArea') s = ''' <uielementrole_only> AXTextField, AXTextArea </uielementrole_only> ''' util.assert_xml_equal(f, s)
def test_windowname_filter(): f = WindowNameFilter('Gmail') s = ''' <windowname_only> Gmail </windowname_only> ''' util.assert_xml_equal(f, s)
def test_generator(): query.DefinitionBucket.clear() KEYMAP_ALIAS = { 'flip': 'FlipScrollWheel', } DEFINITIONS = { 'BILIBILI': 'com.typcn.Bilibili', 'DeviceVendor::CHERRY': '0x046a', 'DeviceProduct::3494' : '0x0011', } MAPS = [ ['cmd', 'alt'], ['alt', 'cmd', ['CHERRY', 'BILIBILI', '3494']], ['_flip_', 'flipscrollwheel_vertical', ['!APPLE_COMPUTER', '!ANY']], ] query.update_aliases({'KEYMAP_ALIAS': KEYMAP_ALIAS}) g = Generator(maps=MAPS, definitions=DEFINITIONS) s = ''' <root> <Easy-Karabiner>{version}</Easy-Karabiner> <item> <name>Easy-Karabiner</name> <appdef> <appname>BILIBILI</appname> <equal>com.typcn.Bilibili</equal> </appdef> <deviceproductdef> <productname>3494</productname> <productid>0x0011</productid> </deviceproductdef> <devicevendordef> <vendorname>CHERRY</vendorname> <vendorid>0x046a</vendorid> </devicevendordef> <item> <name>Enable</name> <identifier>private.easy_karabiner</identifier> <block> <autogen> __KeyToKey__ KeyCode::COMMAND_L, KeyCode::OPTION_L</autogen> </block> <block> <device_only> DeviceVendor::CHERRY, DeviceProduct::3494 </device_only> <only>BILIBILI</only> <autogen> __KeyToKey__ KeyCode::OPTION_L, KeyCode::COMMAND_L </autogen> </block> <block> <device_not> DeviceVendor::APPLE_COMPUTER, DeviceProduct::ANY </device_not> <autogen> __FlipScrollWheel__ Option::FLIPSCROLLWHEEL_VERTICAL </autogen> </block> </item> </item> </root> '''.format(version=__version__) util.assert_xml_equal(g, s) # test for reentrant of `BaseXML` methods assert(str(g) == str(g)) query.DefinitionBucket.clear() DEFINITIONS = { 'APP_FINDER': '/Applications/Finder.app', 'Open::Calculator': '/Applications/Calculator.app', } MAPS = [ ['alt', 'cmd', ['fn']], ['ctrl alt F', 'APP_FINDER', ['!ModifierFlag::NONE']], ['cmd', 'alt', ['fn']], ['ctrl shift C', 'Open::Calculator', ['!none']], ] g = Generator(maps=MAPS, definitions=DEFINITIONS) s = ''' <root> <Easy-Karabiner>{version}</Easy-Karabiner> <item> <name>Easy-Karabiner</name> <vkopenurldef> <name>KeyCode::VK_OPEN_URL_APP_FINDER</name> <url type="file">/Applications/Finder.app</url> </vkopenurldef> <vkopenurldef> <name>KeyCode::VK_OPEN_URL_Calculator</name> <url type="file">/Applications/Calculator.app</url> </vkopenurldef> <item> <name>Enable</name> <identifier>private.easy_karabiner</identifier> <block> <modifier_only>ModifierFlag::FN</modifier_only> <autogen> __KeyToKey__ KeyCode::OPTION_L, KeyCode::COMMAND_L </autogen> <autogen> __KeyToKey__ KeyCode::COMMAND_L, KeyCode::OPTION_L </autogen> </block> <block> <modifier_not>ModifierFlag::NONE</modifier_not> <autogen> __KeyToKey__ KeyCode::F, ModifierFlag::CONTROL_L, ModifierFlag::OPTION_L, ModifierFlag::NONE, KeyCode::VK_OPEN_URL_APP_FINDER </autogen> <autogen> __KeyToKey__ KeyCode::C, ModifierFlag::CONTROL_L, ModifierFlag::SHIFT_L, ModifierFlag::NONE, KeyCode::VK_OPEN_URL_Calculator </autogen> </block> </item> </item> </root> '''.format(version=__version__) util.assert_xml_equal(g, s)
def test_generator(): query.DefinitionBucket.clear() KEYMAP_ALIAS = { 'flip': 'FlipScrollWheel', } DEFINITIONS = { 'BILIBILI': 'com.typcn.Bilibili', 'DeviceVendor::CHERRY': '0x046a', 'DeviceProduct::3494': '0x0011', } MAPS = [ ['cmd', 'alt'], ['alt', 'cmd', ['CHERRY', 'BILIBILI', '3494']], ['_flip_', 'flipscrollwheel_vertical', ['!APPLE_COMPUTER', '!ANY']], ] query.update_aliases({'KEYMAP_ALIAS': KEYMAP_ALIAS}) g = Generator(maps=MAPS, definitions=DEFINITIONS) s = ''' <root> <Easy-Karabiner>{version}</Easy-Karabiner> <item> <name>Easy-Karabiner</name> <appdef> <appname>BILIBILI</appname> <equal>com.typcn.Bilibili</equal> </appdef> <deviceproductdef> <productname>3494</productname> <productid>0x0011</productid> </deviceproductdef> <devicevendordef> <vendorname>CHERRY</vendorname> <vendorid>0x046a</vendorid> </devicevendordef> <item> <name>Enable</name> <identifier>private.easy_karabiner</identifier> <block> <autogen> __KeyToKey__ KeyCode::COMMAND_L, KeyCode::OPTION_L</autogen> </block> <block> <device_only> DeviceVendor::CHERRY, DeviceProduct::3494 </device_only> <only>BILIBILI</only> <autogen> __KeyToKey__ KeyCode::OPTION_L, KeyCode::COMMAND_L </autogen> </block> <block> <device_not> DeviceVendor::APPLE_COMPUTER, DeviceProduct::ANY </device_not> <autogen> __FlipScrollWheel__ Option::FLIPSCROLLWHEEL_VERTICAL </autogen> </block> </item> </item> </root> '''.format(version=__version__) util.assert_xml_equal(g, s) # test for reentrant of `BaseXML` methods assert (str(g) == str(g)) query.DefinitionBucket.clear() DEFINITIONS = { 'APP_FINDER': '/Applications/Finder.app', 'Open::Calculator': '/Applications/Calculator.app', } MAPS = [ ['alt', 'cmd', ['fn']], ['ctrl alt F', 'APP_FINDER', ['!ModifierFlag::NONE']], ['cmd', 'alt', ['fn']], ['ctrl shift C', 'Open::Calculator', ['!none']], ] g = Generator(maps=MAPS, definitions=DEFINITIONS) s = ''' <root> <Easy-Karabiner>{version}</Easy-Karabiner> <item> <name>Easy-Karabiner</name> <vkopenurldef> <name>KeyCode::VK_OPEN_URL_APP_FINDER</name> <url type="file">/Applications/Finder.app</url> </vkopenurldef> <vkopenurldef> <name>KeyCode::VK_OPEN_URL_Calculator</name> <url type="file">/Applications/Calculator.app</url> </vkopenurldef> <item> <name>Enable</name> <identifier>private.easy_karabiner</identifier> <block> <modifier_only>ModifierFlag::FN</modifier_only> <autogen> __KeyToKey__ KeyCode::OPTION_L, KeyCode::COMMAND_L </autogen> <autogen> __KeyToKey__ KeyCode::COMMAND_L, KeyCode::OPTION_L </autogen> </block> <block> <modifier_not>ModifierFlag::NONE</modifier_not> <autogen> __KeyToKey__ KeyCode::F, ModifierFlag::CONTROL_L, ModifierFlag::OPTION_L, ModifierFlag::NONE, KeyCode::VK_OPEN_URL_APP_FINDER </autogen> <autogen> __KeyToKey__ KeyCode::C, ModifierFlag::CONTROL_L, ModifierFlag::SHIFT_L, ModifierFlag::NONE, KeyCode::VK_OPEN_URL_Calculator </autogen> </block> </item> </item> </root> '''.format(version=__version__) util.assert_xml_equal(g, s)