Exemplo n.º 1
0
 def replaced_stdin_objects_dont_explode(self, mock_sys):
     # Replace sys.stdin with an object lacking .isatty(), which
     # normally causes an AttributeError unless we are being careful.
     mock_sys.stdin = object()
     # Test. If bug is present, this will error.
     runner = Local(Context())
     eq_(runner.should_use_pty(pty=True, fallback=True), False)
Exemplo n.º 2
0
 def replaced_stdin_objects_dont_explode(self, mock_sys):
     # Replace sys.stdin with an object lacking .fileno(), which
     # normally causes an AttributeError unless we are being careful.
     mock_sys.stdin = object()
     # Test. If bug is present, this will error.
     runner = Local(Context())
     eq_(runner.should_use_pty(pty=True, fallback=True), False)
Exemplo n.º 3
0
def agent(pytestconfig):

    agent_cli = str(Path(pytestconfig.rootdir) / "arduino-create-agent")
    env = {
        # "ARDUINO_DATA_DIR": data_dir,
        # "ARDUINO_DOWNLOADS_DIR": downloads_dir,
        # "ARDUINO_SKETCHBOOK_DIR": data_dir,
    }
    run_context = Context()

    runner = Local(run_context)  # execute a command on the local filesystem

    cd_command = "cd"
    with run_context.prefix(f'{cd_command} ..'):
        runner.run(agent_cli,
                   echo=True,
                   hide=True,
                   warn=True,
                   env=env,
                   asynchronous=True)

        # we give some time to the agent to start and listen to
        # incoming requests
        time.sleep(.5)

        # we block here until the test function using this fixture has returned
        yield runner

    # Kill the runner's process as we finished our test (platform dependent)
    os_signal = signal.SIGTERM
    if platform.system() != "Windows":
        os_signal = signal.SIGKILL
    os.kill(runner.process.pid, os_signal)
Exemplo n.º 4
0
def daemon_runner(pytestconfig, data_dir, downloads_dir, working_dir):
    """
    Provide an invoke's `Local` object that has started the arduino-cli in daemon mode.
    This way is simple to start and kill the daemon when the test is finished
    via the kill() function

    Useful reference:
        http://docs.pyinvoke.org/en/1.4/api/runners.html#invoke.runners.Local
        http://docs.pyinvoke.org/en/1.4/api/runners.html
    """
    cli_full_line = os.path.join(str(pytestconfig.rootdir), "..", "arduino-cli daemon")
    env = {
        "ARDUINO_DATA_DIR": data_dir,
        "ARDUINO_DOWNLOADS_DIR": downloads_dir,
        "ARDUINO_SKETCHBOOK_DIR": data_dir,
    }
    os.makedirs(os.path.join(data_dir, "packages"))
    run_context = Context()
    run_context.cd(working_dir)
    # Local Class is the implementation of a Runner abstract class
    runner = Local(run_context)
    runner.run(cli_full_line, echo=False, hide=True, warn=True, env=env, asynchronous=True)

    # we block here until the test function using this fixture has returned
    yield runner

    # Kill the runner's process as we finished our test (platform dependent)
    os_signal = signal.SIGTERM
    if platform.system() != "Windows":
        os_signal = signal.SIGKILL
    os.kill(runner.process.pid, os_signal)
