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, )
def regression(): """ Run all stories. """ print( StoryCollection(pathq(DIR.key).ext("story"), Engine( DIR, {})).only_uninherited().ordered_by_name().play().report())
def test(*words): """ Run test with words. """ print( StoryCollection(pathq(DIR.key).ext("story"), Engine(DIR, {})).shortcut(*words).play().report())
def render_to(self, build_path): self._path.copytree(build_path) for template in pathq(build_path).ext("jinja2"): print("Rendering template {0}".format(template)) Path(template.replace(".jinja2", "")).write_text( Template(template.text()).render(**self._templated_vars)) template.remove()
def ci(): """ Continuous integration - run all tests and linter. """ lint() print( StoryCollection(pathq(DIR.key).ext("story"), Engine(DIR, {})).ordered_by_name().play().report())
def bdd(*words): """ Run story in BDD mode that matches keywords (e.g. tdd wait finished) """ print( StoryCollection( pathq(DIR.key).ext("story"), Engine(DIR, {"overwrite artefacts": True})).shortcut( *words).play().report())
def regression(): """ Run regression testing - lint and then run all tests. """ lint() print( StoryCollection( pathq(DIR.key.joinpath("story")).ext("story"), Engine(DIR, {})).ordered_by_name().play().report())
def test(*words): """ Run test with words. """ print( StoryCollection( pathq(KEYPATH).ext("story"), Engine(KEYPATH, {"overwrite artefacts": True}) ).shortcut(*words).play().report() )
def tdd(*words): """ Run test with words. """ print( StoryCollection( pathq(DIR.key.joinpath("story")).ext("story"), Engine(DIR, {}) ).shortcut(*words).play().report() )
def rewrite(): """ Run all stories and rewrite any with different output. """ print( StoryCollection( pathq(DIR.key).ext("story"), Engine(DIR, {"overwrite artefacts": True })).only_uninherited().ordered_by_name().play().report())
def regression(): """ Run regression testing - lint and then run all tests. """ lint() print( StoryCollection( pathq(DIR.key.joinpath("story")).ext("story"), Engine(DIR, {}) ).ordered_by_name().play().report() )
def ci(): """ Run all stories. """ lint() print( StoryCollection( pathq(KEYPATH).ext("story"), Engine(KEYPATH, {}) ).ordered_by_name().play().report() )
def list_dirs(directory, docdir): pages = [] for filepath in pathq(directory): if not filepath.isdir() and filepath.basename() not in ( 'index.jinja2', 'index.md'): relpath = filepath.relpath(docdir) pages.append({ "name": load(filepath.text().split('---')[1])['title'].data, "slug": relpath.dirname().joinpath(relpath.namebase).lstrip("/"), }) return pages
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'), )
def set_up(self): self.path.state = self.path.gen.joinpath("state") if self.path.state.exists(): self.path.state.rmtree(ignore_errors=True) self.path.state.mkdir() for filename, text in self.given.get("files", {}).items(): filepath = self.path.state.joinpath(filename) if not filepath.dirname().exists(): filepath.dirname().mkdir() filepath.write_text(str(text)) filepath.chmod("u+x") for filename, text in self.given.get("variables", {}).items(): filepath = self.path.state.joinpath(filename) if not filepath.dirname().exists(): filepath.dirname().mkdir() filepath.write_text(str(text)) self.path.key.joinpath("code_that_does_things.py").copy( self.path.state) self.python_package = hitchpython.PythonPackage( self.given.get('python_version', self.given['python version'])) self.python_package.build() self.pip = self.python_package.cmd.pip self.python = self.python_package.cmd.python with hitchtest.monitor( [self.path.key.joinpath("debugrequirements.txt")]) as changed: if changed: self.pip("install", "-r", "debugrequirements.txt").in_dir(self.path.key).run() with hitchtest.monitor( pathq(self.path.project.joinpath("icommandlib")).ext( "py")) as changed: if changed: self.pip("uninstall", "icommandlib", "-y").ignore_errors().run() self.pip("install", ".").in_dir(self.path.project).run() self.example_py_code = ExamplePythonCode( self.python, self.path.state, ).with_setup_code(self.given.get('setup', '')).with_code( self.given.get('code', '')).with_timeout(4.0)
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, )
def docgen(): """ Generate documentation. """ class Page(object): def __init__(self, filename): self._filename = filename class TemplatedDocumentation(object): def __init__(self, source_path): self._source_path = source_path self._template_vars = {} def with_vars(self, **template_vars): new_templated_docs = copy(self) new_templated_docs._template_vars = template_vars return new_templated_docs def _templated_vars(self): return self._template_vars def render_to(self, build_path): self._path.copytree(build_path) for template in pathq(build_path).ext("jinja2"): print("Rendering template {0}".format(template)) Path(template.replace(".jinja2", "")).write_text( Template(template.text()).render(**self._templated_vars)) template.remove() docs = DIR.gen.joinpath("docs") if docs.exists(): docs.rmtree(ignore_errors=True) # Copy in non-generated docs DIR.project.joinpath("docs").copytree(docs) using = docs.joinpath("using", "alpha") for story in _storybook({}).with_templates( load(DIR.key.joinpath("doctemplates.yml").bytes().decode( 'utf8')).data).ordered_by_name(): if story.info['docs']: doc = using.joinpath("{0}.md".format(story.info['docs'])) if not doc.dirname().exists(): doc.dirname().makedirs() doc.write_text(story.documentation()) readme = DIR.project.joinpath("docs", "index.md.jinja2").text() from jinja2.environment import Environment from jinja2 import DictLoader, Template env = Environment() env.loader = DictLoader({"README": readme}) def list_dirs(directory, docdir): pages = [] for filepath in pathq(directory): if not filepath.isdir() and filepath.basename() not in ( 'index.jinja2', 'index.md'): relpath = filepath.relpath(docdir) pages.append({ "name": load(filepath.text().split('---')[1])['title'].data, "slug": relpath.dirname().joinpath(relpath.namebase).lstrip("/"), }) return pages def categories(pages): cat = {} for page in pages: levels = page['slug'].split('/') subcat = cat for level in levels[:-1]: if level not in subcat: subcat[level] = {} subcat = subcat[level] subcat[levels[-1]] = page return cat doc_template_vars = { "url": "http://hitchdev.com/strictyaml", "quickstart": _storybook({}).with_templates( load(DIR.key.joinpath("doctemplates.yml").bytes().decode( 'utf8')).data).in_filename( DIR.key / "quickstart.story").non_variations().ordered_by_file(), "why": list_dirs(DIR.project / "docs" / "why", DIR.project / "docs"), "why_not": list_dirs(DIR.project / "docs" / "why-not", DIR.project / "docs"), "using": list_dirs(docs / "using" / "alpha", docs), "using_categories": categories(list_dirs(docs / "using" / "alpha", docs)), "readme": False, } for template in pathq(docs).ext("jinja2"): print("Rendering template {0}".format(template)) Path(template.replace(".jinja2", "")).write_text( Template(template.text()).render(**doc_template_vars)) template.remove() doc_template_vars["readme"] = True readme_text = env.get_template("README").render(**doc_template_vars) import re for match in re.compile("\[.*?\]\(.*?\)").findall(readme_text): if "http://" not in match and "https://" not in match: readme_text = readme_text.replace( match, re.sub("\[(.*?)\]\((.*?)\)", r"[\1](http://hitchdev.com/strictyaml/\2)", match)) DIR.gen.joinpath("README.md").write_text(readme_text)
def test(name): print(StoryCollection(pathq(DIR.key).ext("story"), Engine(DIR)).shortcut(name).play().report())
def _storybook(settings): return StoryCollection( pathq(DIR.key / "story").ext("story"), Engine(DIR, settings))