예제 #1
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.python_package = hitchpython.PythonPackage(self.preconditions.get("python_version", "3.5.0"))
        self.python_package.build()

        # Uninstall and reinstall
        call([self.python_package.pip, "install", "ipython==1.2.1"], stdout=PIPE)
        call([self.python_package.pip, "install", "pyzmq"], stdout=PIPE)
        call([self.python_package.pip, "install", "flake8"], stdout=PIPE)
        call([self.python_package.pip, "uninstall", "dumbyaml", "-y"], stdout=PIPE)
        # chdir(PROJECT_DIRECTORY)
        # check_call([self.python_package.python, "setup.py", "install"], stdout=PIPE)

        run(Command([self.python_package.python, "setup.py", "install"]).in_dir(PROJECT_DIRECTORY))
        # print(Command([self.python_package.python, "setup.py", "install"]).arguments)

        self.services = hitchserve.ServiceBundle(PROJECT_DIRECTORY, startup_timeout=8.0, shutdown_timeout=1.0)

        self.services["IPython"] = hitchpython.IPythonKernelService(self.python_package)

        self.services.startup(interactive=False)
        self.ipython_kernel_filename = self.services["IPython"].wait_and_get_ipykernel_filename()
        self.ipython_step_library = hitchpython.IPythonStepLibrary()
        self.ipython_step_library.startup_connection(self.ipython_kernel_filename)

        self.run_command = self.ipython_step_library.run
        self.assert_true = self.ipython_step_library.assert_true
        self.assert_exception = self.ipython_step_library.assert_exception
        self.shutdown_connection = self.ipython_step_library.shutdown_connection
        self.run_command("import dumbyaml")
        self.run_command("import yaml")
예제 #2
0
 def flake8(self, directory, args=None):
     # Silently install flake8
     self.services.start_interactive_mode()
     flake8 = self.python_package.cmd.flake8
     try:
         run(flake8(str(self.path.project.joinpath(directory)), *args).in_dir(self.path.project))
     except CommandError:
         raise RuntimeError("flake8 failure")
예제 #3
0
 def flake8(self, directory, args=None):
     # Silently install flake8
     self.services.start_interactive_mode()
     flake8 = self.python_package.cmd.flake8
     try:
         run(flake8(str(self.path.project.joinpath(directory)), *args).in_dir(self.path.project))
     except CommandError:
         raise RuntimeError("flake8 failure")
예제 #4
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.path.project = self.path.engine.parent

        if self.path.state.exists():
            self.path.state.rmtree(ignore_errors=True)
        self.path.state.mkdir()

        for filename, text in self.preconditions.get("files", {}).items():
            filepath = self.path.state.joinpath(filename)
            if not filepath.dirname().exists():
                filepath.dirname().mkdir()
            filepath.write_text(text)

        self.python_package = hitchpython.PythonPackage(
            self.preconditions.get('python_version', '3.5.0')
        )
        self.python_package.build()

        self.pip = self.python_package.cmd.pip
        self.python = self.python_package.cmd.python

        # Install debugging packages
        with hitchtest.monitor([self.path.engine.joinpath("debugrequirements.txt")]) as changed:
            if changed:
                run(self.pip("install", "-r", "debugrequirements.txt").in_dir(self.path.engine))

        # Uninstall and reinstall
        run(self.pip("uninstall", "hitchtrigger", "-y").ignore_errors())
        run(self.pip("install", ".").in_dir(self.path.project))

        run(self.pip("install", "peewee=={0}".format(self.preconditions['peewee_version'])))
        run(self.pip("install", "humanize=={0}".format(self.preconditions['humanize_version'])))

        self.services = hitchserve.ServiceBundle(
            str(self.path.project),
            startup_timeout=8.0,
            shutdown_timeout=1.0
        )

        self.services['IPython'] = hitchpython.IPythonKernelService(self.python_package)

        self.services.startup(interactive=False)
        self.ipython_kernel_filename = self.services['IPython'].wait_and_get_ipykernel_filename()
        self.ipython_step_library = hitchpython.IPythonStepLibrary()
        self.ipython_step_library.startup_connection(self.ipython_kernel_filename)

        self.run_command = self.ipython_step_library.run
        self.assert_true = self.ipython_step_library.assert_true
        self.assert_exception = self.ipython_step_library.assert_exception
        self.shutdown_connection = self.ipython_step_library.shutdown_connection
        self.run_command("import os")
        self.run_command("os.chdir('{}')".format(self.path.state))

        for line in self.settings['always run']:
            self.run_command(line)
