git @ Cat's Eye Technologies Falderal / f9d0aa7
Support Python 3. Chris Pressey 6 years ago
3 changed file(s) with 60 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
6767 return 1
6868
6969 if options.dump:
70 print "Functionalities:"
70 print("Functionalities:")
7171 for name in functionalities:
72 print " " + name
72 print(" " + name)
7373 for implementation in functionalities[name].implementations:
74 print " +-" + str(implementation)
75 print "Tests:"
74 print(" +-" + str(implementation))
75 print("Tests:")
7676 for test in tests:
77 print " " + str(test)
77 print(" " + str(test))
7878 return 0
7979
8080 # run tests
8484 try:
8585 for test in tests:
8686 if options.verbose:
87 print str(test)
87 print(str(test))
8888 these_results = test.run(options=options)
8989 if options.verbose:
9090 for result in these_results:
101101 if options.verbose:
102102 for key in dup_check:
103103 if len(dup_check[key]) != 1:
104 print "WARNING: test/impl combination %s was run %d times %r" % (
104 print("WARNING: test/impl combination %s was run %d times %r" % (
105105 key, len(dup_check[key]), dup_check[key]
106 )
106 ))
107107
108108 # report on results
109109 for result in results:
111111 num_results = len(results)
112112 num_failures = len([x for x in results if not x.is_successful()])
113113 if not all_ran:
114 print '**************************************************************'
115 print '** TESTING TERMINATED PREMATURELY -- NOT ALL TESTS WERE RUN **'
116 print '**************************************************************'
114 print('**************************************************************')
115 print('** TESTING TERMINATED PREMATURELY -- NOT ALL TESTS WERE RUN **')
116 print('**************************************************************')
117117
118 print '--------------------------------'
119 print 'Total test runs: %d, failures: %d' % (num_results, num_failures)
120 print '--------------------------------'
118 print('--------------------------------')
119 print('Total test runs: %d, failures: %d' % (num_results, num_failures))
120 print('--------------------------------')
121121
122122 if num_failures == 0:
123123 return 0
33 from subprocess import Popen, PIPE
44 from tempfile import mkstemp
55
6 # Note: the __unicode__ method of all the classes defined herein should
6 # Python 2/3
7 try:
8 unicode = unicode
9 except NameError:
10 unicode = str
11
12 # Note: the __str__ method of all the classes defined herein should
713 # produce a short, human-readable summary of the contents of the object,
814 # suitable for displaying in the test results but not necessarily
915 # complete. __repr__ should produce something complete, when it is
5460
5561
5662 class OutputOutcome(Outcome):
57 def __unicode__(self):
63 def __str__(self):
5864 return u'output:\n' + self.text
5965
6066
6167 class ErrorOutcome(Outcome):
62 def __unicode__(self):
68 def __str__(self):
6369 return u'error:\n' + self.text
6470
6571
121127 def short_description(self):
122128 return 'expected %r, got %r' % (self.test.expectation, self.actual)
123129
130 def fmt(self, field, contents):
131 if str == unicode: # Python 3
132 if isinstance(contents, bytes):
133 contents = contents.decode('utf-8')
134 s = field + contents
135 print(s)
136 else: # Python 2
137 s = field + contents
138 print(s)
139
124140 def report(self):
125 print "FAILED : " + self.format_text_block(self.test.description)
126 print "Location: " + self.test.body_block.location()
127 print "Function: " + self.format_text_block(self.test.functionality.name)
128 print "Impl : " + self.format_text_block(self.implementation)
129 print "Body : " + self.format_text_block(self.test.body)
130 #if input is not None:
131 #print "Input : " + self.format_text_block(self.test.input)
132 print "Expected: " + self.format_text_block(self.test.expectation)
133 print "Actual : " + self.format_text_block(self.actual)
134 print
141 self.fmt("FAILED : ", self.format_text_block(self.test.description))
142 self.fmt("Location: ", self.test.body_block.location())
143 self.fmt("Function: ", self.format_text_block(self.test.functionality.name))
144 self.fmt("Impl : ", self.format_text_block(self.implementation))
145 self.fmt("Body : ", self.format_text_block(self.test.body))
146 self.fmt("Expected: ", self.format_text_block(self.test.expectation))
147 self.fmt("Actual : ", self.format_text_block(self.actual))
148 print("")
135149
136150 def is_successful(self):
137151 return False
156170 u'??> ': u'? ',
157171 u'???> ': u'? ',
158172 }
159 FREESTYLE_PREFIXES = FREESTYLE_MAP.keys()
173 FREESTYLE_PREFIXES = list(FREESTYLE_MAP.keys())
160174 PREFIXES = FREESTYLE_PREFIXES + [
161175 u'| ',
162176 u'+ ',
188202 self.__class__.__name__, self.line_num, filename_repr
189203 )
190204
191 def __unicode__(self):
205 def __str__(self):
192206 return unicode(repr(self))
193207
194208 def location(self):
487501 def __repr__(self):
488502 return "Functionality(%r)" % self.name
489503
490 def __unicode__(self):
504 def __str__(self):
491505 return unicode(repr(self))
492506
493507 def add_implementation(self, implementation):
522536 def __repr__(self):
523537 return '%s(%r)' % (self.__class__.__name__, self.callable)
524538
525 def __unicode__(self):
539 def __str__(self):
526540 return u'callable "%r"' % self.callable
527541
528542 def run(self, body=None, input=None):
540554 def __repr__(self):
541555 return '%s(%r)' % (self.__class__.__name__, self.command)
542556
543 def __unicode__(self):
557 def __str__(self):
544558 return u'shell command "%s"' % self.command
545559
546560 def __eq__(self, other):
638652 return result
639653
640654 def normalize_output(self, text):
641 text = text.decode('UTF-8', errors='ignore')
655 try:
656 text = text.decode('UTF-8', errors='ignore')
657 except AttributeError:
658 pass
642659 text = re.sub(r'\r\n', '\n', text)
643660 return text.strip('\r\n')
644661
11
22 # Really crude test harness for py-falderal itself...
33
4 PYTHONPATH=src python src/falderal/tests.py -v || exit 1
4 if [ "x$PYTHON" = "x" ]; then
5 PYTHON="python3"
6 fi
7 FALDERAL="$PYTHON ../bin/falderal"
8
9 PYTHONPATH=src $PYTHON src/falderal/tests.py -v || exit 1
510
611 cd tests
712
1621 "
1722 for TEST in ${FIRST_TESTS}; do
1823 echo ${TEST}...
19 ../bin/falderal --cavalier ${TEST}.markdown > ${TEST}.actual 2>&1
24 $FALDERAL --cavalier ${TEST}.markdown > ${TEST}.actual 2>&1
2025 diff -u ${TEST}.expected ${TEST}.actual || exit 1
2126 done
2227
2429 LINTING_TESTS="test-no-tests"
2530 for TEST in ${LINTING_TESTS}; do
2631 echo ${TEST}...
27 ../bin/falderal ${TEST}.markdown > ${TEST}.actual 2>&1
32 $FALDERAL ${TEST}.markdown > ${TEST}.actual 2>&1
2833 diff -u ${TEST}.expected ${TEST}.actual || exit 1
2934 done
3035
3338 "
3439 for TEST in ${TWO_PART_TESTS}; do
3540 echo ${TEST}...
36 ../bin/falderal ${TEST}-a.markdown ${TEST}-b.markdown > ${TEST}.actual 2>&1
41 $FALDERAL ${TEST}-a.markdown ${TEST}-b.markdown > ${TEST}.actual 2>&1
3742 diff -u ${TEST}.expected ${TEST}.actual || exit 1
3843 done
3944
4045 # special tests: -b
4146 TEST=test-substring-error
4247 echo ${TEST}...
43 ../bin/falderal -b ${TEST}.markdown > ${TEST}.actual 2>&1
48 $FALDERAL -b ${TEST}.markdown > ${TEST}.actual 2>&1
4449 diff -u ${TEST}.expected ${TEST}.actual || exit 1
4550
4651 rm -f *.actual