640 {"IEC_TYPE":"UDINT","NAME":"__ID0_1_64_25638_3","DIR":"I","SIZE":"D","LOC":(0,1,64,25638,3)}, |
640 {"IEC_TYPE":"UDINT","NAME":"__ID0_1_64_25638_3","DIR":"I","SIZE":"D","LOC":(0,1,64,25638,3)}, |
641 {"IEC_TYPE":"UDINT","NAME":"__ID0_1_64_25638_4","DIR":"I","SIZE":"D","LOC":(0,1,64,25638,4)}] |
641 {"IEC_TYPE":"UDINT","NAME":"__ID0_1_64_25638_4","DIR":"I","SIZE":"D","LOC":(0,1,64,25638,4)}] |
642 |
642 |
643 # Generate MasterNode configuration |
643 # Generate MasterNode configuration |
644 try: |
644 try: |
645 masternode = GenerateConciseDCF(locations, (0, 1), nodelist, True) |
645 masternode = GenerateConciseDCF(locations, (0, 1), nodelist, True, "TestNode") |
646 except ValueError, message: |
646 except ValueError, message: |
647 print "%s\nTest Failed!"%message |
647 print "%s\nTest Failed!"%message |
648 sys.exit() |
648 sys.exit() |
649 |
649 |
650 # Get Text corresponding to MasterNode |
650 # Get Text corresponding to MasterNode |
657 file.write(result) |
657 file.write(result) |
658 file.close() |
658 file.close() |
659 |
659 |
660 print "Reset Successful!" |
660 print "Reset Successful!" |
661 else: |
661 else: |
662 # Test each line of the result with the reference result |
662 import os |
663 test = [line.rstrip() for line in result.splitlines()] |
663 |
664 |
664 file = open("test_config/result_tmp.txt", "w") |
665 file = open("test_config/result.txt", "r") |
665 file.write(result) |
666 model = [line.rstrip() for line in file.readlines() if line.rstrip()] |
|
667 file.close() |
666 file.close() |
668 |
667 |
669 errors = 0 |
668 os.system("diff test_config/result.txt test_config/result_tmp.txt") |
670 for i, line in enumerate(model): |
669 os.remove("test_config/result_tmp.txt") |
671 if i >= len(test): |
|
672 errors += 1 |
|
673 print "Line %d disappear :\n%s\n"%(i + 1, line) |
|
674 elif line != test[i]: |
|
675 errors += 1 |
|
676 print "Error on line %d :\n%s\nInstead of :\n%s\n"%(i + 1, test[i], line) |
|
677 for i in xrange(len(model), len(test)): |
|
678 errors += 1 |
|
679 print "Line %d appear :\n%s\n"%(i + 1, test[i]) |
|
680 |
|
681 if errors > 0: |
|
682 print "%d errors found.\nTest Failed!"%errors |
|
683 else: |
|
684 print "Test Successful!" |
|