예제 #5
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.path.project = self.path.engine.parent

        if self.path.state.exists():
            self.path.state.rmtree(ignore_errors=True)
        self.path.state.mkdir()

        for script, text in self.preconditions.get("scripts", {}).items():
            script_file = self.path.state.joinpath(script)
            if not script_file.dirname().exists():
                script_file.dirname().mkdir()
            script_file.write_text(text)
            script_file.chmod("u+x")

        self.python_package = hitchpython.PythonPackage(self.preconditions.get("python_version", "3.5.0"))
        self.python_package.build()

        self.pip = self.python_package.cmd.pip
        self.python = self.python_package.cmd.python

        # Uninstall and reinstall
        run(self.pip("install", "flake8"))
        run(self.pip("install", "ipython==1.2.1").ignore_errors())
        run(self.pip("install", "pyzmq").ignore_errors())
        run(self.pip("uninstall", "commandlib", "-y").ignore_errors())
        run(self.pip("install", ".").in_dir(self.path.project))

        self.services = hitchserve.ServiceBundle(str(self.path.project), startup_timeout=8.0, shutdown_timeout=1.0)

        self.services["IPython"] = hitchpython.IPythonKernelService(self.python_package)

        self.services.startup(interactive=False)
        self.ipython_kernel_filename = self.services["IPython"].wait_and_get_ipykernel_filename()
        self.ipython_step_library = hitchpython.IPythonStepLibrary()
        self.ipython_step_library.startup_connection(self.ipython_kernel_filename)

        self.run_command = self.ipython_step_library.run
        self.assert_true = self.ipython_step_library.assert_true
        self.assert_exception = self.ipython_step_library.assert_exception
        self.shutdown_connection = self.ipython_step_library.shutdown_connection
        self.run_command("from commandlib import Command, run")
        self.run_command("import os")
        self.run_command("os.chdir('{}')".format(self.path.state))
예제 #6
0
def download_file(downloaded_file_name, url, max_connections=2, max_concurrent=5):
    """Download file to specified location."""
    from commandlib import Command, CommandError, run
    if os.path.exists(downloaded_file_name):
        return

    log("Downloading: {}\n".format(url))
    aria2c = Command("aria2c")
    aria2c = aria2c("--max-connection-per-server={}".format(max_connections))
    aria2c = aria2c("--max-concurrent-downloads={}".format(max_concurrent))

    try:
        if os.path.isabs(downloaded_file_name):
            run(aria2c("--dir=/", "--out={}.part".format(downloaded_file_name), url))
        else:
            run(aria2c("--dir=.", "--out={}.part".format(downloaded_file_name), url))
    except CommandError:
        raise DownloadError("Failed to download {}. Re-running may fix the problem.".format(url))

    shutil.move(downloaded_file_name + ".part", downloaded_file_name)
예제 #7
0
파일: key.py 프로젝트: hitchtest/hitchhttp
    def set_up(self):
        """Set up your applications and the test environment."""
        self.path.state = self.path.gen.joinpath("state")
        
        if self.path.state.exists():
            self.path.state.rmtree()
        self.path.state.mkdir()

        self.python_package = hitchpython.PythonPackage(
            self.preconditions.get('python_version', '3.5.0')
        )
        self.python_package.build()

        self.pip = self.python_package.cmd.pip
        self.python = self.python_package.cmd.python

        # Install debugging packages
        with hitchtest.monitor([self.path.key.joinpath("debugrequirements.txt")]) as changed:
            if changed:
                run(self.pip("install", "-r", "debugrequirements.txt").in_dir(self.path.key))

        # Uninstall and reinstall
        with hitchtest.monitor(pathq(self.path.project.joinpath("hitchhttp")).ext("py")) as changed:
            if changed:
                run(self.pip("uninstall", "hitchhttp", "-y").ignore_errors())
                run(self.pip("install", ".").in_dir(self.path.project))
        
        self.path.state.joinpath("example.yaml").write_text(self.preconditions['example.yaml'])
        self.path.state.joinpath("myserver.py").write_text(self.preconditions['code'])
        
        self.services = hitchserve.ServiceBundle(
            str(self.path.project),
            startup_timeout=2.0,
            shutdown_timeout=2.0,
        )
