summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis Hildebrandt <afh@surryhill.net>2015-02-20 14:07:57 +0100
committerAlexis Hildebrandt <afh@surryhill.net>2015-02-20 14:07:57 +0100
commitc1e409e6934ba298cc71dfb7c6a0079d2038b09d (patch)
tree9a0210bc2da87f4174f896ceb7b0775ecc4b580a
parent34f8c482414775cfb75de32b4181150642a4610d (diff)
downloadfork-ledger-c1e409e6934ba298cc71dfb7c6a0079d2038b09d.tar.gz
fork-ledger-c1e409e6934ba298cc71dfb7c6a0079d2038b09d.tar.bz2
fork-ledger-c1e409e6934ba298cc71dfb7c6a0079d2038b09d.zip
[doc] Add support for additional input files
in test/DocTests.py by allowing file: and with_file: options on examples.
-rw-r--r--doc/ledger3.texi13
-rwxr-xr-xtest/DocTests.py14
2 files changed, 25 insertions, 2 deletions
diff --git a/doc/ledger3.texi b/doc/ledger3.texi
index 3caf4d14..ea4c0e89 100644
--- a/doc/ledger3.texi
+++ b/doc/ledger3.texi
@@ -88,6 +88,19 @@
@c $ 36.84 Expenses:Food:Dining
@c @end smallexample
@c
+@c To pass additional input to ledger for certain commands, e.g. convert add
+@c with_file:filename to the example command and add a file:UUID to an example
+@c that holds the additional input, where UUID is the UUID of the command,
+@c e.g.:
+@c
+@c @smallexample @c file:download.csv
+@c 767718,12/13/2011,"Withdrawal","ACE HARDWARE 16335 S HOUGHTON RD",-8.80,,00001640.04,,
+@c @end smallexample
+@c
+@c @smallexample @c command:94FD2B6,with_file:download.csv
+@c $ ledger -f sample.dat convert download.csv
+@c @end smallexample
+@c
@c Additionally DocTests.py will pass --args-only and --columns 80 to ledger
@c to ignore any default arguments from the environment or .ledgerrc.
@c
diff --git a/test/DocTests.py b/test/DocTests.py
index 6f0276da..f5746ec4 100755
--- a/test/DocTests.py
+++ b/test/DocTests.py
@@ -24,10 +24,12 @@ class DocTests:
self.testin_token = 'command'
self.testout_token = 'output'
self.testdat_token = 'input'
+ self.testfile_token = 'file'
self.validate_token = 'validate'
self.validate_cmd_token = 'validate-command'
self.validate_dat_token = 'validate-data'
self.testwithdat_token = 'with_input'
+ self.testwithfile_token = 'with_file'
def read_example(self):
endexample = re.compile(r'^@end\s+smallexample\s*$')
@@ -44,8 +46,8 @@ class DocTests:
return hashlib.sha1(example.rstrip()).hexdigest()[0:7].upper()
def find_examples(self):
- startexample = re.compile(r'^@smallexample\s+@c\s+(%s|%s|%s)(?::([\dA-Fa-f]+|validate))?(?:,(.*))?'
- % (self.testin_token, self.testout_token, self.testdat_token))
+ startexample = re.compile(r'^@smallexample\s+@c\s+(%s|%s|%s|%s)(?::([\dA-Fa-f]+|validate))?(?:,(.*))?'
+ % (self.testin_token, self.testout_token, self.testdat_token, self.testfile_token))
while True:
line = self.file.readline()
self.current_line += 1
@@ -187,6 +189,14 @@ class DocTests:
elif os.path.exists(os.path.join(test_input_dir, test_file)):
command[findex] = os.path.join(test_input_dir, test_file)
try:
+ convert_idx = command.index('convert')
+ convert_file = command[convert_idx+1]
+ convert_data = example[self.testfile_token][self.testfile_token]
+ if not os.path.exists(convert_file):
+ with open(convert_file, 'w') as f:
+ f.write(convert_data)
+ except ValueError:
+ pass
error = None
try:
verify = subprocess.check_output(command, stderr=subprocess.STDOUT)