def test_locate_file(): r"""Test file location method.""" # Missing file assert (not tools.locate_file('missing_file.fake')) assert (not tools.locate_file(['missing_file.fake'])) # Single file sdir, spat, sans = make_temp_single() sout = tools.locate_file(spat, verification_func=os.path.isfile) assert (isinstance(sout, (bytes, str))) assert_equal(sout, sans[0]) # Multiple files mdir, mpat, mans = make_temp_multiple() with assert_warns(RuntimeWarning): mout = tools.locate_file([mpat]) assert (isinstance(mout, (bytes, str))) assert_equal(mout, mans[0])
def configure_executable_type(cls, cfg): r"""Add configuration options specific in the executable type before the libraries are configured. Args: cfg (CisConfigParser): Config class that options should be set for. Returns: list: Section, option, description tuples for options that could not be set. """ # TODO: Move clone + compile to install out = super(OSRModelDriver, cls).configure_executable_type(cfg) opt = 'repository' desc = 'The full path to the OpenSimRoot repository.' # if platform._is_win: # pragma: windows # out.append((cls.language, opt, desc)) # return out if (((not cfg.has_option(cls.language, opt)) or (not os.path.isdir(cfg.get(cls.language, opt))))): fname = 'OpenSimRoot' fpath = tools.locate_file(fname) if not fpath: logger.info('Could not locate %s, attempting to clone' % fname) try: fpath = cls.clone_repository() except BaseException as e: # pragma: debug logger.info('Failed to clone from %s. error = %s' % (cls.repository_url, str(e))) out.append((cls.language, opt, desc)) if fpath: logger.info('Located %s: %s' % (fname, fpath)) cfg.set(cls.language, opt, fpath) return out