예제 #8
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.doc = hitchdoc.Recorder(
            hitchdoc.HitchStory(self),
            self.path.gen.joinpath('storydb.sqlite'),
        )

        self.path.state = self.path.gen.joinpath("state")
        if self.path.state.exists():
            self.path.state.rmtree(ignore_errors=True)
        self.path.state.mkdir()

        self.path.profile = self.path.gen.joinpath("profile")
        if not self.path.profile.exists():
            self.path.profile.mkdir()

        self.python_package = hitchpython.PythonPackage(
            self.given['python version']
        )
        self.python_package.build()

        self.pip = self.python_package.cmd.pip
        self.python = self.python_package.cmd.python

        # Install debugging packages
        with hitchtest.monitor([self.path.key.joinpath("debugrequirements.txt")]) as changed:
            if changed:
                run(self.pip("install", "-r", "debugrequirements.txt").in_dir(self.path.key))

        # Uninstall and reinstall
        with hitchtest.monitor(
            pathq(self.path.project.joinpath("strictyaml")).ext("py")
        ) as changed:
            if changed:
                run(self.pip("uninstall", "strictyaml", "-y").ignore_errors())
                run(self.pip("install", ".").in_dir(self.path.project))
                run(self.pip("install", "ruamel.yaml=={0}".format(
                    self.given["ruamel version"]
                )))

        self.example_py_code = ExamplePythonCode(self.python, self.path.state)\
            .with_code(self.given.get('code', ''))\
            .with_setup_code(self.given.get('setup', ''))\
            .with_long_strings(
                yaml_snippet_1=self.given.get('yaml_snippet_1'),
                yaml_snippet=self.given.get('yaml_snippet'),
                yaml_snippet_2=self.given.get('yaml_snippet_2'),
                modified_yaml_snippet=self.given.get('modified_yaml_snippet'),
            )
예제 #9
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.python_package = hitchpython.PythonPackage(
            self.preconditions.get('python_version', '3.5.0')
        )
        self.python_package.build()

        # Uninstall and reinstall
        call([self.python_package.pip, "install", "ipython==1.2.1", ], stdout=PIPE)
        call([self.python_package.pip, "install", "pyzmq", ], stdout=PIPE)
        call([self.python_package.pip, "install", "flake8", ], stdout=PIPE)
        call([self.python_package.pip, "uninstall", "dumbyaml", "-y"], stdout=PIPE)
        #chdir(PROJECT_DIRECTORY)
        #check_call([self.python_package.python, "setup.py", "install"], stdout=PIPE)
        
        run(Command([self.python_package.python, "setup.py", "install"]).in_dir(PROJECT_DIRECTORY))
        #print(Command([self.python_package.python, "setup.py", "install"]).arguments)


        self.services = hitchserve.ServiceBundle(
            PROJECT_DIRECTORY,
            startup_timeout=8.0,
            shutdown_timeout=1.0
        )
        
        self.services['IPython'] = hitchpython.IPythonKernelService(self.python_package)
        
        self.services.startup(interactive=False)
        self.ipython_kernel_filename = self.services['IPython'].wait_and_get_ipykernel_filename()
        self.ipython_step_library = hitchpython.IPythonStepLibrary()
        self.ipython_step_library.startup_connection(self.ipython_kernel_filename)
        
        self.run_command = self.ipython_step_library.run
        self.assert_true = self.ipython_step_library.assert_true
        self.assert_exception = self.ipython_step_library.assert_exception
        self.shutdown_connection = self.ipython_step_library.shutdown_connection
        self.run_command("import dumbyaml")
        self.run_command("import yaml")
예제 #10
0
파일: key.py 프로젝트: hitchtest/hitchhttp
    def set_up(self):
        """Set up your applications and the test environment."""
        self.path.state = self.path.gen.joinpath("state")

        if self.path.state.exists():
            self.path.state.rmtree()
        self.path.state.mkdir()

        self.python_package = hitchpython.PythonPackage(
            self.preconditions.get('python_version', '3.5.0'))
        self.python_package.build()

        self.pip = self.python_package.cmd.pip
        self.python = self.python_package.cmd.python

        # Install debugging packages
        with hitchtest.monitor(
            [self.path.key.joinpath("debugrequirements.txt")]) as changed:
            if changed:
                run(
                    self.pip("install", "-r",
                             "debugrequirements.txt").in_dir(self.path.key))

        # Uninstall and reinstall
        with hitchtest.monitor(
                pathq(self.path.project.joinpath("hitchhttp")).ext(
                    "py")) as changed:
            if changed:
                run(self.pip("uninstall", "hitchhttp", "-y").ignore_errors())
                run(self.pip("install", ".").in_dir(self.path.project))

        self.path.state.joinpath("example.yaml").write_text(
            self.preconditions['example.yaml'])
        self.path.state.joinpath("myserver.py").write_text(
            self.preconditions['code'])

        self.services = hitchserve.ServiceBundle(
            str(self.path.project),
            startup_timeout=2.0,
            shutdown_timeout=2.0,
        )
