Best Python code snippet using tox_python
test_config.py
Source:test_config.py
1from papis.config import *2from papis.config import _CONFIGURATION3import os4import sys5import re6import tempfile7import papis.exceptions8def test_default_opener():9 plat = sys.platform10 sys.platform = 'darwin v01'11 assert(get_default_opener() == 'open')12 sys.platform = plat13 osname = os.name14 os.name = 'nt'15 assert(get_default_opener() == 'start')16 os.name = 'posix'17 assert(get_default_opener() == 'xdg-open')18 os.name = osname19def test_get_config_home():20 os.environ['XDG_CONFIG_HOME'] = '/tmp'21 assert get_config_home() == '/tmp'22 del os.environ['XDG_CONFIG_HOME']23 assert re.match(r'.+config', get_config_home()) is not None24def test_get_config_dirs():25 tmpdir = '/tmp'26 os.environ['XDG_CONFIG_HOME'] = tmpdir27 if os.environ.get('XDG_CONFIG_DIRS') is not None:28 del os.environ['XDG_CONFIG_DIRS']29 dirs = get_config_dirs()30 assert os.environ.get('XDG_CONFIG_DIRS') is None31 assert len(dirs) == 232 assert os.path.join('/', 'tmp', 'papis') == dirs[0]33 os.environ['XDG_CONFIG_DIRS'] = '/etc/:/usr/local/etc'34 os.environ['XDG_CONFIG_HOME'] = '~'35 dirs = get_config_dirs()36 assert len(dirs) == 437 assert os.path.abspath('/etc/papis') == os.path.abspath(dirs[0])38 assert os.path.abspath('/usr/local/etc/papis') == os.path.abspath(dirs[1])39 assert (os.path.abspath(os.path.expanduser('~/papis'))40 == os.path.abspath(dirs[2]))41 assert (os.path.abspath(os.path.expanduser('~/.papis'))42 == os.path.abspath(dirs[3]))43def test_get_config_folder():44 os.environ['XDG_CONFIG_HOME'] = tempfile.mkdtemp()45 configpath = os.path.join(os.environ['XDG_CONFIG_HOME'], 'papis')46 if not os.path.exists(configpath):47 os.mkdir(configpath)48 assert get_config_folder() == configpath49def test_get_config_file():50 os.environ['XDG_CONFIG_HOME'] = tempfile.mkdtemp()51 configpath = os.path.join(get_config_folder(), 'config')52 assert configpath == get_config_file()53def test_get_configpy_file():54 os.environ['XDG_CONFIG_HOME'] = tempfile.mkdtemp()55 configpath = os.path.join(get_config_folder(), 'config.py')56 assert configpath == get_configpy_file()57 assert(os.environ['XDG_CONFIG_HOME'] in configpath)58def test_set_config_file():59 configfile = tempfile.mktemp()60 set_config_file(configfile)61 assert get_config_file() == configfile62def test_get_scripts_folder():63 ccfolder = get_config_folder()64 assert os.path.join(ccfolder, 'scripts') == get_scripts_folder()65def test_set():66 set('nonexistenkey', 'rofi')67 assert get('nonexistenkey') == 'rofi'68 set('super_key_', 'adams', section='nonexistent')69 assert get('super_key_', section='nonexistent') == 'adams'70def test_get():71 settings = get_general_settings_name()72 set('test_get', 'value1')73 assert get('test_get') == 'value1'74 assert get('test_get', section=settings) == 'value1'75 set('test_get', 'value42', section=get_lib_name())76 assert 'value42' == get('test_get')77 assert 'value42' == get('test_get', section=get_lib_name())78 assert 'value1' == get('test_get', section=settings)79 set('test_getint', '42')80 assert getint('test_getint') == 4281 assert getint('test_getint', section=settings) == 4282 assert type(getint('test_getint', section=settings)) is int83 set('test_getfloat', '3.14')84 assert getfloat('test_getfloat') == 3.1485 assert getfloat('test_getfloat', section=settings) == 3.1486 assert type(getfloat('test_getfloat', section=settings)) is float87 set('test_getbool', 'True')88 assert getboolean('test_getbool') == True89 assert getboolean('test_getbool', section=settings) == True90 set('test_getbool', 'False')91 assert getboolean('test_getbool') == False92 assert getboolean('test_getbool', section=settings) == False93 try:94 get('_unknown_key')95 except papis.exceptions.DefaultSettingValueMissing:96 assert True97 else:98 assert False99def test_get_configuration():100 settings = get_general_settings_name()101 config = get_configuration()102 assert type(config) is Configuration103 assert settings in config.keys()104 assert id(_CONFIGURATION) == id(config)105def test_get_configuration_2():106 _CONFIGURATION = None107 config = get_configuration()108 assert type(config) is Configuration109def test_merge_configuration_from_path():110 configpath = tempfile.mktemp()111 with open(configpath, "w+") as configfile:112 configfile.write("""113[settings]114some-nice-setting = 42115some-other-setting = mandragora116 """)117 config = get_configuration()118 try:119 get('some-nice-setting')120 except papis.exceptions.DefaultSettingValueMissing:121 assert True122 else:123 assert False124 set('some-nice-setting', 'what-is-the-question')125 assert get('some-nice-setting') == 'what-is-the-question'126 merge_configuration_from_path(configpath, config)127 assert get('some-nice-setting') == '42'128 assert get('some-other-setting') == 'mandragora'129def test_set_lib_from_path():130 lib = tempfile.mkdtemp()131 assert os.path.exists(lib)132 set_lib_from_name(lib)133 assert get_lib_name() == lib134def test_set_lib_from_real_lib():135 libdir = tempfile.mkdtemp()136 libname = 'test-set-lib'137 set('dir', libdir, section=libname)138 assert os.path.exists(libdir)139 set_lib_from_name(libname)140 assert get_lib_name() == libname141def test_reset_configuration():142 set('test_reset_configuration', 'mordor')143 assert get('test_reset_configuration') == 'mordor'144 config = reset_configuration()145 assert type(config) is Configuration146 try:147 get('test_reset_configuration')148 except papis.exceptions.DefaultSettingValueMissing:149 assert True150 else:151 assert False152def test_get_default_settings():153 import collections154 assert(type(get_default_settings()) is dict)155 assert(get_default_settings()['settings']['mvtool'] == 'mv')156def test_register_default_settings():157 papis.config.register_default_settings(158 {'scihub': { 'command': 'open'}}159 )160 assert(papis.config.get('command', section='scihub') == 'open')161 papis.config.set('scihub-command', 'edit')162 assert(papis.config.get('command', section='scihub') == 'edit')163 options = {'settings': { 'hubhub': 42, 'default-library': 'mag' }}164 papis.config.register_default_settings(options)165 assert(papis.config.get('hubhub') == 42)166 assert(papis.config.get('info-name') is not None)167 assert(not papis.config.get('default-library') == 'mag')168 assert(169 papis.config.get_default_settings()['settings']['default-library']170 == 'mag')171def test_get_list():172 papis.config.set('super-key-list', [1,2,3,4])173 assert(papis.config.get('super-key-list') == '[1, 2, 3, 4]')174 assert(papis.config.getlist('super-key-list') == ['1','2','3','4'])175 papis.config.set('super-key-list', ['asdf',2,3,4])176 assert(papis.config.get('super-key-list') == "['asdf', 2, 3, 4]")177 assert(papis.config.getlist('super-key-list') == ['asdf','2','3','4'])178 papis.config.set('super-key-list', ['asdf',2,3,4])179 assert(papis.config.get('super-key-list') == "['asdf', 2, 3, 4]")180 assert(papis.config.getlist('super-key-list') == ['asdf','2','3','4'])181 papis.config.set('super-key-list', "['asdf',2,3,4]")182 assert(papis.config.get('super-key-list') == "['asdf',2,3,4]")183 assert(papis.config.getlist('super-key-list') == ['asdf','2','3','4'])184 papis.config.set('super-key-list', "[asdf,2,3,4]")185 assert(papis.config.get('super-key-list') == "[asdf,2,3,4]")186 try:187 papis.config.getlist('super-key-list') == "[asdf,'2','3','4']"188 except SyntaxError as e:189 assert(190 str(e) == (191 "The key 'super-key-list' must be a valid python "192 "object\n\tname 'asdf' is not defined"193 )194 )195 else:196 assert(False)197 papis.config.set('super-key-list', "2")198 assert(papis.config.get('super-key-list') == "2")199 assert(papis.config.getint('super-key-list') == 2)200 try:201 papis.config.getlist('super-key-list') == "[asdf,2,3,4]"202 except SyntaxError as e:203 assert(204 str(e) == (205 "The key 'super-key-list' must be a valid python list"206 )207 )208 else:...
test_search_parser.py
Source:test_search_parser.py
...30 self.assertEqual(args.getint('myint'), 100)31 self.assertEqual(args.getint('mybadint'), None)32 self.assertEqual(args.getint('notakey'), None)33 self.assertEqual(args.getint('notakey', 8), 8)34 def test_getbool(self):35 self.assertEqual(args.getbool('mybool'), True)36 self.assertEqual(args.getbool('mybadbool'), False)37 self.assertEqual(args.getbool('notakey'), False)38 self.assertEqual(args.getbool('notakey', True), True)39 def test_to_dict(self):40 parser_dict = args.to_dict()41 self.assertEqual(set(parser_dict.keys()), set([42 'text', 'prefix', 'offset', 'limit', 'filters',43 'sorts', 'empties', 'excludes'44 ]))45 self.assertEqual(parser_dict['text'], None)46 self.assertEqual(parser_dict['prefix'], None)47 self.assertEqual(parser_dict['offset'], 5)48 self.assertEqual(parser_dict['limit'], 20)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!