summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCraig Earls <enderw88@gmail.com>2015-02-25 22:01:33 -0700
committerCraig Earls <enderw88@gmail.com>2015-02-25 22:01:33 -0700
commit1f803d629491991afb8aa9cd1d159313b2af78c7 (patch)
tree4eb6f0f90162f4808d0687a06ad1a698eb3ed035 /test
parentfe48f607be7b9da8d2c4ac1fb30078dea55b8240 (diff)
parentaf0da737fc4ef8f9ccebd3d43519610b8a8fcaa1 (diff)
downloadfork-ledger-1f803d629491991afb8aa9cd1d159313b2af78c7.tar.gz
fork-ledger-1f803d629491991afb8aa9cd1d159313b2af78c7.tar.bz2
fork-ledger-1f803d629491991afb8aa9cd1d159313b2af78c7.zip
Merge commit 'af0da737fc4ef8f9ccebd3d43519610b8a8fcaa1' into next
Conflicts: lisp/ledger-reconcile.el
Diffstat (limited to 'test')
-rwxr-xr-xtest/CheckBaselineTests.py9
-rwxr-xr-xtest/DocTests.py97
-rw-r--r--test/baseline/cmd-cleared.test2
-rw-r--r--test/baseline/opt-auto-match.test47
-rw-r--r--test/baseline/opt-init-file.dat1
-rw-r--r--test/baseline/opt-init-file.test10
-rw-r--r--test/baseline/opt-price-db.dat2
-rw-r--r--test/baseline/opt-price-db.test8
-rw-r--r--test/baseline/opt-rich-data.test10
-rw-r--r--test/baseline/opt-script.dat3
-rw-r--r--test/baseline/opt-script.test15
11 files changed, 149 insertions, 55 deletions
diff --git a/test/CheckBaselineTests.py b/test/CheckBaselineTests.py
index 3c3e590b..8c51ddef 100755
--- a/test/CheckBaselineTests.py
+++ b/test/CheckBaselineTests.py
@@ -21,25 +21,18 @@ class CheckBaselineTests (CheckOptions):
self.untested_options = [
'anon',
'args-only',
- 'cache',
'debug',
'download',
'file',
'force-color',
'force-pager',
- 'full-help',
'help',
- 'help-calc',
- 'help-comm',
- 'help-disp',
'import',
- 'init-file',
'no-color',
+ 'no-pager'
'options',
- 'price-db',
'price-exp',
'revalued-total',
- 'script',
'seed',
'trace',
'verbose',
diff --git a/test/DocTests.py b/test/DocTests.py
index cbad9ca7..ac681bc2 100755
--- a/test/DocTests.py
+++ b/test/DocTests.py
@@ -19,13 +19,17 @@ class DocTests:
self.verbose = args.verbose
self.tests = args.examples
- self.examples = dict()
- self.test_files = list()
- self.testin_token = 'command'
- self.testout_token = 'output'
- self.testdat_token = 'input'
+ self.examples = dict()
+ self.test_files = list()
+ self.testin_token = 'command'
+ self.testout_token = 'output'
+ self.testdat_token = 'input'
+ self.testfile_token = 'file'
self.validate_token = 'validate'
- self.testwithdat_token = 'with_input'
+ 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*$')
@@ -35,15 +39,15 @@ class DocTests:
self.current_line += 1
if len(line) <= 0 or endexample.match(line): break
# Replace special texinfo character sequences with their ASCII counterpart
- example += line.replace("@@","@").replace("@{","{").replace("@}","}")
+ example += re.sub(r'@([@{}])', r'\1', line)
return example
def test_id(self, example):
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
@@ -78,9 +82,9 @@ class DocTests:
if test_id == self.validate_token:
test_id = "Val-" + str(test_begin_line)
if test_kind == self.testin_token:
- test_kind = "validate-command"
+ test_kind = self.validate_cmd_token
elif test_kind == self.testdat_token:
- test_kind = "validate-data"
+ test_kind = self.validate_dat_token
try:
self.examples[test_id]
except KeyError:
@@ -105,15 +109,15 @@ class DocTests:
try:
command = example[self.testin_token][self.testin_token]
except KeyError:
- if 'validate-data' in example:
+ if self.validate_dat_token in example:
command = '$ ledger bal'
- elif 'validate-command' in example:
+ elif self.validate_cmd_token in example:
validate_command = True
- command = example['validate-command']['validate-command']
+ command = example[self.validate_cmd_token][self.validate_cmd_token]
else:
return None
- command = shlex.split(command)
+ command = filter(lambda x: x != '\n', shlex.split(command))
if command[0] == '$': command.remove('$')
index = command.index('ledger')
command[index] = self.ledger
@@ -145,7 +149,7 @@ class DocTests:
for test_id in tests:
validation = False
- if "validate-data" in self.examples[test_id] or "validate-command" in self.examples[test_id]:
+ if self.validate_dat_token in self.examples[test_id] or self.validate_cmd_token in self.examples[test_id]:
validation = True
example = self.examples[test_id]
try:
@@ -154,51 +158,52 @@ class DocTests:
failed.add(test_id)
continue
- try:
- output = example[self.testout_token][self.testout_token]
- except KeyError:
- output = None
-
- try:
- input = example[self.testdat_token][self.testdat_token]
- except KeyError:
- try:
- with_input = example[self.testin_token]['opts'][self.testwithdat_token]
- input = self.examples[with_input][self.testdat_token][self.testdat_token]
- except KeyError:
- try:
- input = example['validate-data']['validate-data']
- except KeyError:
- input = None
+ output = example.get(self.testout_token, {}).get(self.testout_token)
+ input = example.get(self.testdat_token, {}).get(self.testdat_token)
+ if not input:
+ with_input = example.get(self.testin_token, {}).get('opts', {}).get(self.testwithdat_token)
+ input = self.examples.get(with_input, {}).get(self.testdat_token, {}).get(self.testdat_token)
+ if not input:
+ input = example.get(self.validate_dat_token, {}).get(self.validate_dat_token)
- if command and (output or validation):
+ if command and (output != None or validation):
test_file_created = False
if findex:
scriptpath = os.path.dirname(os.path.realpath(__file__))
- test_input_dir = scriptpath + '/../test/input/'
+ test_input_dir = os.path.join(scriptpath, '..', 'test', 'input')
test_file = command[findex]
if not os.path.exists(test_file):
if input:
test_file_created = True
with open(test_file, 'w') as f:
f.write(input)
- elif os.path.exists(test_input_dir + test_file):
- command[findex] = test_input_dir + test_file
- error = False
+ 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)
- except:
- verify = str()
- error = True
- valid = (output == verify) or (not error and validation)
+ valid = (output == verify) or (not error and validation)
+ except subprocess.CalledProcessError, e:
+ error = e.output
+ valid = False
+ failed.add(test_id)
if valid and test_file_created:
os.remove(test_file)
if self.verbose > 0:
- print test_id, ':', 'Passed' if valid else 'FAILED'
+ print test_id, ':', 'Passed' if valid else 'FAILED: {}'.format(error) if error else 'FAILED'
else:
sys.stdout.write('.' if valid else 'E')
- if not valid:
+ if not (valid or error):
failed.add(test_id)
if self.verbose > 1:
print ' '.join(command)
@@ -206,6 +211,12 @@ class DocTests:
for line in unified_diff(output.split('\n'), verify.split('\n'), fromfile='generated', tofile='expected'):
print(line)
print
+ else:
+ if self.verbose > 0:
+ print test_id, ':', 'Skipped'
+ else:
+ sys.stdout.write('X')
+
if not self.verbose:
print
if len(failed) > 0:
diff --git a/test/baseline/cmd-cleared.test b/test/baseline/cmd-cleared.test
index 501d207f..91219a40 100644
--- a/test/baseline/cmd-cleared.test
+++ b/test/baseline/cmd-cleared.test
@@ -30,7 +30,7 @@ test cleared
-20 0 F
-30 -30 12-Feb-26 G
-40 0 H
----------------- ---------------- ---------
+---------------- ---------------- ---------
0 0
end test
diff --git a/test/baseline/opt-auto-match.test b/test/baseline/opt-auto-match.test
index 7c3fb40a..54a1053b 100644
--- a/test/baseline/opt-auto-match.test
+++ b/test/baseline/opt-auto-match.test
@@ -14,17 +14,58 @@
Expenses:Food 20.00 EUR
Liabilities:CC -20.00 EUR
+test --input-date-format "%Y-%m-%d" convert test/baseline/opt-auto-match.dat
+2012/03/01 * Food
+ Expenses:Unknown 10
+ Equity:Unknown
+
+2012/03/02 * Phone
+ Expenses:Unknown 10
+ Equity:Unknown
+
+2012/03/02 * Dining
+ Expenses:Unknown 10
+ Equity:Unknown
+end test
+
test --input-date-format "%Y-%m-%d" --auto-match convert test/baseline/opt-auto-match.dat
2012/03/01 * Food
- Assets:Cash 10
+ Expenses:Food 10
Equity:Unknown
2012/03/02 * Phone
- Assets:Cash 10
+ Expenses:Phone 10
Equity:Unknown
2012/03/02 * Dining
- Liabilities:CC 10
+ Expenses:Food 10
Equity:Unknown
end test
+test --input-date-format "%Y-%m-%d" --account Assets:Bank convert test/baseline/opt-auto-match.dat
+2012/03/01 * Food
+ Expenses:Unknown 10
+ Assets:Bank
+
+2012/03/02 * Phone
+ Expenses:Unknown 10
+ Assets:Bank
+
+2012/03/02 * Dining
+ Expenses:Unknown 10
+ Assets:Bank
+end test
+
+test --input-date-format "%Y-%m-%d" --auto-match --account Assets:Bank convert test/baseline/opt-auto-match.dat
+2012/03/01 * Food
+ Expenses:Food 10
+ Assets:Bank
+
+2012/03/02 * Phone
+ Expenses:Phone 10
+ Assets:Bank
+
+2012/03/02 * Dining
+ Expenses:Food 10
+ Assets:Bank
+end test
diff --git a/test/baseline/opt-init-file.dat b/test/baseline/opt-init-file.dat
new file mode 100644
index 00000000..92c5307a
--- /dev/null
+++ b/test/baseline/opt-init-file.dat
@@ -0,0 +1 @@
+--decimal-comma
diff --git a/test/baseline/opt-init-file.test b/test/baseline/opt-init-file.test
new file mode 100644
index 00000000..128814e1
--- /dev/null
+++ b/test/baseline/opt-init-file.test
@@ -0,0 +1,10 @@
+2012-03-17 Quick
+ Expenses:Food 12,50 €
+ Assets:Cash
+
+test --init-file test/baseline/opt-init-file.dat bal
+ -12,50 € Assets:Cash
+ 12,50 € Expenses:Food
+--------------------
+ 0
+end test
diff --git a/test/baseline/opt-price-db.dat b/test/baseline/opt-price-db.dat
new file mode 100644
index 00000000..abc51a0a
--- /dev/null
+++ b/test/baseline/opt-price-db.dat
@@ -0,0 +1,2 @@
+P 2012-03-16 06:47:12 CAD $2.50
+P 2012-03-17 06:47:12 CAD $3.50
diff --git a/test/baseline/opt-price-db.test b/test/baseline/opt-price-db.test
new file mode 100644
index 00000000..06021e4a
--- /dev/null
+++ b/test/baseline/opt-price-db.test
@@ -0,0 +1,8 @@
+2012-03-17 KFC
+ Expenses:Food 20 CAD
+ Assets:Cash
+
+test pricedb --price-db test/baseline/opt-price-db.dat
+P 2012/03/16 06:47:12 CAD $2.5
+P 2012/03/17 06:47:12 CAD $3.5
+end test
diff --git a/test/baseline/opt-rich-data.test b/test/baseline/opt-rich-data.test
index fbb73ebe..265af531 100644
--- a/test/baseline/opt-rich-data.test
+++ b/test/baseline/opt-rich-data.test
@@ -1,3 +1,13 @@
+test -f /dev/null convert test/baseline/feat-convert-with-directives.dat --now '2014/08/01'
+2012/01/01 * KFC
+ Expenses:Unknown $10
+ Equity:Unknown
+
+2012/01/02 * REWE SAGT DANKE 123454321
+ Expenses:Unknown 10€
+ Equity:Unknown
+end test
+
test -f /dev/null convert test/baseline/feat-convert-with-directives.dat --detail --now '2014/08/01'
2012/01/01 * KFC
; CSV: 2012/01/01,KFC,$10
diff --git a/test/baseline/opt-script.dat b/test/baseline/opt-script.dat
new file mode 100644
index 00000000..ac6085d5
--- /dev/null
+++ b/test/baseline/opt-script.dat
@@ -0,0 +1,3 @@
+--no-pager --columns=80 bal
+--no-pager --columns=80 reg
+--no-pager --columns=80 print
diff --git a/test/baseline/opt-script.test b/test/baseline/opt-script.test
new file mode 100644
index 00000000..041c15ee
--- /dev/null
+++ b/test/baseline/opt-script.test
@@ -0,0 +1,15 @@
+2012-03-17 KFC
+ Expenses:Food 20 CAD
+ Assets:Cash
+
+test --script test/baseline/opt-script.dat
+ -20 CAD Assets:Cash
+ 20 CAD Expenses:Food
+--------------------
+ 0
+12-Mar-17 KFC Expenses:Food 20 CAD 20 CAD
+ Assets:Cash -20 CAD 0
+2012/03/17 KFC
+ Expenses:Food 20 CAD
+ Assets:Cash
+end test