[py-svn] r57840 - py/extradoc/talk/pycon-uk-2008
hpk at codespeak.net
hpk at codespeak.net
Fri Sep 5 13:58:55 CEST 2008
Author: hpk
Date: Fri Sep 5 13:58:53 2008
New Revision: 57840
Added:
py/extradoc/talk/pycon-uk-2008/author.latex
py/extradoc/talk/pycon-uk-2008/beamerdefs.txt (contents, props changed)
py/extradoc/talk/pycon-uk-2008/makepdf (contents, props changed)
py/extradoc/talk/pycon-uk-2008/rst2beamer.py (contents, props changed)
py/extradoc/talk/pycon-uk-2008/stylesheet.latex
Modified:
py/extradoc/talk/pycon-uk-2008/pytest.txt
Log:
preparing pdf, adjustments to formatting
Added: py/extradoc/talk/pycon-uk-2008/author.latex
==============================================================================
--- (empty file)
+++ py/extradoc/talk/pycon-uk-2008/author.latex Fri Sep 5 13:58:53 2008
@@ -0,0 +1,7 @@
+\definecolor{rrblitbackground}{rgb}{0.0, 0.0, 0.0}
+
+\title[pytest - rapid testing with minimal effort]{rapid testing with minimal effort}
+\author[H. Krekel]{Holger Krekel \\Merlinux GmbH}
+
+\institute[PyCon UK 2008]{PyCon UK 2008 - Birmingham}
+\date{September 13 2008}
Added: py/extradoc/talk/pycon-uk-2008/beamerdefs.txt
==============================================================================
--- (empty file)
+++ py/extradoc/talk/pycon-uk-2008/beamerdefs.txt Fri Sep 5 13:58:53 2008
@@ -0,0 +1,77 @@
+.. colors
+.. ===========================
+
+.. role:: green
+.. role:: red
+
+
+.. general useful commands
+.. ===========================
+
+.. |pause| raw:: latex
+
+ \pause
+
+.. |small| raw:: latex
+
+ {\small
+
+.. |end_small| raw:: latex
+
+ }
+
+
+.. closed bracket
+.. ===========================
+
+.. |>| raw:: latex
+
+ }
+
+
+.. example block
+.. ===========================
+
+.. |example<| raw:: latex
+
+ \begin{exampleblock}{
+
+
+.. |end_example| raw:: latex
+
+ \end{exampleblock}
+
+
+
+.. alert block
+.. ===========================
+
+.. |alert<| raw:: latex
+
+ \begin{alertblock}{
+
+
+.. |end_alert| raw:: latex
+
+ \end{alertblock}
+
+
+
+.. columns
+.. ===========================
+
+.. |column1| raw:: latex
+
+ \begin{columns}
+ \begin{column}{0.45\textwidth}
+
+.. |column2| raw:: latex
+
+ \end{column}
+ \begin{column}{0.45\textwidth}
+
+
+.. |end_columns| raw:: latex
+
+ \end{column}
+ \end{columns}
Added: py/extradoc/talk/pycon-uk-2008/makepdf
==============================================================================
--- (empty file)
+++ py/extradoc/talk/pycon-uk-2008/makepdf Fri Sep 5 13:58:53 2008
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+# you can find rst2beamer.py here:
+# http://codespeak.net/svn/user/antocuni/bin/rst2beamer.py
+
+# WARNING: to work, it needs this patch for docutils
+# https://sourceforge.net/tracker/?func=detail&atid=422032&aid=1459707&group_id=38414
+
+python rst2beamer.py --stylesheet=stylesheet.latex --documentoptions=14pt pytest.txt pytest.latex
+sed 's/\\date{}/\\input{author.latex}/' -i pytest.latex
+pdflatex pytest.latex
+
Modified: py/extradoc/talk/pycon-uk-2008/pytest.txt
==============================================================================
--- py/extradoc/talk/pycon-uk-2008/pytest.txt (original)
+++ py/extradoc/talk/pycon-uk-2008/pytest.txt Fri Sep 5 13:58:53 2008
@@ -1,3 +1,4 @@
+.. include:: beamerdefs.txt
.. include:: <s5defs.txt>
=================================================================
@@ -7,7 +8,6 @@
:author: Holger Krekel, merlinux GmbH
:event: 13.9.2008, Pycon UK 2008, Birmingham
-
my background
===============
@@ -31,58 +31,65 @@
==========================
writing and running tests:
- - test functions
- - test classes
- - generative tests
- - test driven development
- - setup and teardown test state
- - skipping tests
- - doctests
+
+- test functions
+- test classes
+- generative tests
+- test driven development
+- setup and teardown test state
+- skipping tests
+- doctests
Structure of Tutorial (II)
==========================
writing and using extensions:
- - conftest.py mechanism
- - test collection hooks
- - test running hooks
- - existing extensions: control collection, ReST tests, HTML
- generation, run prolog tests, run javascript tests
+
+- conftest.py mechanism
+- test collection hooks
+- test running hooks
+- existing extensions: control collection, ReST tests, HTML
+ generation, run prolog tests, run javascript tests
First: Install py.test
============================
install "py.test" (see http://pylib.org):
- - via "easy_install -U py"
- - via download and "python setup.py install"
- - via svn and adding py/bin to system $PATH
- - works on python 2.3-2.6, windows, linux, osx
+
+- via "easy_install -U py"
+- via download and "python setup.py install"
+- via svn and adding py/bin to system $PATH
+- works on python 2.3-2.6, windows, linux, osx
Write and run basic tests
===================================
example from ``py/path/local/testing/test_local.py``::
- def test_pypkgdir():
- datadir = py.test.ensuretemp("pypkgdir")
- pkg = datadir.ensure('pkg1', dir=1)
- pkg.ensure("__init__.py")
- pkg.ensure("subdir/__init__.py")
- assert pkg.pypkgpath() == pkg
- assert pkg.join('subdir', '__init__.py').pypkgpath() == pkg
+ def test_pypkgdir():
+ datadir = py.test.ensuretemp("pypkgdir")
+ pkg = datadir.ensure('pkg1', dir=1)
+ pkg.ensure("__init__.py")
+ pkg.ensure("subdir/__init__.py")
+ assert pkg.pypkgpath() == pkg
+ subinit = pkg.join('subdir', '__init__.py')
+ assert subinit.pypkgpath() == pkg
+
Putting tests in Test Classes
==================================
example from ``py/path/local/testing/test_local.py``::
- class TestExecutionOnWindows(LocalSetup):
- disabled = py.std.sys.platform != 'win32'
+ class TestExecutionOnWindows(LocalSetup):
+ disabled = py.std.sys.platform != 'win32'
+
+ def test_sysfind(self):
+ x = py.path.local.sysfind('cmd')
+ assert x.check(file=1)
+ x = py.path.local.sysfind('jaksdkasldqwe')
+ assert x is None
- def test_sysfind(self):
- x = py.path.local.sysfind('cmd')
- assert x.check(file=1)
- assert py.path.local.sysfind('jaksdkasldqwe') is None
observations and notes
========================
@@ -134,14 +141,14 @@
let's revisit the above ``test_local.py``:
- class LocalSetup:
- def setup_class(cls):
- cls.root = py.test.ensuretemp(cls.__name__)
- cls.root.ensure(dir=1)
- setuptestfs(cls.root)
+ class LocalSetup:
+ def setup_class(cls):
+ cls.root = py.test.ensuretemp(cls.__name__)
+ cls.root.ensure(dir=1)
+ setuptestfs(cls.root)
- def setup_method(self, method):
- self.tmpdir = self.root.mkdir(method.__name__)
+ def setup_method(self, method):
+ self.tmpdir = self.root.mkdir(method.__name__)
Skipping tests
@@ -149,10 +156,10 @@
Sometimes you need to skip test, use ``py.test.skip``::
- class TestSomeClass:
- def setup_class(cls):
- if sys.platform == "win32":
- py.test.skip("posix platform required")
+ class TestSomeClass:
+ def setup_class(cls):
+ if sys.platform == "win32":
+ py.test.skip("win32 required")
you can also place such calls to "py.test.skip()" inside test functions
or in other test setup functions.
@@ -178,7 +185,6 @@
- add command line options
- influence the collection process
- for debugging::
-
py.test --collectonly
py.test --traceconfig
@@ -186,34 +192,23 @@
Important Internal Objects
==================================
-**Session**: iterates over (custom) collection tree, executes
+- **Session**: iterates over (custom) collection tree, executes
tests and reports outcomes.
+- **Directory** collect files in directory
+- **Module** collect python Classes and Functions
+- **Class**/**Instance** collect test methods
+- **Generator** collect generative tests
+- **Function** sets up and executes a python test function
+- **DoctestFile** collect doctests in a .txt file
-Collection Nodes ("py.test.collect.*"):
-
-**Directory**: collect files
-
-**Module**: collect test Classes and Functions
-
-**Class**/**Instance**: collect test methods
-
-**DoctestFile**: collect doctest of a .txt file
-
-**Generator**: collect generative tests
-
-***Function***: sets up and executes a python test function
-
-The collection process
+The collection tree
===========================
-collection process forms a tree:
- - leaves: so called "items", e.g. ``py.test.collect.Function``
- - nodes: so called "collectors" contain further collectors or items
- - collection tree is built iterativels
-
-test collection usually starts from directories or files
-
-**dynamic lookup of Collector/Item class from conftest.py files**
+- leaves: so called "items", e.g. ``py.test.collect.Function``
+- nodes: so called "collectors" contain further collectors or items
+- collection tree is built iterativels
+- test collection usually starts from directories or files
+- **dynamic lookup in conftest.py files**
Example conftest.py: control directory traversal
===================================================
@@ -333,129 +328,3 @@
http://pylib.org http://pytest.org
http://merlinux.eu - holger at merlinux.de
https://codespeak.net/svn/py/extradoc/talk/ep2008/pytest.txt
-
-
-ad-hoc distribution of tests
-===================================
-
-``py.test --dist`` sends tests to remote places
-or multiple processors
-
-- for each host:
-
- - setup (ssh) connection
- - sync local source code to remote place
- - trigger running of (isolated) tests
-
-ad-hoc distribution of tests (2)
-=====================================
-
-- synchronise source code "1 -> N" simultaneously
-
-- uses py.execnet:
-
- - can connect e.g. via SSH
- - expects plain Python executable on remote side
- - no need to pre-install other software remotely
-
-cross-platform testing
-=============================
-
-- test run on linux, test execution on windows
-- uses py.execnet (same technique as "--dist")
-- works well with "--looponfailing"
-
-status cross-platform/distributed testing
-==============================================
-
-- should basically work for any project
-- gives full tracebacks, most options work
-
-todo:
-
-- make introspection/pdb work
-- use ``screen`` for access to failed tests
-- accellerate py.execnet setup
-- more unification among testing modes
-
-collect info about functions (apigen)
-=============================================
-
-- collect function signatures (via settrace)
-- track input values/types, stacktraces, return values
-- web page with rich automatically produced information
-- TODO: decoupling of collecting info and generating html
-
-doctests
-==============
-
-- basically work (automatically collected from text files)
-- uses 2.5's doctest module
-- needs more fine-grained integration
-
-Unifying Test Reporting
-=================================
-
-py.test contains two approaches for processing test results:
-
-- "old style": methods invoked on session object
-- "new style": reporting events are sent to Reporter object
-
-next:
-
-- use reporting event architecture pervasively
-- refactor existing reporting extensions
-
-py.test extensions (conftest)
-=================================
-
-- all conftest.py files are considered in traversed directories
-- can extend/modify testing process in arbitrary ways
-- however:
-
- - often requires too much knowledge of internal architecture
- - no convention for organising shared test support code
-
-- ergo: introduce mechanism to share test support code / plugins
-
-
-Platform support
-======================
-
-- py lib works on linux, freebsd, windows and OSX, ...
-- works on python 2.3, 2.4, 2.5
-- py lib provides doctest/optparse/... unified compat modules
-- todo: improve and automate packaging/installation
-
-test networks
-==================
-
-- currently model for 1:1 process-to-process
-- "A <-> B and B <-> C" connections do not imply "A <-> C"
-- fix that!
-- then: manage (large) network of test hosts
-- select set of test deployment hosts by platform, load
-- have modes for testing on several platforms at once
-
-difference to "buildbot" ...
-==================================
-
-- py.test generally works from developers WC
-- no need to first commit and wait for later (nightly) test run
-- developer's choice of test setting
-- more interactivity
-
-summary development topics
-=============================
-
-- refactor/unify reporting mechanisms
-- introduce shared test support code (plugins)
-- improve py.execnet (towards networks)
-- interactive debugging / introspection everywhere
-- systematically persist test results
-
-Goal
-=============
-
-Maximize fun and efficiency of (test-driven) development
-
Added: py/extradoc/talk/pycon-uk-2008/rst2beamer.py
==============================================================================
--- (empty file)
+++ py/extradoc/talk/pycon-uk-2008/rst2beamer.py Fri Sep 5 13:58:53 2008
@@ -0,0 +1,170 @@
+#!/usr/bin/env python
+# encoding: utf-8
+"""
+A docutils script converting restructured text into Beamer-flavoured LaTeX.
+
+Beamer is a LaTeX document class for presentations. Via this script, ReST can
+be used to prepare slides. It can be called::
+
+ rst2beamer.py infile.txt > outfile.tex
+
+where ``infile.tex`` contains the produced Beamer LaTeX.
+
+See <http:www.agapow.net/programming/python/rst2beamer> for more details.
+
+"""
+# TODO: modifications for handout sections?
+# TOOD: sections and subsections?
+# TODO: enable beamer themes?
+# TODO: convert document metadata to front page fields?
+# TODO: toc-conversion?
+# TODO: fix descriptions
+
+# Unless otherwise stated, created by P-M Agapow on 2007-08-21
+# and open for academic & non-commercial use and modification .
+
+__docformat__ = 'restructuredtext en'
+__author__ = "Paul-Michael Agapow <agapow at bbsrc.ac.uk>"
+__version__ = "0.2"
+
+
+### IMPORTS ###
+
+import locale
+from docutils.core import publish_cmdline, default_description
+from docutils.writers.latex2e import Writer as Latex2eWriter
+from docutils.writers.latex2e import LaTeXTranslator, DocumentClass
+from docutils import nodes
+
+## CONSTANTS & DEFINES: ###
+
+BEAMER_SPEC = (
+ 'Beamer options',
+ 'These are derived almost entirely from the LaTeX2e options',
+ tuple (
+ [
+ (
+ 'Specify theme.',
+ ['--theme'],
+ {'default': '', }
+ ),
+ (
+ 'Specify document options. Multiple options can be given, '
+ 'separated by commas. Default is "10pt,a4paper".',
+ ['--documentoptions'],
+ {'default': '', }
+ ),
+ ] + list (Latex2eWriter.settings_spec[2][2:])
+ ),
+)
+
+BEAMER_DEFAULTS = {
+ 'output_encoding': 'latin-1',
+ 'documentclass': 'beamer',
+}
+
+
+### IMPLEMENTATION ###
+
+try:
+ locale.setlocale (locale.LC_ALL, '')
+except:
+ pass
+
+class BeamerTranslator (LaTeXTranslator):
+ """
+ A converter for docutils elements to beamer-flavoured latex.
+ """
+
+ def __init__ (self, document):
+ LaTeXTranslator.__init__ (self, document)
+ self.head_prefix = [x for x in self.head_prefix if ('{typearea}' not in x)]
+ hyperref_posn = [i for i in range (len (self.head_prefix)) if ('{hyperref}' in self.head_prefix[i])]
+ self.head_prefix[hyperref_posn[0]] = '\\usepackage{hyperref}\n'
+ self.head_prefix.extend ([
+ '\\definecolor{rrblitbackground}{rgb}{0.55, 0.3, 0.1}\n',
+ '\\newenvironment{rtbliteral}{\n',
+ '\\begin{ttfamily}\n',
+ '\\color{rrblitbackground}\n',
+ '}{\n',
+ '\\end{ttfamily}\n',
+ '}\n',
+ ])
+ # this fixes the hardcoded section titles in docutils 0.4
+ self.d_class = DocumentClass ('article')
+
+ def begin_frametag (self):
+ return '\\begin{frame}\n'
+
+ def end_frametag (self):
+ return '\\end{frame}\n'
+
+ def visit_section (self, node):
+ if (self.section_level == 0):
+ self.body.append (self.begin_frametag())
+ LaTeXTranslator.visit_section (self, node)
+
+ def depart_section (self, node):
+ # Remove counter for potential subsections:
+ LaTeXTranslator.depart_section (self, node)
+ if (self.section_level == 0):
+ self.body.append (self.end_frametag())
+
+ def visit_title (self, node):
+ if (self.section_level == 1):
+ self.body.append ('\\frametitle{%s}\n\n' % self.encode(node.astext()))
+ raise nodes.SkipNode
+ else:
+ LaTeXTranslator.visit_title (self, node)
+
+ def depart_title (self, node):
+ if (self.section_level != 1):
+ LaTeXTranslator.depart_title (self, node)
+
+ def visit_literal_block(self, node):
+ if not self.active_table.is_open():
+ self.body.append('\n\n\\smallskip\n\\begin{rtbliteral}\n')
+ self.context.append('\\end{rtbliteral}\n\\smallskip\n\n')
+ else:
+ self.body.append('\n')
+ self.context.append('\n')
+ if (self.settings.use_verbatim_when_possible and (len(node) == 1)
+ # in case of a parsed-literal containing just a "**bold**" word:
+ and isinstance(node[0], nodes.Text)):
+ self.verbatim = 1
+ self.body.append('\\begin{verbatim}\n')
+ else:
+ self.literal_block = 1
+ self.insert_none_breaking_blanks = 1
+
+ def depart_literal_block(self, node):
+ if self.verbatim:
+ self.body.append('\n\\end{verbatim}\n')
+ self.verbatim = 0
+ else:
+ self.body.append('\n')
+ self.insert_none_breaking_blanks = 0
+ self.literal_block = 0
+ self.body.append(self.context.pop())
+
+
+class BeamerWriter (Latex2eWriter):
+ """
+ A docutils writer that modifies the translator and settings for beamer.
+ """
+ settings_spec = BEAMER_SPEC
+ settings_defaults = BEAMER_DEFAULTS
+
+ def __init__(self):
+ Latex2eWriter.__init__(self)
+ self.translator_class = BeamerTranslator
+
+
+if __name__ == '__main__':
+ description = (
+ "Generates Beamer-flavoured LaTeX for PDF-based presentations." + default_description)
+ publish_cmdline (writer=BeamerWriter(), description=description)
+
+
+### END ######################################################################
+
Added: py/extradoc/talk/pycon-uk-2008/stylesheet.latex
==============================================================================
--- (empty file)
+++ py/extradoc/talk/pycon-uk-2008/stylesheet.latex Fri Sep 5 13:58:53 2008
@@ -0,0 +1,10 @@
+\usetheme{Boadilla}
+\setbeamercovered{transparent}
+\setbeamertemplate{navigation symbols}{}
+
+\definecolor{darkgreen}{rgb}{0, 0.5, 0.0}
+\newcommand{\docutilsrolegreen}[1]{\color{darkgreen}#1\normalcolor}
+\newcommand{\docutilsrolered}[1]{\color{red}#1\normalcolor}
+
+\newcommand{\green}[1]{\color{darkgreen}#1\normalcolor}
+\newcommand{\red}[1]{\color{red}#1\normalcolor}
More information about the pytest-commit
mailing list