Exemplo n.º 5
0
def daemon_runner(pytestconfig, data_dir, downloads_dir, working_dir):
    """
    Provide an invoke's `Local` object that has started the arduino-cli in daemon mode.
    This way is simple to start and kill the daemon when the test is finished
    via the kill() function

    Useful reference:
        http://docs.pyinvoke.org/en/1.4/api/runners.html#invoke.runners.Local
        http://docs.pyinvoke.org/en/1.4/api/runners.html
    """
    cli_full_line = str(
        Path(pytestconfig.rootdir).parent / "arduino-cli daemon")
    env = {
        "ARDUINO_DATA_DIR": data_dir,
        "ARDUINO_DOWNLOADS_DIR": downloads_dir,
        "ARDUINO_SKETCHBOOK_DIR": data_dir,
    }
    (Path(data_dir) / "packages").mkdir()
    run_context = Context()
    # It might happen that we need to change directories between drives on Windows,
    # in that case the "/d" flag must be used otherwise directory wouldn't change
    cd_command = "cd"
    if platform.system() == "Windows":
        cd_command += " /d"
    # Context.cd() is not used since it doesn't work correctly on Windows.
    # It escapes spaces in the path using "\ " but it doesn't always work,
    # wrapping the path in quotation marks is the safest approach
    run_context.prefix(f'{cd_command} "{working_dir}"')
    # Local Class is the implementation of a Runner abstract class
    runner = Local(run_context)
    runner.run(cli_full_line,
               echo=False,
               hide=True,
               warn=True,
               env=env,
               asynchronous=True)

    # we block here until the test function using this fixture has returned
    yield runner

    # Kill the runner's process as we finished our test (platform dependent)
    os_signal = signal.SIGTERM
    if platform.system() != "Windows":
        os_signal = signal.SIGKILL
    os.kill(runner.process.pid, os_signal)
Exemplo n.º 6
0
 def _hang_on_full_pipe(self, pty):
     class Whoops(Exception):
         pass
     runner = Local(Context())
     # Force runner IO thread-body method to raise an exception to mimic
     # real world encoding explosions/etc. When bug is present, this
     # will make the test hang until forcibly terminated.
     runner.handle_stdout = Mock(side_effect=Whoops, __name__='sigh')
     # NOTE: both Darwin (10.10) and Linux (Travis' docker image) have
     # this file. It's plenty large enough to fill most pipe buffers,
     # which is the triggering behavior.
     try:
         runner.run("cat /usr/share/dict/words", pty=pty)
     except ThreadException as e:
         eq_(len(e.exceptions), 1)
         ok_(e.exceptions[0].type is Whoops)
     else:
         assert False, "Did not receive expected ThreadException!"
Exemplo n.º 7
0
 def _hang_on_full_pipe(self, pty):
     class Whoops(Exception):
         pass
     runner = Local(Context())
     # Force runner IO thread-body method to raise an exception to mimic
     # real world encoding explosions/etc. When bug is present, this
     # will make the test hang until forcibly terminated.
     runner.handle_stdout = Mock(side_effect=Whoops, __name__='sigh')
     # NOTE: both Darwin (10.10) and Linux (Travis' docker image) have
     # this file. It's plenty large enough to fill most pipe buffers,
     # which is the triggering behavior.
     try:
         runner.run("cat /usr/share/dict/words", pty=pty)
     except ThreadException as e:
         eq_(len(e.exceptions), 1)
         ok_(e.exceptions[0].type is Whoops)
     else:
         assert False, "Did not receive expected ThreadException!"
Exemplo n.º 8
0
 def triggers_exception_when_command_slow(self):
     before = time.time()
     with raises(CommandTimedOut) as info:
         Local(Context()).run("sleep 5", timeout=0.5)
     after = time.time()
     # Fudge real time check a bit, <=0.5 typically fails due to
     # overhead etc. May need raising further to avoid races? Meh.
     assert (after - before) <= 0.75
     # Sanity checks of the exception obj
     assert info.value.timeout == 0.5
     assert info.value.result.command == "sleep 5"
Exemplo n.º 9
0
 def does_not_fire_when_command_quick(self):
     assert Local(Context()).run("sleep 1", timeout=5)
Exemplo n.º 10
0
def webpack():

    Local('rm -rf dublinBus/static/bundles/stage/*')
    Local('rm -rf dublinBus/static/bundles/prod/*')
    Local('webpack --config webpack.stage.config.js --progress --colors')
    Local('webpack --config webpack.prod.config.js --progress --colors')