예제 #11
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.path.project = self.path.engine.parent

        if self.path.state.exists():
            self.path.state.rmtree(ignore_errors=True)
        self.path.state.mkdir()

        for script, text in self.preconditions.get("scripts", {}).items():
            script_file = self.path.state.joinpath(script)
            if not script_file.dirname().exists():
                script_file.dirname().mkdir()
            script_file.write_text(text)
            script_file.chmod("u+x")

        for script, text in self.preconditions.get("files", {}).items():
            script_file = self.path.state.joinpath(script)
            if not script_file.dirname().exists():
                script_file.dirname().mkdir()
            script_file.write_text(text)

        self.python_package = hitchpython.PythonPackage(
            self.preconditions.get('python_version', '3.5.0'))
        self.python_package.build()

        self.pip = self.python_package.cmd.pip
        self.python = self.python_package.cmd.python

        # Uninstall and reinstall
        run(self.pip("install", "flake8"))
        run(self.pip("install", "ipython==1.2.1").ignore_errors())
        run(self.pip("install", "pyzmq").ignore_errors())
        run(self.pip("uninstall", "commandlib", "-y").ignore_errors())
        run(self.pip("install", ".").in_dir(self.path.project))

        if "pexpect_version" in self.preconditions:
            run(
                self.pip(
                    "install", "pexpect=={0}".format(
                        self.preconditions['pexpect_version'])))

        self.services = hitchserve.ServiceBundle(str(self.path.project),
                                                 startup_timeout=8.0,
                                                 shutdown_timeout=1.0)

        self.services['IPython'] = hitchpython.IPythonKernelService(
            self.python_package)

        self.services.startup(interactive=False)
        self.ipython_kernel_filename = self.services[
            'IPython'].wait_and_get_ipykernel_filename()
        self.ipython_step_library = hitchpython.IPythonStepLibrary()
        self.ipython_step_library.startup_connection(
            self.ipython_kernel_filename)

        self.run_command = self.ipython_step_library.run
        self.assert_true = self.ipython_step_library.assert_true
        self.assert_exception = self.ipython_step_library.assert_exception
        self.shutdown_connection = self.ipython_step_library.shutdown_connection
        self.run_command("from commandlib import Command, run")
        self.run_command("import os")
        self.run_command("os.chdir('{}')".format(self.path.state))
예제 #12
0
    def set_up(self):
        self.path.project = self.path.engine.parent
        self.path.state = self.path.engine.parent.joinpath("state")
        self.path.samples = self.path.engine.joinpath("samples")

        if self.path.state.exists():
            self.path.state.rmtree()
        self.path.state.mkdir()

        if self.settings.get("kaching", False):
            kaching.start()

        self.python_package = hitchpython.PythonPackage(
            python_version=self.settings['python_version']
        )
        self.python_package.build()

        self.firefox_package = hitchselenium.FirefoxPackage()
        self.firefox_package.build()

        self.python = self.python_package.cmd.python
        self.pip = self.python_package.cmd.pip

        run(self.pip("uninstall", "hitchselenium", "-y").ignore_errors())
        run(self.pip("install", ".", "--no-cache-dir").in_dir(
            self.path.project.joinpath("..", "test")    # Install hitchtest
        ))
        run(self.pip("install", ".").in_dir(self.path.project))
        run(self.pip("install", "ipykernel"))
        run(self.pip("install", "pip"))
        run(self.pip("install", "q"))
        run(self.pip("install", "pudb"))
        run(self.pip("install", "flake8"))

        self.path.state.joinpath("index.html").write_text(
            self.settings['html_base'].format(core=self.preconditions.get('html'))
        )

        if "selectors" in self.preconditions:
            self.path.state.joinpath("selectors.yaml").write_text(self.preconditions['selectors'])

        self.path.state.joinpath("success.html").write_text(self.settings['success_html'])

        self.cli = hitchcli.CommandLineStepLibrary(
            default_timeout=int(self.settings.get("cli_timeout", 720))
        )

        self.services = hitchserve.ServiceBundle(
            self.path.project,
            startup_timeout=8.0,
            shutdown_timeout=1.0
        )

        self.services['Webserver'] = hitchserve.Service(
            command=["python", "-u", "-m", "SimpleHTTPServer"],
            log_line_ready_checker=lambda line: "Serving" in line,
            directory=self.path.state,
        )

        self.services['IPython'] = hitchpython.IPythonKernelService(self.python_package)

        self.services['Firefox'] = hitchselenium.FirefoxService(
            firefox_binary=self.firefox_package.firefox,
            no_libfaketime=True,
            xvfb=self.settings.get("xvfb", False) or self.settings.get("quiet", False),
        )


        self.services.startup(interactive=False)

        command_executor = self.services['Firefox'].logs.json()[0]['uri']

        self.ipython_kernel_filename = self.services['IPython'].wait_and_get_ipykernel_filename()
        self.ipython_step_library = hitchpython.IPythonStepLibrary()
        self.ipython_step_library.startup_connection(self.ipython_kernel_filename)

        self.run_command = self.ipython_step_library.run
        self.assert_true = self.ipython_step_library.assert_true
        self.assert_exception = self.ipython_step_library.assert_exception
        self.shutdown_connection = self.ipython_step_library.shutdown_connection

        self.run_command("import os")
        self.run_command("""os.chdir("{}")""".format(self.path.state))
        self.run_command("from selenium import webdriver")
        self.run_command("desired_capabilities = {}")
        self.run_command(
            """driver = webdriver.Remote(command_executor="{0}", desired_capabilities=desired_capabilities)""".format(
                command_executor
            )
        )
