def test_templated_input_same_anchors(self): template = '\n'.join( ["CQUAD4 1 3.456", "CQUAD4 2 4.123", "CQUAD4 3 7.222", "CQUAD4 4"]) outfile = open(self.templatename, 'w') outfile.write(template) outfile.close() gen = InputFileGenerator() gen.set_template_file(self.templatename) gen.set_generated_file(self.filename) gen.set_delimiters(', ') gen.mark_anchor('CQUAD4') gen.transfer_var('x', 0, 2) gen.mark_anchor('CQUAD4') gen.transfer_var('y', 0, 3) gen.mark_anchor('CQUAD4', 2) gen.transfer_var('z', 0, 2) gen.generate() infile = open(self.filename, 'r') result = infile.read() infile.close() answer = '\n'.join( ["CQUAD4 x 3.456", "CQUAD4 2 y", "CQUAD4 3 7.222", "CQUAD4 z"]) self.assertEqual(answer, result)
def test_templated_input_same_anchors(self): template = '\n'.join([ "CQUAD4 1 3.456", "CQUAD4 2 4.123", "CQUAD4 3 7.222", "CQUAD4 4" ]) outfile = open(self.templatename, 'w') outfile.write(template) outfile.close() gen = InputFileGenerator() gen.set_template_file(self.templatename) gen.set_generated_file(self.filename) gen.set_delimiters(', ') gen.mark_anchor('CQUAD4') gen.transfer_var('x', 0, 2) gen.mark_anchor('CQUAD4') gen.transfer_var('y', 0, 3) gen.mark_anchor('CQUAD4', 2) gen.transfer_var('z', 0, 2) gen.generate() infile = open(self.filename, 'r') result = infile.read() infile.close() answer = '\n'.join([ "CQUAD4 x 3.456", "CQUAD4 2 y", "CQUAD4 3 7.222", "CQUAD4 z" ]) self.assertEqual(answer, result)
def test_templated_input(self): template = '\n'.join([ "Junk", "Anchor", " A 1, 2 34, Test 1e65", " B 4 Stuff", "Anchor", " C 77 False Inf 333.444" ]) outfile = open(self.templatename, 'w') outfile.write(template) outfile.close() gen = InputFileGenerator() gen.set_template_file(self.templatename) gen.set_generated_file(self.filename) gen.set_delimiters(', ') gen.mark_anchor('Anchor') gen.transfer_var('CC', 2, 0) gen.transfer_var(3.0, 1, 3) gen.reset_anchor() gen.mark_anchor('Anchor', 2) gen.transfer_var('NaN', 1, 4) gen.reset_anchor() gen.transfer_var('55', 3, 2) gen.mark_anchor('C 77') gen.transfer_var(1.3e-37, -3, 6) gen.clearline(-5) gen.mark_anchor('Anchor', -1) gen.transfer_var('8.7', 1, 5) gen.generate() infile = open(self.filename, 'r') result = infile.read() infile.close() answer = '\n'.join([ "", "Anchor", " A 1, 3.0 34, Test 1.3e-37", " B 55 Stuff", "Anchor", " C 77 False NaN 8.7" ]) self.assertEqual(answer, result) # Test some errors try: gen.mark_anchor('C 77', 3.14) except ValueError as err: msg = "The value for occurrence must be an integer" self.assertEqual(str(err), msg) else: self.fail('ValueError expected') try: gen.mark_anchor('C 77', 0) except ValueError as err: msg = "0 is not valid for an anchor occurrence." self.assertEqual(str(err), msg) else: self.fail('ValueError expected') try: gen.mark_anchor('ZZZ') except RuntimeError as err: msg = "Could not find pattern ZZZ in template file template.dat" self.assertEqual(str(err), msg) else: self.fail('RuntimeError expected')