SyFi  0.3
test_sfc.test_codeformatter.CodeFormattingTest Class Reference

List of all members.

Public Member Functions

def setUp
def test_switch
def test_gen_tokens
def test_functions

Private Member Functions

def _compare_codes

Private Attributes

 _text

Detailed Description

Definition at line 52 of file test_codeformatter.py.


Member Function Documentation

def test_sfc.test_codeformatter.CodeFormattingTest._compare_codes (   self,
  code,
  correct 
) [private]

Definition at line 57 of file test_codeformatter.py.

Referenced by test_sfc.test_codeformatter.CodeFormattingTest.test_functions(), test_sfc.test_codeformatter.CodeFormattingTest.test_gen_tokens(), and test_sfc.test_codeformatter.CodeFormattingTest.test_switch().

00057 
00058     def _compare_codes(self, code, correct):
00059         "Compare codes and print codes if this fails."
00060         if code != correct:
00061             print "Failure, got code:"
00062             print '"""%s"""' % code
00063             print "but expecting:"
00064             print '"""%s"""' % correct
00065         self.assertTrue(code == correct)

Definition at line 54 of file test_codeformatter.py.

00054 
00055     def setUp(self):
00056         pass

Definition at line 111 of file test_codeformatter.py.

References test_sfc.test_codeformatter.CodeFormattingTest._compare_codes().

00111 
00112     def test_functions(self):
00113         code = CodeFormatter()
00114 
00115         name = "myfunction"
00116 
00117         argnames = ["a", "b", "c"]
00118         args = [("double", name, "[3]") for name in argnames]
00119 
00120         code.declare_function(name, args=args, const=True, inline=True)
00121         code.new_line("")
00122 
00123         body = "// Empty body!"
00124         code.define_function(name, args=args, const=True, inline=True, body=body)
00125         code.new_line("")
00126 
00127         code.call_function(name, args=argnames)
00128         code.new_line("")
00129 
00130         code = str(code)
00131 
00132         self._compare_codes(code, functions_result)

Definition at line 84 of file test_codeformatter.py.

References test_sfc.test_codeformatter.CodeFormattingTest._compare_codes(), and test_sfc.test_codeformatter.CodeFormattingTest._text.

00084 
00085     def test_gen_tokens(self):
00086         code = CodeFormatter()
00087         class MockObject:
00088             def __init__(self, text):
00089                 self._text = text
00090             def printc(self):
00091                 return self._text
00092             def __str__(self):
00093                 return self._text
00094         s1 = MockObject("s1")
00095         e1 = MockObject("e1")
00096         s2 = MockObject("s2")
00097         e2 = MockObject("e2")
00098         tokens = [(s1, e1), (s2, e2)]
00099         code.begin_block()
00100         code += gen_token_declarations(tokens)
00101         code.end_block()
00102         code.indent()
00103         code.indent()
00104         code += gen_token_definitions(tokens)
00105         code.dedent()
00106         code += gen_token_definitions(tokens)
00107         code.dedent()
00108         code = str(code)
00109 
00110         self._compare_codes(code, gen_tokens_result)

Definition at line 66 of file test_codeformatter.py.

References test_sfc.test_codeformatter.CodeFormattingTest._compare_codes().

00066 
00067     def test_switch(self):
00068         code = CodeFormatter()
00069         code.begin_switch("facet")
00070         facet_dofs = [(2, 0, 1), (5, 3, 4), (6, 7, 8)]
00071         for i, dofs in enumerate(facet_dofs):
00072             code.begin_case(i)
00073             for j, d in enumerate(dofs):
00074                 code += "dofs[%d] = %d;" % (j, d)
00075             code.end_case()
00076         code += "default:"
00077         code.indent()
00078         code += 'throw std::runtime_error("Invalid facet number.");'
00079         code.dedent()
00080         code.end_switch()
00081         code = str(code)
00082 
00083         self._compare_codes(code, test_switch_result)


Member Data Documentation


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines