コード例 #1
0
 def Test_B_remove(self):
     snoop = watch_modules.watch(log=self.log, module_path=working_dir)
     for m in self.module_list:
         snoop.add(m)
     self.log.info("Before remove: %d module%s for %d command%s",
                   len(snoop.modules),
                   '' if len(snoop.modules) == 1 else 's', len(snoop.names),
                   '' if len(snoop.names) == 1 else 's')
     before = len(snoop.names)
     snoop.remove(self.module_list[1])
     self.log.info("After remove: %d module%s for %d command%s",
                   len(snoop.modules),
                   '' if len(snoop.modules) == 1 else 's', len(snoop.names),
                   '' if len(snoop.names) == 1 else 's')
     assert len(snoop.names) == before - 1
コード例 #2
0
    def Test_A_add(self):
        snoop = watch_modules.watch(log=self.log, module_path=working_dir)
        snoop.add(self.test_module)

        names = {}
        for m in snoop.modules:
            for name in snoop.modules[m]:
                if name in names:
                    names[name].append(m)
                else:
                    names[name] = [m]
        for name in names:
            self.log.info("Watching '%s' modules ...", name)
            for m in names[name]:
                self.log.info("    %s", m)
        self.log.info("Found %d modules, %d expected", len(snoop.modules),
                      len(test_modules))
        assert len(snoop.modules) == len(test_modules)
コード例 #3
0
 def Test_C_watch(self):
     snoop = watch_modules.watch(log=self.log, module_path=working_dir)
     snoop.add(self.test_module)
     self.log.info("Watch setup: %d module%s for %d command%s",
                   len(snoop.modules),
                   '' if len(snoop.modules) == 1 else 's', len(snoop.names),
                   '' if len(snoop.names) == 1 else 's')
     touched = False
     pset = poll.poll()
     pset.register(snoop, poll.POLLIN)
     while True:
         try:
             evlist = pset.poll(1000)
         except OSError as e:
             self.log.info("poll() exception -- %s", str(e))
             if e.errno != errno.EINTR:
                 raise e
         if not evlist:
             self.log.info("poll() timeout, will touch")
             snoop.scan()
             with open(self.change_target, 'w') as f:
                 f.write(module_content)
             touched = True
             continue
         if not touched:
             self.log.info("Premature change detected")
             for path in snoop.get():
                 self.log.info('    %s', path)
             continue
         self.log.info('Change detected')
         assert touched
         for name, path, module_list in snoop.get(timeout=0):
             self.log.info('    %s', path)
             assert path == os.path.realpath(self.test_module)
         break
     del pset
     del_fds = support.find_open_fds()
     self.log.info("%d files open after watch: %s", len(del_fds),
                   str(del_fds))
     self.log.info("paths known to watcher: %s",
                   support.known_fds(snoop._watch, log=self.log))