def configure_new_sketch(sketch_name, monitor): """ Create dir and configure boilerplate Params: - sketch_name: name of the sketch (will create a {sketch_name}.py) Opitionals: - monitor: start the monitor command as well Example: $ pyp5js new my_sketch """ files = commands.new_sketch(sketch_name) cprint.ok(f"Your sketch was created!") if not monitor: cprint.ok(f"Please, open and edit the file {files.sketch_py} to draw. When you're ready to see your results, just run:") cmd = f"\t pyp5js transcrypt {sketch_name}" cprint.ok(cmd) cprint.ok(f"And open file://{files.index_html.absolute()} on your browser to see yor results!") else: cprint.ok(f"Please, open and edit the file {sketch_py} to draw.") cprint.ok(f"And open file://{files.index_html.absolute()} on your browser to see yor results!") commands.monitor_sketch(sketch_name)
def configure_new_sketch(sketch_name, sketch_dir, monitor): """ Create dir and configure boilerplate Params: - sketch_name: name of the sketch (will create a {sketch_name}.py) Opitionals: - sketch_dir: directory to save the sketch (defaults to {sketch_name}) Example: $ pyp5js new my_sketch """ sketch_py, index_html = commands.new_sketch(sketch_name, sketch_dir) cprint.ok(f"Your sketch was created!") if not monitor: cprint.ok( f"Please, open and edit the file {sketch_py} to draw. When you're ready to see your results, just run:" ) cmd = f"\t pyp5js transcrypt {sketch_name}" if sketch_dir: cmd += f" --sketch-dir {sketch_dir}" cprint.ok(cmd) cprint.ok( f"And open file://{index_html.absolute()} on your browser to see yor results!" ) else: cprint.ok(f"Please, open and edit the file {sketch_py} to draw.") cprint.ok( f"And open file://{index_html.absolute()} on your browser to see yor results!" ) commands.monitor_sketch(sketch_name, sketch_dir)
def configure_new_sketch(sketch_name, monitor, interpreter, template, cdn): """ Create dir and configure boilerplate - Example:\n $ pyp5js new my_sketch -i pyodide """ files = commands.new_sketch(sketch_name, interpreter, template_file=template, use_cdn=cdn) cprint.ok(f"Your sketch was created!") if not monitor: cprint.ok( f"Please, open and edit the file {files.sketch_py} to draw. When you're ready to see your results, just run:" ) cmd = f"\t pyp5js compile {sketch_name}" cprint.ok(cmd) cprint.ok( f"And open file://{files.index_html.absolute()} on your browser to see yor results!" ) else: cprint.ok(f"Please, open and edit the file {files.sketch_py} to draw.") cprint.ok( f"And open file://{files.index_html.absolute()} on your browser to see yor results!" ) commands.monitor_sketch(sketch_name)
def test_monitor_sketch_error_if_sketch_does_not_exist(MockedFiles): files = Mock(spec=Pyp5jsSketchFiles) files.check_sketch_exists.return_value = False MockedFiles.return_value = files with patch('pyp5js.commands.monitor_sketch_service') as monitor: with pytest.raises(SystemExit): commands.monitor_sketch(sketch_name='foo', sketch_dir='bar')
def test_monitor_sketch(MockedFiles): files = Mock(spec=Pyp5jsSketchFiles) files.check_sketch_exists.return_value = True MockedFiles.return_value = files with patch('pyp5js.commands.monitor_sketch_service') as monitor: commands.monitor_sketch(sketch_name='foo', sketch_dir='bar') MockedFiles.assert_called_once_with('bar', 'foo') monitor.assert_called_once_with(files)
def monitor_sketch(sketch_name): """ Command to generate keep watching a sketch's dir and, after any change, it'll automatically generate the JS files as in pyp5js transcrypt command Params: - sketch_name: name of the sketch Example: $ pyp5js monitor my_sketch """ commands.monitor_sketch(sketch_name)
def monitor_sketch(sketch_name, sketch_dir): """ Command to generate keep watching a sketch's dir and, after any change, it'll automatically generate the JS files as in pyp5js transcrypt command Params: - sketch_name: name of the sketch Opitionals - sketch_dir: sketch's directory (defaults to ./{sketch_name}) """ commands.monitor_sketch(sketch_name, sketch_dir)
def test_monitor_sketch_error_if_invalid_name(files): with patch('pyp5js.commands.monitor_sketch_service') as monitor: with pytest.raises(InvalidName): commands.monitor_sketch('1234foo') assert not monitor.called
def test_monitor_sketch_error_if_sketch_does_not_exist(files): with patch('pyp5js.commands.monitor_sketch_service') as monitor: with pytest.raises(PythonSketchDoesNotExist): commands.monitor_sketch('foo') assert not monitor.called
def test_monitor_sketch(files): files.sketch_py.touch() with patch('pyp5js.commands.monitor_sketch_service') as monitor: commands.monitor_sketch('foo') monitor.assert_called_once_with(files)
def monitor_sketch(sketch_name): """ Command to generate keep watching a sketch's dir and, after any change, it'll automatically generate the JS files as in pyp5js transcrypt command """ commands.monitor_sketch(sketch_name)