@@ -96,7 +96,8 @@ def clearing_cdread_cdwrite_tests(mapdl):
9696
9797
9898def asserting_cdread_cdwrite_tests (mapdl ):
99- return 'asdf1234' in mapdl .parameters ['T_PAR' ] # Using in because of the padding APDL does on strings.
99+ # Using ``in`` because of the padding APDL does on strings.
100+ return 'asdf1234' in mapdl .parameters ['T_PAR' ]
100101
101102
102103@pytest .fixture (scope = "function" )
@@ -716,36 +717,45 @@ def test_cdread_different_location(mapdl, cleared, tmpdir):
716717 assert random_letters == mapdl .parameters ['parmtest' ]
717718
718719
719- def test_cdread_in_python_directory (mapdl , cleared ):
720+ def test_cdread_in_python_directory (mapdl , cleared , tmpdir ):
720721 # Writing db file in python directory.
721722 # Pyansys should upload it when it detects it is not in the APDL directory.
722- with open ('model.cdb' , 'w' ) as file :
723- file .write (CDB_FILE )
723+ fullpath = str (tmpdir .join ('model.cdb' ))
724+ with open (fullpath , 'w' ) as fid :
725+ fid .write (CDB_FILE )
724726
725- mapdl .cdread ('cdb' , 'model' , 'cdb' )
726- assert asserting_cdread_cdwrite_tests (mapdl )
727+ # check if pymapdl is smart enough to determine if it can access
728+ # the archive from the current working directory.
729+ old_cwd = os .getcwd ()
730+ try :
731+ os .chdir (tmpdir )
732+ mapdl .cdread ('db' , 'model' , 'cdb' )
733+ assert asserting_cdread_cdwrite_tests (mapdl )
727734
728- clearing_cdread_cdwrite_tests (mapdl )
729- mapdl .cdread ('cdb ' , 'model.cdb' )
730- assert asserting_cdread_cdwrite_tests (mapdl )
735+ clearing_cdread_cdwrite_tests (mapdl )
736+ mapdl .cdread ('db ' , 'model.cdb' )
737+ assert asserting_cdread_cdwrite_tests (mapdl )
731738
732- clearing_cdread_cdwrite_tests (mapdl )
733- mapdl .cdread ('cdb' , 'model' )
734- assert asserting_cdread_cdwrite_tests (mapdl )
739+ clearing_cdread_cdwrite_tests (mapdl )
740+ mapdl .cdread ('db' , 'model' )
741+ assert asserting_cdread_cdwrite_tests (mapdl )
742+ finally :
743+ # always change back to the previous directory
744+ os .chdir (old_cwd )
735745
736746 clearing_cdread_cdwrite_tests (mapdl )
737- fullpath = os . path . join (os . getcwd (), 'model.cdb' )
738- mapdl .cdread ('cdb ' , fullpath )
747+ fullpath = str ( tmpdir . join ('model.cdb' ) )
748+ mapdl .cdread ('db ' , fullpath )
739749 assert asserting_cdread_cdwrite_tests (mapdl )
740750
741751 clearing_cdread_cdwrite_tests (mapdl )
742- fullpath = os . path . join (os . getcwd (), 'model' )
743- mapdl .cdread ('cdb ' , fullpath , 'cdb' )
752+ fullpath = str ( tmpdir . join ('model' ) )
753+ mapdl .cdread ('db ' , fullpath , 'cdb' )
744754 assert asserting_cdread_cdwrite_tests (mapdl )
745755
746756 clearing_cdread_cdwrite_tests (mapdl )
747- fullpath = os . path . join (os . getcwd (), 'model' )
748- mapdl .cdread ('cdb ' , fullpath )
757+ fullpath = str ( tmpdir . join ('model' ) )
758+ mapdl .cdread ('db ' , fullpath )
749759 assert asserting_cdread_cdwrite_tests (mapdl )
750760
751761
0 commit comments