예제 #13
0
 def lint(self, args=None):
     """Lint the source code."""
     run(self.pip("install", "flake8"))
     run(self.python_package.cmd.flake8(*args).in_dir(self.path.project))
예제 #14
0
파일: engine.py 프로젝트: crdoconnor/simex
    def set_up(self):
        self.path.project = self.path.engine.parent
        self.path.state = self.path.engine.parent.joinpath("state")
        self.path.samples = self.path.engine.joinpath("samples")

        if self.path.state.exists():
            self.path.state.rmtree()
        self.path.state.mkdir()

        if self.settings.get("kaching", False):
            kaching.start()

        self.python_package = hitchpython.PythonPackage(
            python_version=self.preconditions.get('python_version', '3.5.0')
        )
        self.python_package.build()

        self.python = self.python_package.cmd.python
        self.pip = self.python_package.cmd.pip

        self.cli_steps = hitchcli.CommandLineStepLibrary(
            default_timeout=int(self.settings.get("cli_timeout", 5))
        )

        self.cd = self.cli_steps.cd
        self.pexpect_run = self.cli_steps.run
        self.expect = self.cli_steps.expect
        self.send_control = self.cli_steps.send_control
        self.send_line = self.cli_steps.send_line
        self.exit_with_any_code = self.cli_steps.exit_with_any_code
        self.exit = self.cli_steps.exit
        self.finish = self.cli_steps.finish

        run(self.pip("uninstall", "simex", "-y").ignore_errors())
        run(self.pip("install", ".").in_dir(self.path.project))
        run(self.pip("install", "ipykernel"))
        run(self.pip("install", "pip"))
        run(self.pip("install", "q"))
        run(self.pip("install", "pudb"))

        for filename, contents in self.preconditions.get("files", {}).items():
            self.path.state.joinpath(filename).write_text(contents)
        self.path.state.chdir()
예제 #15
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.path.project = self.path.engine.parent
        self.path.docs = self.path.project.joinpath("docs")
        self.path.this_story_doc = self.path.docs.joinpath(
            "{0}.rst".format(path.basename(self._test.filename).replace(".test", ""))
        )

        if self.path.this_story_doc.exists():
            self.path.this_story_doc.remove()
        self.append_to_docs("{0}\n{1}\n\n".format(
                self._test.name, "=" * len(self._test.name),
            )
        )

        if self._test.description is not None:
            self.append_to_docs("{0}\n\n".format(self._test.description))

        if self.path.state.exists():
            self.path.state.rmtree(ignore_errors=True)
        self.path.state.mkdir()

        for filename, text in self.preconditions.get("files", {}).items():
            filepath = self.path.state.joinpath(filename)
            if not filepath.dirname().exists():
                filepath.dirname().mkdir()
            filepath.write_text(text)

        self.python_package = hitchpython.PythonPackage(
            self.preconditions.get('python_version', '3.5.0')
        )
        self.python_package.build()

        self.pip = self.python_package.cmd.pip
        self.python = self.python_package.cmd.python

        # Install debugging packages
        with hitchtest.monitor([self.path.engine.joinpath("debugrequirements.txt")]) as changed:
            if changed:
                run(self.pip("install", "-r", "debugrequirements.txt").in_dir(self.path.engine))

        # Uninstall and reinstall
        run(self.pip("uninstall", "strictyaml", "-y").ignore_errors())
        run(self.pip("install", ".").in_dir(self.path.project))
        run(self.pip("install", "ruamel.yaml=={0}".format(self.preconditions.get("ruamel version", "0.12.12"))))

        self.services = hitchserve.ServiceBundle(
            str(self.path.project),
            startup_timeout=8.0,
            shutdown_timeout=1.0
        )

        self.services['IPython'] = hitchpython.IPythonKernelService(self.python_package)

        self.services.startup(interactive=False)
        self.ipython_kernel_filename = self.services['IPython'].wait_and_get_ipykernel_filename()
        self.ipython_step_library = hitchpython.IPythonStepLibrary()
        self.ipython_step_library.startup_connection(self.ipython_kernel_filename)

        #self.assert_true = self.ipython_step_library.assert_true
        #self.assert_exception = self.ipython_step_library.assert_exception
        self.shutdown_connection = self.ipython_step_library.shutdown_connection
        self.ipython_step_library.run("import os")
        self.ipython_step_library.run("from path import Path")
        self.ipython_step_library.run("os.chdir('{}')".format(self.path.state))

        for filename, text in self.preconditions.get("files", {}).items():
            self.ipython_step_library.run(
                """{} = Path("{}").bytes().decode("utf8")""".format(
                    filename.replace(".yaml", ""), filename
                )
            )
            self.append_to_docs("{0}\n.. code-block:: yaml\n\n  {1}\n\n".format(
                filename.replace(".yaml", ""),
                text.rstrip("\n").replace("\n", "\n  ")
            ))
