Exemplo n.º 1
0
    def test_hooks_can_inherit(self):
        class Base(object):
            value1 = 0

            @hook()
            def func1(self):
                self.value1 = 1

        class Derive(Base):
            hooks = Base.hooks.copy()
            value2 = 0

            @hook()
            def func2(self):
                self.value2 = 2

        obj = Derive()
        Hooks.exec_hooks(obj)
        self.assertEqual(1, obj.value1)
        self.assertEqual(2, obj.value2)

        obj = Base()
        Hooks.exec_hooks(obj)
        self.assertEqual(1, obj.value1)
        self.assert_(not hasattr(obj, 'value2'))
Exemplo n.º 2
0
    def test_inherit_a_hook_method(self):
        class Base(object):
            value1 = 0
            value2 = 0

            @hook()
            def func1(self):
                self.value1 = 1

            @hook()
            def func2(self):
                self.value2 = 2

        class Derive(Base):
            value3 = 0

            @hook()
            def func3(self):
                self.value3 = 3

            func2 = hook()(Base.func2)

        obj = Derive()
        Hooks.exec_hooks(obj)
        self.assertEqual(0, obj.value1)  # value1 was inherited, but not hooked
        self.assertEqual(2, obj.value2)
        self.assertEqual(3, obj.value3)
Exemplo n.º 3
0
    def test_inherit_hooks_must_not_pollution(self):
        class Base(object):
            value1 = 0

            @hook()
            def func1(self):
                self.value1 = 1

        class DeriveA(Base):
            hooks = Base.hooks.copy()
            value2 = 0

            @hook()
            def func2(self):
                self.value2 = 2

        class DeriveB(Base):
            value3 = 0

            @hook()
            def func3(self):
                self.value3 = 3

        obj = DeriveB()
        Hooks.exec_hooks(obj)
        self.assertEqual(0, obj.value1)  # value1 was inherited, but not hooked
        self.assertEqual(3, obj.value3)
        self.assert_(not hasattr(obj, 'value2'))
Exemplo n.º 4
0
    def test_call_func(self):
        class Base(object):
            value = 0

            @hook()
            def func1(self):
                self.value = 1

        obj = Base()
        Hooks.exec_hooks(obj)
        self.assertEqual(1, obj.value)
Exemplo n.º 5
0
 def __init__(self, config, install_dir):
     AgentLogicBase.__init__(self, config)
     self.dr = WinDataRetriver()
     self.commandHandler = CommandHandlerWin()
     hooks_dir = os.path.join(install_dir, 'hooks')
     self.hooks = Hooks(logging.getLogger('Hooks'), hooks_dir)
     set_bcd_useplatformclock()
Exemplo n.º 6
0
    def __init__(self, config, install_dir):
        AgentLogicBase.__init__(self, config)
        self.dr = WinDataRetriver()
        self.commandHandler = CommandHandlerWin(self.dr)
        hooks_dir = os.path.join(install_dir, 'hooks')
        self.hooks = Hooks(logging.getLogger('Hooks'), hooks_dir)

        if config.getboolean('general', 'apply_timer_configuration'):
            apply_clock_tuning()
Exemplo n.º 7
0
    def test_hooks_does_not_inherit(self):
        class Base(object):
            value1 = 0

            @hook()
            def func1(self):
                self.value1 = 1

        class Derive(Base):
            value2 = 0

            @hook()
            def func2(self):
                self.value2 = 2

        obj = Derive()
        Hooks.exec_hooks(obj)
        self.assertEqual(0, obj.value1)  # value1 was inherited, but not hooked
        self.assertEqual(2, obj.value2)
Exemplo n.º 8
0
def main():
    train_dataset = ImagenetteDataset(training=True)
    val_dataset = ImagenetteDataset(training=False)
    bs = 64
    train_dataloader = DataLoader(train_dataset, shuffle=True, batch_size=bs)
    val_dataloader = DataLoader(val_dataset, shuffle=False, batch_size=bs)

    net = ConvNet(in_ch=3).cuda()
    hooks = Hooks(net)
    optim = torch.optim.SGD(net.parameters(), lr=0.5)
    lossfxn = nn.CrossEntropyLoss()

    for epoch in range(5):
        pbar = tqdm(train_dataloader)
        for batch in pbar:
            optim.zero_grad()
            imgs = batch['image'].cuda()
            labels = batch['label'].cuda()
            preds = net(imgs)

            loss = lossfxn(preds, labels)
            pbar.set_postfix({'Loss': float(loss)})

            loss.backward()
            optim.step()

        hooks.show_me()

        pbar = tqdm(val_dataloader)
        total = 0
        correct = 0
        for batch in pbar:
            imgs = batch['image'].cuda()
            labels = batch['label'].cuda()
            with torch.no_grad():
                preds = net(imgs)

            assert_shapes(labels, ['bs'], preds, ['bs', 10])
            total += labels.numel()
            correct += (labels == torch.argmax(preds, dim=1)).sum().item()

        print(f'Top 1 accuracy is {correct/total}')
