git @ Cat's Eye Technologies Falderal / support-python-3
Doctests will need rewriting, but harnessed tests pass in Python3. Chris Pressey 1 year, 11 months ago
3 changed file(s) with 57 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
8181 return 1
8282
8383 if options.dump:
84 print "Functionalities:"
84 print("Functionalities:")
8585 for name in functionalities:
86 print " " + name
86 print(" " + name)
8787 for implementation in functionalities[name].implementations:
88 print " +-" + str(implementation)
89 print "Tests:"
88 print(" +-" + str(implementation))
89 print("Tests:")
9090 for test in tests:
91 print " " + str(test)
91 print(" " + str(test))
9292 return 0
9393
9494 # run tests
9898 try:
9999 for test in tests:
100100 if options.verbose:
101 print str(test)
101 print(str(test))
102102 these_results = test.run(options=options)
103103 if options.verbose:
104104 for result in these_results:
115115 if options.verbose:
116116 for key in dup_check:
117117 if len(dup_check[key]) != 1:
118 print "WARNING: test/impl combination %s was run %d times %r" % (
118 print("WARNING: test/impl combination %s was run %d times %r" % (
119119 key, len(dup_check[key]), dup_check[key]
120 )
120 ))
121121
122122 # report on results
123123 for result in results:
125125 num_results = len(results)
126126 num_failures = len([x for x in results if not x.is_successful()])
127127 if not all_ran:
128 print '**************************************************************'
129 print '** TESTING TERMINATED PREMATURELY -- NOT ALL TESTS WERE RUN **'
130 print '**************************************************************'
128 print('**************************************************************')
129 print('** TESTING TERMINATED PREMATURELY -- NOT ALL TESTS WERE RUN **')
130 print('**************************************************************')
131131
132 print '--------------------------------'
133 print 'Total test runs: %d, failures: %d' % (num_results, num_failures)
134 print '--------------------------------'
132 print('--------------------------------')
133 print('Total test runs: %d, failures: %d' % (num_results, num_failures))
134 print('--------------------------------')
135135
136136 if num_failures == 0:
137137 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
5157
5258
5359 class OutputOutcome(Outcome):
54 def __unicode__(self):
60 def __str__(self):
5561 return u'output:\n' + self.text
5662
5763
5864 class ErrorOutcome(Outcome):
59 def __unicode__(self):
65 def __str__(self):
6066 return u'error:\n' + self.text
6167
6268
118124 def short_description(self):
119125 return 'expected %r, got %r' % (self.test.expectation, self.actual)
120126
127 def fmt(self, field, contents):
128 if str == unicode: # Python 3
129 if isinstance(contents, bytes):
130 contents = contents.decode('utf-8')
131 s = field + contents
132 print(s)
133 else: # Python 2
134 s = field + contents
135 print(s)
136
121137 def report(self):
122 print "FAILED : " + self.format_text_block(self.test.description)
123 print "Location: " + self.test.body_block.location()
124 print "Function: " + self.format_text_block(self.test.functionality.name)
125 print "Impl : " + self.format_text_block(self.implementation)
126 print "Body : " + self.format_text_block(self.test.body)
127 #if input is not None:
128 #print "Input : " + self.format_text_block(self.test.input)
129 print "Expected: " + self.format_text_block(self.test.expectation)
130 print "Actual : " + self.format_text_block(self.actual)
131 print
138 self.fmt("FAILED : ", self.format_text_block(self.test.description))
139 self.fmt("Location: ", self.test.body_block.location())
140 self.fmt("Function: ", self.format_text_block(self.test.functionality.name))
141 self.fmt("Impl : ", self.format_text_block(self.implementation))
142 self.fmt("Body : ", self.format_text_block(self.test.body))
143 self.fmt("Expected: ", self.format_text_block(self.test.expectation))
144 self.fmt("Actual : ", self.format_text_block(self.actual))
145 print("")
132146
133147 def is_successful(self):
134148 return False
203217 u'??> ': u'? ',
204218 u'???> ': u'? ',
205219 }
206 FREESTYLE_PREFIXES = FREESTYLE_MAP.keys()
220 FREESTYLE_PREFIXES = list(FREESTYLE_MAP.keys())
207221 PREFIXES = FREESTYLE_PREFIXES + [
208222 u'| ',
209223 u'+ ',
235249 self.__class__.__name__, self.line_num, filename_repr
236250 )
237251
238 def __unicode__(self):
252 def __str__(self):
239253 return unicode(repr(self))
240254
241255 def location(self):
665679 def __repr__(self):
666680 return "Functionality(%r)" % self.name
667681
668 def __unicode__(self):
682 def __str__(self):
669683 return unicode(repr(self))
670684
671685 def add_implementation(self, implementation):
700714 def __repr__(self):
701715 return '%s(%r)' % (self.__class__.__name__, self.callable)
702716
703 def __unicode__(self):
717 def __str__(self):
704718 return u'callable "%r"' % self.callable
705719
706720 def run(self, body=None, input=None):
718732 def __repr__(self):
719733 return '%s(%r)' % (self.__class__.__name__, self.command)
720734
721 def __unicode__(self):
735 def __str__(self):
722736 return u'shell command "%s"' % self.command
723737
724738 def run(self, body=None, input=None):
845859 return result
846860
847861 def normalize_output(self, text):
848 text = text.decode('UTF-8', errors='ignore')
862 try:
863 text = text.decode('UTF-8', errors='ignore')
864 except AttributeError:
865 pass
849866 text = re.sub(r'\r\n', '\n', text)
850867 return text.strip('\r\n')
851868
11
22 # Really crude test harness for py-falderal itself...
33
4 bin/falderal -v -t || exit 1
4 FALDERAL="python2 ../bin/falderal"
55
66 cd tests
7
8 #$FALDERAL -v -t || exit 1
79
810 FIRST_TESTS="
911 test-pass-fail test-no-functionality test-ill-formed test-no-test-body
1618 "
1719 for TEST in ${FIRST_TESTS}; do
1820 echo ${TEST}...
19 ../bin/falderal --cavalier ${TEST}.markdown > ${TEST}.actual 2>&1
21 $FALDERAL --cavalier ${TEST}.markdown > ${TEST}.actual 2>&1
2022 diff -u ${TEST}.expected ${TEST}.actual || exit 1
2123 done
2224
2426 LINTING_TESTS="test-no-tests"
2527 for TEST in ${LINTING_TESTS}; do
2628 echo ${TEST}...
27 ../bin/falderal ${TEST}.markdown > ${TEST}.actual 2>&1
29 $FALDERAL ${TEST}.markdown > ${TEST}.actual 2>&1
2830 diff -u ${TEST}.expected ${TEST}.actual || exit 1
2931 done
3032
3335 "
3436 for TEST in ${TWO_PART_TESTS}; do
3537 echo ${TEST}...
36 ../bin/falderal ${TEST}-a.markdown ${TEST}-b.markdown > ${TEST}.actual 2>&1
38 $FALDERAL ${TEST}-a.markdown ${TEST}-b.markdown > ${TEST}.actual 2>&1
3739 diff -u ${TEST}.expected ${TEST}.actual || exit 1
3840 done
3941
4042 # special tests: -b
4143 TEST=test-substring-error
4244 echo ${TEST}...
43 ../bin/falderal -b ${TEST}.markdown > ${TEST}.actual 2>&1
45 $FALDERAL -b ${TEST}.markdown > ${TEST}.actual 2>&1
4446 diff -u ${TEST}.expected ${TEST}.actual || exit 1
4547
4648 rm -f *.actual