def test_mkdirs(self): mkdirs('spam.eggs') self.assertEqual(self._dentries(), []) for _ in range(2): mkdirs('spam/eggs/spam.eggs') self.assertEqual(self._dentries(), [(False, 'spam'), (False, 'spam/eggs')])
def save(self, filename=None, directory=None): """Save the DOT source to file. Ensure the file ends with a newline. Args: filename: Filename for saving the source (defaults to ``name`` + ``'.gv'``) directory: (Sub)directory for source saving and rendering. Returns: The (possibly relative) path of the saved source file. """ if filename is not None: self.filename = filename if directory is not None: self.directory = directory filepath = self.filepath tools.mkdirs(filepath) data = text_type(self.source) with codecs.open(filepath, 'w', encoding=self.encoding) as fd: fd.write(data) if not data.endswith(u'\n'): fd.write(u'\n') return filepath
def _run_batch(opts, **kwargs): input_paths = opts['<input-path>'] or ['.'] output_folder = opts['-O'] log.info("Processing %r --> %r...", input_paths, output_folder) input_paths = file_finder(input_paths) if not input_paths: raise CmdException("No <input-path> found! \n" "\n Try: co2mpas batch <fpath-1>..." "\n or : co2mpas gui" "\n or : co2mpas --help") if not osp.isdir(output_folder): if opts['--force']: from graphviz.tools import mkdirs if not ''.endswith('/'): output_folder = '%s/' % output_folder mkdirs(output_folder) else: raise CmdException("Specify a folder for " "the '-O %s' option!" % output_folder) _init_defaults(opts['--modelconf']) kw = { 'variation': parse_overrides(opts['--override']), 'overwrite_cache': opts['--overwrite-cache'], 'modelconf': opts['--modelconf'] } kw.update(kwargs) from co2mpas.batch import process_folder_files process_folder_files(input_paths, output_folder, **kw)
def test_mkdirs(tmp_path): with utils.as_cwd(tmp_path): mkdirs('spam.eggs') assert list(itertree(str(tmp_path))) == [] for _ in range(2): mkdirs('spam/eggs/spam.eggs') assert list(itertree(str(tmp_path))) == [(False, 'spam'), (False, 'spam/eggs')]
def test_mkdirs(tmpdir): with tmpdir.as_cwd(): mkdirs('spam.eggs') assert list(itertree(str(tmpdir))) == [] for _ in range(2): mkdirs('spam/eggs/spam.eggs') assert list(itertree(str(tmpdir))) == [(False, 'spam'), (False, 'spam/eggs')]
def _cmd_modelconf(opts): output_folder = opts['-O'] if not osp.isdir(output_folder): if opts['--force']: from graphviz.tools import mkdirs if not ''.endswith('/'): output_folder = '%s/' % output_folder mkdirs(output_folder) else: raise CmdException("Specify a folder for " "the '-O %s' option!" % output_folder) import datetime fname = datetime.datetime.now().strftime('%Y%m%d_%H%M%S-conf.yaml') fname = osp.join(output_folder, fname) defaults = _init_defaults(opts['--modelconf']) defaults.dump(fname) log.info('Default model config written into yaml-file(%s)...', fname)
def _run_batch(opts): input_paths = opts['<input-path>'] output_folder = opts['-O'] if opts['--gui']: input_paths = [ _prompt_folder(folder_name='INPUT', fpath=input_paths[-1] if input_paths else None) ] output_folder = _prompt_folder(folder_name='OUTPUT', fpath=output_folder) opts.update(_prompt_options(opts)) log.info("Processing %r --> %r...", input_paths, output_folder) input_paths = file_finder(input_paths) if not input_paths: raise CmdException("No <input-path> found! \n" "\n Try: co2mpas batch <fpath-1>..." "\n or : co2mpas --gui" "\n or : co2mpas --help") if not osp.isdir(output_folder): if opts['--force']: from graphviz.tools import mkdirs if not ''.endswith('/'): output_folder = '%s/' % output_folder mkdirs(output_folder) else: raise CmdException("Specify a folder for " "the '-O %s' option!" % output_folder) from co2mpas.batch import process_folder_files process_folder_files(input_paths, output_folder, with_output_file=not opts['--only-summary'], plot_workflow=opts['--plot-workflow'], output_template=opts['--out-template'], overwrite_cache=opts['--overwrite-cache'], soft_validation=opts['--soft-validation'])
def test_mkdirs_invalid(self): with open('spam.eggs', 'wb'): pass with self.assertRaises(OSError): mkdirs('spam.eggs/spam')
def test_mkdirs_invalid(tmp_path): with utils.as_cwd(tmp_path): (tmp_path / 'spam.eggs').write_bytes(b'') with pytest.raises(OSError): mkdirs('spam.eggs/spam')
def test_file(self): with self.assertRaises(OSError): mkdirs('setup.py/spam')
def test_cwd(self): dirnames = self._dirnames() mkdirs('setup.py') self.assertEqual(self._dirnames(), dirnames)
def test_mkdirs_invalid(tmpdir): with tmpdir.as_cwd(): (tmpdir / 'spam.eggs').write_binary(b'') with pytest.raises(OSError): mkdirs('spam.eggs/spam')
def test_mkdirs_invalid(tmpdir): with tmpdir.as_cwd(): tmpdir.join('spam.eggs').write(b'') with pytest.raises(OSError): mkdirs('spam.eggs/spam')