Exemplo n.º 9
0
 def __init__(self, config):
     AgentLogicBase.__init__(self, config)
     self.dr = LinuxDataRetriver()
     self.dr.app_list = config.get("general", "applications_list")
     self.dr.ignored_fs = set(config.get("general", "ignored_fs").split())
     self.dr.ignore_zero_size_fs = config.get("general",
                                              "ignore_zero_size_fs")
     self.commandHandler = CommandHandlerLinux(self)
     self.cred_server = CredServer()
     self.hooks = Hooks(logging.getLogger('Hooks'),
                        _GUEST_HOOKS_CONFIG_PATH)
Exemplo n.º 10
0
        def tryToChangeCommitter(self=self):
            from git_tests import FakeGitAccessObject
            fakeShow = \
"""
Monty Cantsin
diff --git a/NEOISM b/NEOISM
new file mode 100644
index 0000000..6666666
"""
            self.git.setAccessResponse(fakeShow)
            head = self.git.getCommit("0"*40)
            other = FakeGitAccessObject()
            fakeShow = \
"""
Dmytri Kleiner
diff --git a/README b/README
new file mode 100644
index 0000000..4337545
"""
            other.setAccessResponse(fakeShow)
            update = other.getCommit("0"*40)
            Hooks.haveMatchingCommitterNames(head, update)
Exemplo n.º 11
0
    def test_register_named_hooks(self):
        class Base(object):
            value1 = 0
            value2 = 0
            value3 = 0

            @hook()
            def func1(self):
                self.value1 = 1

            @hook('foo')
            def func2(self):
                self.value2 = 2

            @hook('bar')
            def func3(self):
                self.value3 = 3

        obj = Base()
        Hooks.exec_hooks(obj)
        self.assertEqual(1, obj.value1)
        self.assertEqual(2, obj.value2)
        self.assertEqual(3, obj.value3)

        obj = Base()
        Hooks.exec_hooks(obj, 'foo')
        self.assertEqual(0, obj.value1)
        self.assertEqual(2, obj.value2)
        self.assertEqual(0, obj.value3)

        obj = Base()
        Hooks.exec_hooks(obj, 'bar')
        self.assertEqual(0, obj.value1)
        self.assertEqual(0, obj.value2)
        self.assertEqual(3, obj.value3)

        obj = Base()
        Hooks.exec_hooks(obj, 'baz')
        self.assertEqual(0, obj.value1)
        self.assertEqual(0, obj.value2)
        self.assertEqual(0, obj.value3)
Exemplo n.º 12
0
    def test_inherit_and_retiming_hook_method(self):
        class Base(object):
            value1 = 0
            value2 = 0

            @hook('foo')
            def func1(self):
                self.value1 = 1

            @hook('foo')
            def func2(self):
                self.value2 = 2

        class Derive(Base):
            value3 = 0

            @hook('bar')
            def func3(self):
                self.value3 = 3

            func2 = hook('bar')(Base.func2)

        obj = Base()
        Hooks.exec_hooks(obj, 'foo')
        self.assertEqual(1, obj.value1)
        self.assertEqual(2, obj.value2)
        self.assert_(not hasattr(obj, 'value3'))

        obj = Derive()
        Hooks.exec_hooks(obj, 'foo')
        self.assertEqual(0, obj.value1)
        self.assertEqual(0, obj.value2)
        self.assertEqual(0, obj.value3)

        obj = Derive()
        Hooks.exec_hooks(obj, 'bar')
        self.assertEqual(0, obj.value1)
        self.assertEqual(2, obj.value2)
        self.assertEqual(3, obj.value3)
Exemplo n.º 13
0
 def __init__(self, plugin):
     ida_idp.IDB_Hooks.__init__(self)
     Hooks.__init__(self, plugin)
Exemplo n.º 14
0
 def __init__(self, plugin):
     ida_kernwin.UI_Hooks.__init__(self)
     Hooks.__init__(self, plugin)
Exemplo n.º 15
0
 def tryToUpdateTag():
     Hooks.update("tags/init","0" * 40, "0" * 40)
Exemplo n.º 16
0
 def tryToUpdateMaster():
     Hooks.update("refs/heads/master","0" * 40, "0" * 40)
Exemplo n.º 17
0
 def testUpdate(self):
     """ Telekommie should allow pushing to a new branch
     """
     self.git.setAccessResponse('Dmytri Kleiner')
     Hooks.update("refs/heads/newbranch","A" * 40, "F" * 40, self.git)