Exemple #1
0
def test_augment_subcommands_subcommand_on_non_existant_fails():
    class Base:
        pass
    with pytest.raises(AttributeError, match=r'apple'):
        with patch('owmeta_core.cli.iter_entry_points') as iter_entry_points, \
                patch('owmeta_core.cli.OWM', new=Base):
            ep = Mock(name='entry_point')
            ep.name = 'apple.pear'
            ep.load.return_value = Mock('sc')
            iter_entry_points.return_value = [ep]
            PCLI._augment_subcommands_from_entry_points()
Exemple #2
0
def test_augment_mult_subsubcommands():
    class Base:
        pass

    class SubCommand:
        def __init__(self, parent):
            pass

    class SubSubCommand1:
        def __init__(self, parent):
            pass

    class SubSubCommand2:
        def __init__(self, parent):
            pass

    with patch('owmeta_core.cli.iter_entry_points') as iter_entry_points, \
            patch('owmeta_core.cli.OWM', new=Base):

        scscep1 = Mock(name='entry_point_peach')
        scscep1.name = 'apple.peach'
        scscep1.load.return_value = SubSubCommand1

        scscep2 = Mock(name='entry_point_pear')
        scscep2.name = 'apple.pear'
        scscep2.load.return_value = SubSubCommand2

        scep = Mock(name='entry_point1')
        scep.name = 'apple'
        scep.load.return_value = SubCommand

        iter_entry_points.return_value = [scscep1, scscep2, scep]
        augmented = PCLI._augment_subcommands_from_entry_points()
        assert isinstance(augmented().apple.pear, SubSubCommand2)
        assert isinstance(augmented().apple.peach, SubSubCommand1)
Exemple #3
0
def test_augment_subcommands_level_ordered_with_two():
    class Base:
        pass

    class SubCommand:
        def __init__(self, parent):
            pass

    class SubSubCommand:
        def __init__(self, parent):
            pass

    with patch('owmeta_core.cli.iter_entry_points') as iter_entry_points, \
            patch('owmeta_core.cli.OWM', new=Base):

        scscep = Mock(name='entry_point')
        scscep.name = 'apple.pear'
        scscep.load.return_value = SubSubCommand

        scep = Mock(name='entry_point')
        scep.name = 'apple'
        scep.load.return_value = SubCommand

        iter_entry_points.return_value = [scscep, scep]
        augmented = PCLI._augment_subcommands_from_entry_points()
        assert isinstance(augmented().apple.pear, SubSubCommand)
Exemple #4
0
def test_augment_subcommands_base_name_matches():
    class Base:
        pass
    with patch('owmeta_core.cli.iter_entry_points') as iter_entry_points, \
            patch('owmeta_core.cli.OWM', new=Base):
        ep = Mock(name='entry_point')
        sc = Mock('subcommand')
        ep.name = 'apple'
        ep.load.return_value = sc
        iter_entry_points.return_value = [ep]
        assert 'Base' == PCLI._augment_subcommands_from_entry_points().__name__
Exemple #5
0
def test_augment_function_subcommand():
    class Base:
        pass

    def subcommand(self):
        pass

    with patch('owmeta_core.cli.iter_entry_points') as iter_entry_points, \
            patch('owmeta_core.cli.OWM', new=Base):
        ep = Mock(name='entry_point')
        ep.name = 'apple'
        ep.load.return_value = subcommand
        iter_entry_points.return_value = [ep]
        augmented = PCLI._augment_subcommands_from_entry_points()
        assert isinstance(augmented().apple, MethodType)
Exemple #6
0
def test_augment_subcommands_subcommand_is_instance():
    class Base:
        pass

    class SubCommand:
        def __init__(self, parent):
            pass
    with patch('owmeta_core.cli.iter_entry_points') as iter_entry_points, \
            patch('owmeta_core.cli.OWM', new=Base):
        ep = Mock(name='entry_point')
        sc = SubCommand
        ep.name = 'apple'
        ep.load.return_value = sc
        iter_entry_points.return_value = [ep]
        assert isinstance(PCLI._augment_subcommands_from_entry_points()().apple, sc)
Exemple #7
0
def test_augment_subcommands_no_entries():
    with patch('owmeta_core.cli.iter_entry_points'), \
            patch('owmeta_core.cli.OWM') as base_cmd:
        assert base_cmd is PCLI._augment_subcommands_from_entry_points()