From d4be8d773860a025d7e94f6905171ac258b1ad05 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Fri, 26 Jul 2013 11:25:07 -0700 Subject: [PATCH] Document rules --- README.rst | 16 ++++++++++++++++ quickunit/plugin.py | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/README.rst b/README.rst index 2c578b7..2c8368b 100644 --- a/README.rst +++ b/README.rst @@ -39,3 +39,19 @@ Or, if you'd prefer, via ``setup.cfg``:: quickunit-prefix = tests/unit tests/integration quickunit-rule = tests/{path}/test_{filename} + +Rules +----- + +Rules are a combination of simple formatting a regular expressions. + +The following formatted variables are available within a rule: + +{path} + The base path of the filename (e.g. foo/bar) +{filename} + The filename excluding the path (e.g. baz.py) +{basename} + The filename excluding the extension (e.g. baz) + +A rule is first formatted (using ``.format(params)``) and then compiled into a regular expression on top of each changed file. diff --git a/quickunit/plugin.py b/quickunit/plugin.py index e6d7c77..85710f7 100644 --- a/quickunit/plugin.py +++ b/quickunit/plugin.py @@ -54,9 +54,13 @@ def compile(self): path, filename = filepath.rsplit('/', 1) except ValueError: path, filename = '', filepath + + basename = filename.rsplit('.', 1)[0] + params = { 'path': path, 'filename': filename, + 'basename': basename, } for rule in self.rules: rules.append(re.compile(rule.format(**params)))