Skip to content

Commit 17a32a3

Browse files
authored
licensing and tmp file fixes (#642)
* licensing and tmp file fixes * Apply suggestions from code review
1 parent 2974e52 commit 17a32a3

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

tests/test_licensing.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,12 @@ def test_check_license_file_fail():
117117
def test_license_checker(tmpdir):
118118
# validate license checker (this will only checkout the license)
119119
checker = licensing.LicenseChecker()
120-
checker.start(license_file=False)
120+
checker.start(license_file=False, checkout_license=True)
121+
assert checker.check() is False
122+
assert checker._license_checkout_success is None
121123
checker.wait()
122124
assert checker.check()
123125

124-
checker = licensing.LicenseChecker(timeout=0.1)
125-
checker.start(checkout_license=False)
126-
checker.wait()
127-
with pytest.raises(errors.LicenseServerConnectionError):
128-
checker.check()
129-
130126

131127
@skip_launch_mapdl
132128
@skip_no_lic_bin

tests/test_mapdl.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ def clearing_cdread_cdwrite_tests(mapdl):
9696

9797

9898
def 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

Comments
 (0)