예제 #16
0
    def set_up(self):
        self.path.project = self.path.engine.parent
        self.path.state = self.path.engine.parent.joinpath("state")
        self.path.samples = self.path.engine.joinpath("samples")

        if self.path.state.exists():
            self.path.state.rmtree()
        self.path.state.mkdir()

        if self.settings.get("kaching", False):
            kaching.start()

        self.python_package = hitchpython.PythonPackage(
            python_version=self.settings['python_version']
        )
        self.python_package.build()

        self.firefox_package = hitchselenium.FirefoxPackage()
        self.firefox_package.build()

        self.python = self.python_package.cmd.python
        self.pip = self.python_package.cmd.pip
        self.hitchhttpcmd = self.python("-u", "-m", "hitchhttp.commandline")

        self.cli_steps = hitchcli.CommandLineStepLibrary(
            default_timeout=int(self.settings.get("cli_timeout", 5))
        )

        self.cd = self.cli_steps.cd
        self.run = self.cli_steps.run
        self.expect = self.cli_steps.expect
        self.send_control = self.cli_steps.send_control
        self.send_line = self.cli_steps.send_line
        self.exit_with_any_code = self.cli_steps.exit_with_any_code
        self.exit = self.cli_steps.exit
        self.finish = self.cli_steps.finish

        run(self.pip("uninstall", "hitchhttp", "-y").ignore_errors())
        run(self.pip("uninstall", "hitchtest", "-y").ignore_errors())
        run(self.pip("install", ".").in_dir(
            self.path.project.joinpath("..", "test")    # Install hitchtest
        ))
        run(self.pip("install", ".").in_dir(self.path.project))
        run(self.pip("install", "ipykernel"))
        run(self.pip("install", "pip"))
        run(self.pip("install", "q"))
        run(self.pip("install", "pudb"))

        for filename, contents in self.preconditions.get("config_files", {}).items():
            self.path.state.joinpath(filename).write_text(contents)
