def setUpClass(cls): slogging.setup("DEBUG", False) parent = Path(__file__).parent.resolve() cls.base_dir_ = tempfile.TemporaryDirectory() cls.base_dir = cls.base_dir_.name cls.jquery_dir = os.path.join(cls.base_dir, "jquery") # str() is needed for Python 3.5 with tarfile.open(str(parent / "jquery.tar.xz")) as tar: tar.extractall(path=cls.base_dir)
def test_setup(self): with captured_output() as (out, err, log): root = logging.getLogger() if len(root.handlers) == 1: root.handlers.insert(0, logging.StreamHandler()) slogging.setup("INFO", False) logger = logging.getLogger("test") logger.info("success") self.assertIn("test", err.getvalue()) self.assertIn("success", err.getvalue()) self.assertIn("1;36", err.getvalue())
def setUpClass(cls): slogging.setup("DEBUG", False) cls.seqs3 = [ ("", "", ""), ("abc", "", ""), ("abc", "abc", ""), ("ab", "abc", "ab"), ("ab", "abc", "abc"), ("abd", "abc", ""), ("abd", "abc", "abg"), ("abd", "abc", "ab"), ("abcd", "abc", ""), ("abcd", "abc", "abcd"), ("abcd", "abc", "axbcd"), ("aabb", "bbcc", "ccdd"), # case with nonoptimal alignment ("bbcc", "ccdd", "aabb"), # case with nonoptimal alignment ("abbc", "aabcc", "abc"), ("abcabcbabac", "abcbabababc", "abcbacabca"), ] cls.seqs3_answers = [ (("", "", ""), ("", "", ""), ("", "", "")), (("abc", "␣␣␣", "␣␣␣"), ("␣␣␣", "␣␣␣", "abc"), ("␣␣␣", "abc", "␣␣␣")), (("abc", "abc", "␣␣␣"), ("abc", "␣␣␣", "abc"), ("␣␣␣", "abc", "abc")), (("ab␣", "abc", "ab␣"), ("abc", "ab␣", "ab␣"), ("ab␣", "ab␣", "abc")), (("ab␣", "abc", "abc"), ("abc", "abc", "ab␣"), ("abc", "ab␣", "abc")), (("abd", "abc", "␣␣␣"), ("abc", "␣␣␣", "abd"), ("␣␣␣", "abd", "abc")), (("abd", "abc", "abg"), ("abc", "abg", "abd"), ("abg", "abd", "abc")), (("abd", "abc", "ab␣"), ("abc", "ab␣", "abd"), ("ab␣", "abd", "abc")), (("abcd", "abc␣", "␣␣␣␣"), ("abc␣", "␣␣␣␣", "abcd"), ("␣␣␣␣", "abcd", "abc␣")), (("abcd", "abc␣", "abcd"), ("abc␣", "abcd", "abcd"), ("abcd", "abcd", "abc␣")), (("a␣bcd", "a␣bc␣", "axbcd"), ("a␣bc␣", "axbcd", "a␣bcd"), ("axbcd", "a␣bcd", "a␣bc␣")), (("aabb␣␣", "␣␣bbcc", "ccdd␣␣"), ("␣␣bbcc␣␣", "␣␣␣␣ccdd", "aabb␣␣␣␣"), ("␣␣ccdd", "␣␣aabb", "bbcc␣␣")), (("␣␣bbcc␣␣", "␣␣␣␣ccdd", "aabb␣␣␣␣"), ("␣␣ccdd", "␣␣aabb", "bbcc␣␣"), ("aabb␣␣", "␣␣bbcc", "ccdd␣␣")), (("␣abbc␣", "aab␣cc", "␣ab␣c␣"), ("aab␣cc", "␣ab␣c␣", "␣abbc␣"), ("␣ab␣c␣", "␣abbc␣", "aab␣cc")), (("abcabcbaba␣␣␣c␣␣␣␣", "␣␣␣abcbabababc␣␣␣␣", "␣␣␣abcba␣␣␣␣␣cabca"), ("␣␣␣abcbabababc␣", "␣␣␣abcbac␣␣abca", "abcabcbaba␣␣␣c␣"), ("␣␣␣abcba␣␣cabca", "abcabcbabac␣␣␣␣", "␣␣␣abcbabababc␣")), ]
def main() -> Any: """Entry point of the utility.""" parser = create_parser() args = parser.parse_args() slogging.setup(args.log_level, args.log_structured, args.log_config) delattr(args, "log_level") delattr(args, "log_structured") delattr(args, "log_config") try: handler = args.handler delattr(args, "handler") except AttributeError: def print_usage(*args, **kwargs): parser.print_usage() handler = print_usage return handler(**vars(args))
def main(): """ Creates all the argparse-rs and invokes the function from set_defaults(). :return: The result of the function from set_defaults(). """ parser = get_parser() args = parser.parse_args() args.log_level = logging._nameToLevel[args.log_level] slogging.setup(args.log_level, False) try: handler = args.handler except AttributeError: def print_usage(_): parser.print_usage() handler = print_usage return handler(args)
def setUpClass(cls): """Prepare environment & train the model for tests.""" slogging.setup("DEBUG", False) # required config cls.bblfsh = "0.0.0.0:9432" cls.language = "javascript" # analyzer parent_loc = Path(__file__).parent.resolve() cls.base_dir_ = tempfile.TemporaryDirectory() cls.base_dir = cls.base_dir_.name # extract repo cls.jquery_dir = os.path.join(cls.base_dir, "jquery") # str() is needed for Python 3.5 with tarfile.open(str(parent_loc / "jquery.tar.xz")) as tar: tar.extractall(path=cls.base_dir) files = glob.glob(os.path.join(cls.jquery_dir, "**", "*"), recursive=True) assert len(files) == 15, len(files) cls.model_path = os.path.join(str(parent_loc), "model_jquery.asdf")
def test_cloner(self, f1, f2): slogging.setup("DEBUG", True) with Capturing() as output: with tempfile.TemporaryDirectory() as tmp_dir: cloner = Cloner(tmp_dir, 1) cloner.clone( ["repo1", "repo2", "repo3", "existing_repo", "downloaded_repo", "failed repo"]) expected_log = [ "started cloning 6 repositories", "repo1 was cloned to", "repo2 was cloned to", "repo3 was cloned to", "existing_repo exists", "downloaded_repo was found at", "failed to clone", "successfully cloned 5/6 repositories", ] output = (json.loads(log_entry)["msg"] for log_entry in output) output = [o for o in output if "| elapsed" not in o and "Using backend" not in o] self.assertEqual(len(output), len(expected_log)) for expected_msg, log_msg in zip(expected_log, output): self.assertEqual(expected_msg, log_msg[:len(expected_msg)]) self.assertEqual(set(downloaded_repos), {"repo1", "repo2", "repo3"})
def setUpClass(cls): slogging.setup("DEBUG", False)
def test_trailing_dot_check_exceptions(self): slogging.setup("INFO", False) logger = logging.getLogger("test182") slogging.trailing_dot_exceptions.add("test182") logger.info("success.")
def test_trailing_dot_check(self): slogging.setup("INFO", False) logger = logging.getLogger("test") with self.assertRaises(AssertionError): logger.info("success.")
def setUp(self): slogging.setup("INFO", False)
def setup(): slogging.setup("INFO", False)
def main(): """ Create all the argparse-rs and invokes the function from set_defaults(). :return: The result of the function from set_defaults(). """ parser = argparse.ArgumentParser() parser.add_argument("--log-level", default="INFO", choices=logging._nameToLevel, help="Logging verbosity.") subparsers = parser.add_subparsers(help="Commands", dest="command") def add_backend_args(p): p.add_argument("--backend", default=None, help="Backend to use.") p.add_argument("--args", default=None, help="Backend's arguments.") def add_index_args(p): p.add_argument("--username", default="", help="Username for the Git repository with the index.") p.add_argument("--password", default="", help="Password for the Git repository with the index.") p.add_argument("--index-repo", default=None, help="Url of the remote Git repository.") p.add_argument( "--cache", default=None, help="Path to the folder where the Git repository will be cached.") p.add_argument( "-s", "--signoff", action="store_true", help= "Add Signed-off-by line by the committer at the end of the commit log " "message. The meaning of a signoff depends on the project, but it " "typically certifies that committer has the rights to submit this work" " under the same license and agrees to a Developer Certificate of " "Origin (see http://developercertificate.org/ for more information)." ) def add_templates_args(p): p.add_argument( "--template-model", default=os.path.join(os.path.dirname(__file__), "templates/model.md.jinja2"), help="Path to the jinja2 template used in the index for the model." ) p.add_argument( "--template-readme", default=os.path.join(os.path.dirname(__file__), "templates/readme.md.jinja2"), help="Path to the jinja2 template used in the index for the readme." ) # ------------------------------------------------------------------------ init_parser = subparsers.add_parser("init", help="Initialize the registry.") init_parser.set_defaults(handler=initialize_registry) init_parser.add_argument("-f", "--force", action="store_true", help="Destructively initialize the registry.") add_index_args(init_parser) add_backend_args(init_parser) # ------------------------------------------------------------------------ dump_parser = subparsers.add_parser( "dump", help="Print a brief information about the model to stdout.") dump_parser.set_defaults(handler=dump_model) dump_parser.add_argument("input", help="Path to the model file, URL or UUID.") add_index_args(dump_parser) add_backend_args(dump_parser) # ------------------------------------------------------------------------ install_parser = subparsers.add_parser( "install", help="Install the environment to run the model.") install_parser.set_defaults(handler=install_environment) install_parser.add_argument("input", help="Path to the model file, URL or UUID.") install_parser.add_argument( "--reproduce", action="store_true", help="Ensure that training the model is possible.") install_parser.add_argument("--pip", nargs="*", help="Additional arguments to pass to pip.") add_index_args(install_parser) add_backend_args(install_parser) # ------------------------------------------------------------------------ publish_parser = subparsers.add_parser( "publish", help="Upload the model and update the registry.") publish_parser.set_defaults(handler=publish_model) publish_parser.add_argument("model", help="The path to the model to publish.") publish_parser.add_argument( "--meta", default=os.path.join(os.path.dirname(__file__), "templates/meta.json"), help= "Path to the JSON file which contains the additional metadata of the model." ) publish_parser.add_argument("-d", "--update-default", action="store_true", help="Set this model as the default one.") publish_parser.add_argument("-f", "--force", action="store_true", help="Overwrite existing models.") add_index_args(publish_parser) add_backend_args(publish_parser) add_templates_args(publish_parser) # ------------------------------------------------------------------------ list_parser = subparsers.add_parser( "list", help="Lists all the models in the registry.") list_parser.set_defaults(handler=list_models) add_index_args(list_parser) # ------------------------------------------------------------------------ delete_parser = subparsers.add_parser("delete", help="Delete a model.") delete_parser.set_defaults(handler=delete_model) delete_parser.add_argument("input", help="UUID of the model to be deleted.") add_index_args(delete_parser) add_backend_args(delete_parser) add_templates_args(delete_parser) # ------------------------------------------------------------------------ args = parser.parse_args() args.log_level = logging._nameToLevel[args.log_level] slogging.setup(args.log_level, False) try: handler = args.handler except AttributeError: def print_usage(_): parser.print_usage() handler = print_usage return handler(args)
def setUpClass(cls): slogging.setup("INFO", False)