def test_find_proj_root_bad(self):
     with tempfile.TemporaryDirectory() as tempdir:
         try:
             hwsuite.find_proj_root(cwd=tempdir)
             self.fail("should have failed")
         except hwsuite.WhereamiException:
             pass
 def test_find_proj_root_child(self):
     with tempfile.TemporaryDirectory() as tempdir:
         hwsuite.init.do_init(tempdir, safety_mode='cautious', hwconfig={})
         subdir = os.path.join(tempdir, "q1")
         os.makedirs(subdir)
         actual = hwsuite.find_proj_root(cwd=subdir)
         self.assertEqual(tempdir, actual)
Example #3
0
def _main(proj_root: str = None):
    if proj_root is None:
        proj_root = hwsuite.find_proj_root()
    if not os.path.isfile(os.path.join(proj_root, hwsuite.CFG_FILENAME)):
        raise ProjectRootRequiredException()
    build(proj_root)
    return 0
Example #4
0
def main():
    parser = ArgumentParser()
    parser.add_argument("prefix", nargs='?', help="prefix")
    hwsuite.add_logging_options(parser)
    parser.add_argument("--project-root", metavar="DIR")
    parser.add_argument("--stage-dir",
                        metavar="DIR",
                        help="destination directory")
    args = parser.parse_args()
    try:
        hwsuite.configure_logging(args)
        proj_root = os.path.abspath(args.project_root
                                    or hwsuite.find_proj_root())
        cfg = hwsuite.get_config(proj_root)
        prefix = args.prefix
        if prefix is None:
            prefix = require_prefix(cfg, proj_root)
        stager = Stager(proj_root)
        num_staged = stager.stage(prefix, args.stage_dir)
    except hwsuite.MessageworthyException as ex:
        print(f"{__name__}: {type(ex).__name__}: {ex}", file=sys.stderr)
        return 1
    if num_staged == 0:
        # warning message already printed by logger
        return 1
    return 0
Example #5
0
def main():
    parser = ArgumentParser()
    parser.add_argument("project_root", nargs='?')
    args = parser.parse_args()
    try:
        proj_root = args.project_root or hwsuite.find_proj_root()
        clean(proj_root)
        return 0
    except hwsuite.MessageworthyException as ex:
        print(f"{__name__}: {type(ex).__name__}: {ex}", file=sys.stderr)
        return 1
def produce_files(subdirs: Optional[List[str]], definitions_filename: str, dest_dirname: str, proj_dir: str=None):
    proj_dir = os.path.abspath(proj_dir or hwsuite.find_proj_root())
    if not subdirs:
        defs_files = find_all_definitions_files(proj_dir, definitions_filename)
    else:
        defs_files = map(lambda d: os.path.join(d, definitions_filename), subdirs)
        defs_files = list(filter(os.path.exists, defs_files))
    nsuccesses = 0
    for defs_file in defs_files:
        try:
            produce_from_defs(defs_file, dest_dirname)
            nsuccesses += 1
        except Exception:
            exc_info = sys.exc_info()
            info = traceback.format_exception(*exc_info)
            _log.debug("exception info:\n%s", "".join(info).strip())
            e = exc_info[1]
            _log.warning("failure to load model and write cases from %s: %s, %s", defs_file, type(e), e)
    _log.debug("test cases generated from %s of %s definitions files", nsuccesses, len(defs_files))
    if nsuccesses == 0:
        _log.error("test case generation did not succeed for any of %s definitions files", len(defs_files))
    return nsuccesses
Example #7
0
def _main_raw(proj_dir=None,
              q_name=None,
              mode=_DEFAULT_MODE,
              includes: Optional[str] = None,
              excludes: Optional[str] = None) -> str:
    """Does the work you want and returns the path of the new directory."""
    proj_dir = os.path.abspath(proj_dir or hwsuite.find_proj_root())
    questioner = Questioner(proj_dir,
                            includes=_parse_cludes(includes),
                            excludes=_parse_cludes(excludes))
    q_name = q_name if q_name is not None else questioner.detect_next_qname()
    if os.path.isabs(q_name):
        raise ValueError(
            "'name' should be basename or relative path, not an absolute path")
    q_dir = os.path.join(proj_dir, q_name)
    if mode == 'replace' and os.path.exists(q_dir):
        shutil.rmtree(q_dir)
    os.makedirs(q_dir, exist_ok=(mode == 'overwrite'))
    questioner.populate(q_dir)
    questioner.config_root_proj(q_name)
    _log.info("%s created", hwsuite.describe_path(q_dir))
    return q_dir
 def test_find_proj_root_standard(self):
     with tempfile.TemporaryDirectory() as tempdir:
         hwsuite.init.do_init(tempdir, safety_mode='cautious', hwconfig={})
         actual = hwsuite.find_proj_root(cwd=tempdir)
         self.assertEqual(tempdir, actual)