예제 #17
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.path.project = self.path.engine.parent
        self.path.config_file = self.path.project.joinpath("config.py")

        self.path.appdb = self.path.project.joinpath("app.db")
        self.path.testdb = self.path.project.joinpath("test.db")

        if self.path.appdb.exists():
            self.path.appdb.remove()

        if self.path.testdb.exists():
            self.path.testdb.remove()

        self.path.config_file.write_text((
            """import os\n"""
            """basedir = os.path.abspath(os.path.dirname(__file__))\n"""
            """\n"""
            """SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db')\n"""
            """SQLALCHEMY_MIGRATE_REPO = os.path.join(basedir, 'db_repository')\n"""
            """WTF_CSRF_ENABLED = True\n"""
            """SECRET_KEY = 'you-will-never-guess'\n"""
        ))

        self.python_package = hitchpython.PythonPackage(
            python_version=self.settings['python_version']
        )
        self.python_package.build()

        self.python = self.python_package.cmd.python.in_dir(self.path.project)
        self.pip = self.python_package.cmd.pip.in_dir(self.path.project)

        with monitor([self.path.project.joinpath("requirements.txt"), ]) as changed:
            if changed:
                run(self.pip("install", "-r", "requirements.txt"))

        run(Command("bash")("-c", "sqlite3 {0}/test.db < {0}/test.sql".format(self.path.project)))

        #run(self.python("db_create.py"))
        #run(self.python("db_migrate.py"))

        self.services = ServiceBundle(
            project_directory=str(self.path.project),
            startup_timeout=float(self.settings["startup_timeout"]),
            shutdown_timeout=float(self.settings["shutdown_timeout"]),
        )

        # Docs : https://hitchtest.readthedocs.org/en/latest/plugins/hitchpython.html
        self.services['Flask'] = hitchserve.Service(
            command=self.python("run.py"),
            log_line_ready_checker=lambda line: "Restarting with stat" in line,
        )

        # Docs : https://hitchtest.readthedocs.org/en/latest/plugins/hitchselenium.html

        self.services['Firefox'] = hitchselenium.SeleniumService(
            xvfb=self.settings.get("xvfb", False) or self.settings.get("quiet", False),
            no_libfaketime=True,
        )

        self.services.startup(interactive=False)

        # Docs : https://hitchtest.readthedocs.org/en/latest/plugins/hitchselenium.html
        self.driver = self.services['Firefox'].driver

        self.webapp = hitchselenium.SeleniumStepLibrary(
            selenium_webdriver=self.driver,
            wait_for_timeout=5,
        )

        self.click = self.webapp.click
        self.wait_to_appear = self.webapp.wait_to_appear
        self.wait_to_contain = self.webapp.wait_to_contain
        self.wait_for_any_to_contain = self.webapp.wait_for_any_to_contain
        self.click_and_dont_wait_for_page_load = self.webapp.click_and_dont_wait_for_page_load

        # Configure selenium driver
        screen_res = self.settings.get(
            "screen_resolution", {"width": 1024, "height": 768, }
        )
        self.driver.set_window_size(
            int(screen_res['width']), int(screen_res['height'])
        )
        self.driver.set_window_position(0, 0)
        self.driver.implicitly_wait(2.0)
        self.driver.accept_next_alert = True
예제 #18
0
파일: key.py 프로젝트: tobbez/strictyaml
    def set_up(self):
        """Set up your applications and the test environment."""
        self.doc = hitchdoc.Recorder(
            hitchdoc.HitchStory(self),
            self.path.gen.joinpath('storydb.sqlite'),
        )

        if self.path.gen.joinpath("state").exists():
            self.path.gen.joinpath("state").rmtree(ignore_errors=True)
        self.path.gen.joinpath("state").mkdir()
        self.path.state = self.path.gen.joinpath("state")

        for filename, text in self.preconditions.get("files", {}).items():
            filepath = self.path.state.joinpath(filename)
            if not filepath.dirname().exists():
                filepath.dirname().mkdir()
            filepath.write_text(text)

        self.python_package = hitchpython.PythonPackage(
            self.preconditions.get('python_version', '3.5.0'))
        self.python_package.build()

        self.pip = self.python_package.cmd.pip
        self.python = self.python_package.cmd.python

        # Install debugging packages
        with hitchtest.monitor(
            [self.path.key.joinpath("debugrequirements.txt")]) as changed:
            if changed:
                run(
                    self.pip("install", "-r",
                             "debugrequirements.txt").in_dir(self.path.key))

        # Uninstall and reinstall
        run(self.pip("uninstall", "strictyaml", "-y").ignore_errors())
        run(self.pip("install", ".").in_dir(self.path.project))
        run(
            self.pip(
                "install", "ruamel.yaml=={0}".format(
                    self.preconditions["ruamel version"])))

        self.services = hitchserve.ServiceBundle(str(self.path.project),
                                                 startup_timeout=8.0,
                                                 shutdown_timeout=1.0)

        self.services['IPython'] = hitchpython.IPythonKernelService(
            self.python_package)

        self.services.startup(interactive=False)
        self.ipython_kernel_filename = self.services[
            'IPython'].wait_and_get_ipykernel_filename()
        self.ipython_step_library = hitchpython.IPythonStepLibrary()
        self.ipython_step_library.startup_connection(
            self.ipython_kernel_filename)

        self.shutdown_connection = self.ipython_step_library.shutdown_connection
        self.ipython_step_library.run("import os")
        self.ipython_step_library.run("import sure")
        self.ipython_step_library.run("from path import Path")
        self.ipython_step_library.run("os.chdir('{}')".format(self.path.state))

        for filename, text in self.preconditions.get("files", {}).items():
            self.ipython_step_library.run(
                """{} = Path("{}").bytes().decode("utf8")""".format(
                    filename.replace(".yaml", ""), filename))
