def test_get_interpreters_to_show(): default_interpreters = OrderedDict(( ('hive', { 'name': 'Hive', 'interface': 'hiveserver2', 'type': 'hive', 'is_sql': True, 'options': {}, 'is_catalog': False, 'category': 'editor', 'dialect': 'hive' }), ('spark', { 'name': 'Scala', 'interface': 'livy', 'type': 'spark', 'is_sql': False, 'options': {}, 'is_catalog': False, 'category': 'editor', 'dialect': 'scala' }), ('pig', { 'name': 'Pig', 'interface': 'pig', 'type': 'pig', 'is_sql': False, 'options': {}, 'is_catalog': False, 'category': 'editor', 'dialect': 'pig' }), ('java', { 'name': 'Java', 'interface': 'oozie', 'type': 'java', 'is_sql': False, 'options': {}, 'is_catalog': False, 'category': 'editor', 'dialect': 'java' }) )) expected_interpreters = OrderedDict(( ('java', { 'name': 'Java', 'interface': 'oozie', 'type': 'java', 'is_sql': False, 'options': {}, 'is_catalog': False, 'category': 'editor', 'dialect': 'java' }), ('pig', { 'name': 'Pig', 'interface': 'pig', 'is_sql': False, 'type': 'pig', 'options': {}, 'is_catalog': False, 'category': 'editor', 'dialect': 'pig' }), ('hive', { 'name': 'Hive', 'interface': 'hiveserver2', 'is_sql': True, 'type': 'hive', 'options': {}, 'is_catalog': False, 'category': 'editor', 'dialect': 'hive' }), ('spark', { 'name': 'Scala', 'interface': 'livy', 'type': 'spark', 'is_sql': False, 'options': {}, 'is_catalog': False, 'category': 'editor', 'dialect': 'scala' }) )) try: resets = [INTERPRETERS.set_for_testing(default_interpreters), APP_BLACKLIST.set_for_testing('')] appmanager.DESKTOP_MODULES = [] appmanager.DESKTOP_APPS = None appmanager.load_apps(APP_BLACKLIST.get()) interpreters_shown_on_wheel_unset = get_ordered_interpreters() assert_equal( list(default_interpreters.values()), interpreters_shown_on_wheel_unset, 'get_interpreters_to_show should return the same as get_interpreters when interpreters_shown_on_wheel is unset. expected: %s, actual: %s' % ( list(default_interpreters.values()), interpreters_shown_on_wheel_unset ) ) resets.append(INTERPRETERS_SHOWN_ON_WHEEL.set_for_testing('java,pig')) assert_equal(list(expected_interpreters.values()), get_ordered_interpreters(), 'get_interpreters_to_show did not return interpreters in the correct order expected: %s, actual: %s' % (list(expected_interpreters.values()), get_ordered_interpreters())) finally: for reset in resets: reset() appmanager.DESKTOP_MODULES = [] appmanager.DESKTOP_APPS = None appmanager.load_apps(APP_BLACKLIST.get())
def test_get_ordered_interpreters(): default_interpreters = OrderedDict(( ('hive', { 'name': 'Hive', 'displayName': 'Hive', 'interface': 'hiveserver2', 'type': 'hive', 'is_sql': True, 'options': {}, 'dialect_properties': None, 'is_catalog': False, 'category': 'editor', 'dialect': 'hive' }), ('impala', { 'name': 'Impala', 'displayName': 'Impala', 'interface': 'hiveserver2', 'type': 'impala', 'is_sql': True, 'options': {}, 'dialect_properties': None, 'is_catalog': False, 'category': 'editor', 'dialect': 'impala' }), ('spark', { 'name': 'Scala', 'displayName': 'Scala', 'interface': 'livy', 'type': 'spark', 'is_sql': False, 'options': {}, 'dialect_properties': None, 'is_catalog': False, 'category': 'editor', 'dialect': 'scala' }), ('pig', { 'name': 'Pig', 'displayName': 'Pig', 'interface': 'pig', 'type': 'pig', 'is_sql': False, 'options': {}, 'dialect_properties': None, 'is_catalog': False, 'category': 'editor', 'dialect': 'pig' }), ('java', { 'name': 'Java', 'displayName': 'Java', 'interface': 'oozie', 'type': 'java', 'is_sql': False, 'options': {}, 'dialect_properties': None, 'is_catalog': False, 'category': 'editor', 'dialect': 'java' }) )) try: resets = [APP_BLACKLIST.set_for_testing('')] appmanager.DESKTOP_MODULES = [] appmanager.DESKTOP_APPS = None appmanager.load_apps(APP_BLACKLIST.get()) with patch('notebook.conf.is_cm_managed') as is_cm_managed: with patch('notebook.conf.appmanager.get_apps_dict') as get_apps_dict: with patch('notebook.conf.has_connectors') as has_connectors: get_apps_dict.return_value = {'hive': {}} has_connectors.return_value = False notebook.conf.INTERPRETERS_CACHE = None is_cm_managed.return_value = False # No CM --> Verbatim INTERPRETERS.set_for_testing( OrderedDict(( ('phoenix', { 'name': 'Phoenix', 'interface': 'sqlalchemy', 'dialect': 'phoenix' }),) ) ) assert_equal( [interpreter['dialect'] for interpreter in get_ordered_interpreters()], ['phoenix'] ) assert_equal( # Check twice because of cache [interpreter['dialect'] for interpreter in get_ordered_interpreters()], ['phoenix'] ) is_cm_managed.return_value = True notebook.conf.INTERPRETERS_CACHE = None # CM --> Append [] INTERPRETERS.set_for_testing( OrderedDict(() ) ) assert_equal( [interpreter['dialect'] for interpreter in get_ordered_interpreters()], ['hive'] ) assert_equal( # Check twice [interpreter['dialect'] for interpreter in get_ordered_interpreters()], ['hive'] ) notebook.conf.INTERPRETERS_CACHE = None # CM --> Append [Phoenix] INTERPRETERS.set_for_testing( OrderedDict(( ('phoenix', { 'name': 'Phoenix', 'interface': 'sqlalchemy', 'dialect': 'phoenix' }),) ) ) assert_equal( [interpreter['dialect'] for interpreter in get_ordered_interpreters()], ['hive', 'phoenix'] ) assert_equal( # Check twice [interpreter['dialect'] for interpreter in get_ordered_interpreters()], ['hive', 'phoenix'] ) finally: for reset in resets: reset() appmanager.DESKTOP_MODULES = [] appmanager.DESKTOP_APPS = None appmanager.load_apps(APP_BLACKLIST.get()) notebook.conf.INTERPRETERS_CACHE = None