|
47 | 47 | # Many of the commands could be deleted, but for the sake of good |
48 | 48 | # testing we are going to leave them. |
49 | 49 |
|
50 | | -CDB_FILE = """/COM,ANSYS RELEASE 2021 R2 BUILD 21.2 |
| 50 | +CDB_FILE = """ S 1 |
| 51 | +/COM,ANSYS RELEASE 12.1BETAUP20090531 10:26:32 06/01/2009 S 2 |
| 52 | +/NOPR S 3 |
| 53 | +/PREP7 S 4 |
| 54 | +/TITLE, S 5 |
| 55 | +1H,,1H;,,18Hdisc_pad_model.cdb, G 1 |
| 56 | +5HANSYS,22H 12.1BETA UP20090531,,,,,,,1.0,,,,,13H000601.102632, G 2 |
| 57 | +1.0000E-04,,,,9,,; G 3 |
| 58 | +S 29G 3D 0P 0 T 1 |
| 59 | +:CDWRITE ! START OF CDWRITE DATA |
| 60 | +/COM,ANSYS RELEASE 2021 R2 BUILD 21.2 |
51 | 61 | /PREP7 |
52 | 62 | /NOPR |
53 | | -/TITLE,'CDREAD and CDWRITE tests |
| 63 | +/TITLE,'CDREAD and CDWRITE tests' |
54 | 64 | *IF,_CDRDOFF,EQ,1,THEN !if solid model was read in |
55 | 65 | _CDRDOFF= !reset flag, numoffs already performed |
56 | 66 | *ELSE !offset database for the following FE model |
@@ -103,6 +113,25 @@ def asserting_cdread_cdwrite_tests(mapdl): |
103 | 113 | return 'asdf1234' in mapdl.parameters['T_PAR'] |
104 | 114 |
|
105 | 115 |
|
| 116 | +def warns_in_cdread_error_log(mapdl): |
| 117 | + """Check for specific warns in the error log associated with using /INPUT with CDB files |
| 118 | + instead of CDREAD command.""" |
| 119 | + error_files = [each for each in os.listdir(mapdl.directory) if each.endswith('.err')] |
| 120 | + |
| 121 | + # "S 1", "1 H" and "5 H Ansys" are character at the end of lines in the CDB_FILE variable. |
| 122 | + # They are allowed in the CDREAD command, but it gives warnings in the /INPUT command. |
| 123 | + warn_cdread_1 = "S1 is not a recognized" |
| 124 | + warn_cdread_2 = "1H is not a recognized" |
| 125 | + warn_cdread_3 = "5HANSYS is not a recognized" |
| 126 | + |
| 127 | + warns = [] |
| 128 | + for each in error_files: |
| 129 | + with open(os.path.join(mapdl.directory, each)) as fid: |
| 130 | + error_log = ''.join(fid.readlines()) |
| 131 | + warns.append((warn_cdread_1 in error_log) or (warn_cdread_2 in error_log) or (warn_cdread_3 in error_log)) |
| 132 | + return any(warns) |
| 133 | + |
| 134 | + |
106 | 135 | @pytest.fixture(scope="function") |
107 | 136 | def make_block(mapdl, cleared): |
108 | 137 | mapdl.block(0, 1, 0, 1, 0, 1) |
@@ -696,15 +725,15 @@ def test_title(mapdl, cleared): |
696 | 725 |
|
697 | 726 |
|
698 | 727 | def test_cdread(mapdl, cleared): |
699 | | - random_letters = mapdl.directory.split('/')[0][-3:0] |
| 728 | + random_letters = random_string(4) |
700 | 729 |
|
701 | | - mapdl.run(f"parmtest='{random_letters}'") |
| 730 | + mapdl.run(f"PARMTEST='{random_letters}'") |
702 | 731 | mapdl.cdwrite('all', 'model2', 'cdb') |
703 | 732 |
|
704 | 733 | mapdl.clear() |
705 | 734 | mapdl.cdread("db", 'model2', 'cdb') |
706 | 735 |
|
707 | | - assert random_letters == mapdl.parameters['parmtest'] |
| 736 | + assert random_letters in mapdl.parameters['PARMTEST'] |
708 | 737 |
|
709 | 738 |
|
710 | 739 | # CDREAD tests are actually a good way to test 'input' command. |
@@ -738,35 +767,38 @@ def test_cdread_in_python_directory(mapdl, cleared, tmpdir): |
738 | 767 | # the archive from the current working directory. |
739 | 768 | old_cwd = os.getcwd() |
740 | 769 | try: |
| 770 | + # We are not checking yet if the file is read correctly, just if the file |
| 771 | + # can be read. |
741 | 772 | os.chdir(tmpdir) |
742 | | - mapdl.cdread('db', 'model', 'cdb') |
743 | | - assert asserting_cdread_cdwrite_tests(mapdl) |
| 773 | + mapdl.cdread('COMB', 'model', 'cdb') # 'COMB' is needed since we use the CDB with the strange line endings. |
| 774 | + assert asserting_cdread_cdwrite_tests(mapdl) and not warns_in_cdread_error_log(mapdl) |
744 | 775 |
|
745 | 776 | clearing_cdread_cdwrite_tests(mapdl) |
746 | | - mapdl.cdread('db', 'model.cdb') |
747 | | - assert asserting_cdread_cdwrite_tests(mapdl) |
| 777 | + mapdl.cdread('COMB', 'model.cdb') |
| 778 | + assert asserting_cdread_cdwrite_tests(mapdl) and not warns_in_cdread_error_log(mapdl) |
748 | 779 |
|
749 | 780 | clearing_cdread_cdwrite_tests(mapdl) |
750 | | - mapdl.cdread('db', 'model') |
751 | | - assert asserting_cdread_cdwrite_tests(mapdl) |
| 781 | + mapdl.cdread('COMB', 'model') |
| 782 | + assert asserting_cdread_cdwrite_tests(mapdl) and not warns_in_cdread_error_log(mapdl) |
| 783 | + |
752 | 784 | finally: |
753 | 785 | # always change back to the previous directory |
754 | 786 | os.chdir(old_cwd) |
755 | 787 |
|
756 | 788 | clearing_cdread_cdwrite_tests(mapdl) |
757 | 789 | fullpath = str(tmpdir.join('model.cdb')) |
758 | | - mapdl.cdread('db', fullpath) |
759 | | - assert asserting_cdread_cdwrite_tests(mapdl) |
| 790 | + mapdl.cdread('COMB', fullpath) |
| 791 | + assert asserting_cdread_cdwrite_tests(mapdl) and not warns_in_cdread_error_log(mapdl) |
760 | 792 |
|
761 | 793 | clearing_cdread_cdwrite_tests(mapdl) |
762 | 794 | fullpath = str(tmpdir.join('model')) |
763 | | - mapdl.cdread('db', fullpath, 'cdb') |
764 | | - assert asserting_cdread_cdwrite_tests(mapdl) |
| 795 | + mapdl.cdread('COMB', fullpath, 'cdb') |
| 796 | + assert asserting_cdread_cdwrite_tests(mapdl) and not warns_in_cdread_error_log(mapdl) |
765 | 797 |
|
766 | 798 | clearing_cdread_cdwrite_tests(mapdl) |
767 | 799 | fullpath = str(tmpdir.join('model')) |
768 | | - mapdl.cdread('db', fullpath) |
769 | | - assert asserting_cdread_cdwrite_tests(mapdl) |
| 800 | + mapdl.cdread('COMB', fullpath) |
| 801 | + assert asserting_cdread_cdwrite_tests(mapdl) and not warns_in_cdread_error_log(mapdl) |
770 | 802 |
|
771 | 803 |
|
772 | 804 | def test_cdread_in_apdl_directory(mapdl, cleared): |
|
0 commit comments