예제 #19
0
    def set_up(self):
        self.path.project = self.path.engine.parent
        self.path.state = self.path.engine.parent.joinpath("state")
        self.path.samples = self.path.engine.joinpath("samples")

        if not self.path.state.exists():
            self.path.state.mkdir()

        if self.settings.get("kaching", False):
            kaching.start()

        self.python_package = hitchpython.PythonPackage(
            python_version="3.5.0"  #self.preconditions['python_version']
        )
        self.python_package.build()

        self.python = self.python_package.cmd.python
        self.pip = self.python_package.cmd.pip

        self.cli_steps = hitchcli.CommandLineStepLibrary(
            default_timeout=int(self.settings.get("cli_timeout", 720)))

        self.cd = self.cli_steps.cd
        self.run = self.cli_steps.run
        self.expect = self.cli_steps.expect
        self.send_control = self.cli_steps.send_control
        self.send_line = self.cli_steps.send_line
        self.exit_with_any_code = self.cli_steps.exit_with_any_code
        self.exit = self.cli_steps.exit
        self.finish = self.cli_steps.finish

        if "files" in self.preconditions:
            self.path.state.rmtree(ignore_errors=True)
            self.path.state.mkdir()
            for filename, contents in self.preconditions['files'].items():
                self.path.state.joinpath(filename).write_text(contents)

        if "state" in self.preconditions:
            self.path.state.rmtree(ignore_errors=True)
            self.path.samples.joinpath(self.preconditions['state'])\
                             .copytree(self.path.state)

        run(self.pip("uninstall", "hitchmysql", "-y").ignore_errors())
        run(self.pip("uninstall", "hitchtest", "-y").ignore_errors())
        run(
            self.pip("install",
                     ".").in_dir(self.path.project.joinpath("..", "test")))
        run(
            self.pip("install", ".").in_dir(
                self.path.project.joinpath("..", "commandlib")))
        run(self.pip("install", ".").in_dir(self.path.project))
        run(self.pip("install", "ipykernel"))
        run(self.pip("install", "pip", "--upgrade"))
        run(self.pip("install", "pygments", "--upgrade"))

        self.services = hitchserve.ServiceBundle(self.path.project,
                                                 startup_timeout=8.0,
                                                 shutdown_timeout=1.0)
예제 #20
0
파일: engine.py 프로젝트: crdoconnor/simex
 def lint(self, args=None):
     """Lint the source code."""
     run(self.pip("install", "flake8"))
     run(self.python_package.cmd.flake8(*args).in_dir(self.path.project))
예제 #21
0
    def set_up(self):
        self.path.project = self.path.engine.parent
        self.path.state = self.path.engine.parent.joinpath("state")
        self.path.samples = self.path.engine.joinpath("samples")

        if not self.path.state.exists():
            self.path.state.mkdir()

        if self.settings.get("kaching", False):
            kaching.start()

        self.python_package = hitchpython.PythonPackage(python_version="3.5.0")  # self.preconditions['python_version']
        self.python_package.build()

        self.python = self.python_package.cmd.python
        self.pip = self.python_package.cmd.pip

        self.cli_steps = hitchcli.CommandLineStepLibrary(default_timeout=int(self.settings.get("cli_timeout", 720)))

        self.cd = self.cli_steps.cd
        self.run = self.cli_steps.run
        self.expect = self.cli_steps.expect
        self.send_control = self.cli_steps.send_control
        self.send_line = self.cli_steps.send_line
        self.exit_with_any_code = self.cli_steps.exit_with_any_code
        self.exit = self.cli_steps.exit
        self.finish = self.cli_steps.finish

        if "files" in self.preconditions:
            self.path.state.rmtree(ignore_errors=True)
            self.path.state.mkdir()
            for filename, contents in self.preconditions["files"].items():
                self.path.state.joinpath(filename).write_text(contents)

        if "state" in self.preconditions:
            self.path.state.rmtree(ignore_errors=True)
            self.path.samples.joinpath(self.preconditions["state"]).copytree(self.path.state)

        run(self.pip("uninstall", "hitchmysql", "-y").ignore_errors())
        run(self.pip("uninstall", "hitchtest", "-y").ignore_errors())
        run(self.pip("install", ".").in_dir(self.path.project.joinpath("..", "test")))
        run(self.pip("install", ".").in_dir(self.path.project.joinpath("..", "commandlib")))
        run(self.pip("install", ".").in_dir(self.path.project))
        run(self.pip("install", "ipykernel"))
        run(self.pip("install", "pip", "--upgrade"))
        run(self.pip("install", "pygments", "--upgrade"))

        self.services = hitchserve.ServiceBundle(self.path.project, startup_timeout=8.0, shutdown_timeout=1.0)