Пример #1
0
                    def test_main(self,
                                  module_path=module_path,
                                  argv=argv,
                                  main=stem in mains,
                                  test=stem in tests):
                        try:
                            script = self._modules[module_path]
                        except KeyError:
                            return print('Import failed for', module_path,
                                         'cannot test main, skipping.')

                        if argv and argv[0] != script:
                            os.system(' '.join(argv))  # FIXME error on this?

                        try:
                            if argv is not None:
                                sys.argv = argv
                            else:
                                sys.argv = self.argv_orig

                            if main:
                                print(tc.ltyellow('MAINING:'), module_path)
                                script.main()
                            elif test:
                                print(tc.ltyellow('TESTING:'), module_path)
                                script.test()  # FIXME mutex and confusion
                        except BaseException as e:
                            if isinstance(e, SystemExit):
                                return  # --help
                            raise e
                        finally:
                            pass
                    def test_main(self,
                                  module_path=module_path,
                                  argv=argv,
                                  main=stem in mains,
                                  test=stem in tests):
                        try:
                            script = self._modules[module_path]
                        except KeyError as e:
                            # we have to raise here becuase we can't delete
                            # the test mfuncs once pytest has loaded them
                            pytest.skip(f'Import failed for {module_path}'
                                        ' cannot test main, skipping.')
                            return

                        if argv and argv[0] != script:
                            os.system(' '.join(argv))  # FIXME error on this?

                        try:
                            if argv is not None:
                                sys.argv = argv
                            else:
                                sys.argv = self.argv_orig

                            if main:
                                print(tc.ltyellow('MAINING:'), module_path)
                                script.main()
                            elif test:
                                print(tc.ltyellow('TESTING:'), module_path)
                                script.test()  # FIXME mutex and confusion
                        except BaseException as e:
                            if isinstance(e, SystemExit):
                                return  # --help
                            raise e
                        finally:
                            post_main()
                def test_file(self,
                              module_path=module_path,
                              stem=stem,
                              fname=fname):
                    try:
                        print(tc.ltyellow('IMPORTING:'), module_path)
                        module = import_module(
                            module_path)  # this returns the submod
                        self._modules[module_path] = module
                        if hasattr(module, '_CHECKOUT_OK'):
                            print(tc.blue('MODULE CHECKOUT:'), module,
                                  module._CHECKOUT_OK)
                            setattr(module, '_CHECKOUT_OK', True)
                            #print(tc.blue('MODULE'), tc.ltyellow('CHECKOUT:'), module, module._CHECKOUT_OK)
                    #except BaseException as e:
                    # FIXME this does not work because collected tests cannot be uncollected
                    #suffix = fname.split('__', 1)[-1]
                    #for mn in dir(self):
                    #if suffix in mn:
                    #old_func = getattr(self, mn)
                    #new_func = pytest.mark.xfail(raises=ModuleNotFoundError)(old_func)
                    #setattr(self, mn, new_func)

                    #raise e
                    finally:
                        post_load()
Пример #4
0
 def sv(asdf, start, ind, warn=False):
     if type(asdf) not in (bool, int) and asdf.startswith('http'):
         for iri, short in scigPrint.shorten.items():
             if iri in asdf:
                 return scigPrint.wrap(asdf.replace(iri, short + ':'),
                                       start, ind)
         print(tc.red('WARNING:'), 'Shorten failed for', tc.ltyellow(asdf))
         return scigPrint.wrap(repr(asdf), start, ind)
     else:
         return scigPrint.wrap(repr(asdf), start, ind)
Пример #5
0
 def test_file(self, module_path=module_path, stem=stem):
     try:
         print(tc.ltyellow('IMPORTING:'), module_path)
         module = import_module(
             module_path)  # this returns the submod
         self._modules[module_path] = module
         if hasattr(module, '_CHECKOUT_OK'):
             print(tc.blue('MODULE CHECKOUT:'), module,
                   module._CHECKOUT_OK)
             setattr(module, '_CHECKOUT_OK', True)
             #print(tc.blue('MODULE'), tc.ltyellow('CHECKOUT:'), module, module._CHECKOUT_OK)
     finally:
         pass
Пример #6
0
 def test_file(self, modpath=modpath):
     print(tc.ltyellow('IMPORTING:'), modpath)
     module = import_module(modpath)
     self._modules[modpath] = module