Skip to content

Commit

Permalink
Update procedures using the natlinkstatus module
Browse files Browse the repository at this point in the history
Re: #354.

Dragonfly will now attempt to import this module with the following
incantations (in order):

 1. import natlinkstatus
 2. from natlinkcore import natlinkstatus

This allows the library to work with older and newer versions of
Natlink.

I note that, apart from the `natlink' ext. module, `natlinkstatus'
is the only Natlink module used by this library.
  • Loading branch information
drmfinlay committed Jul 19, 2022
1 parent 8fc9f27 commit 17b4e35
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
5 changes: 4 additions & 1 deletion dragonfly/engines/backend_natlink/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ def set_retain_directory(self, retain_dir):
try:
import natlinkstatus
except ImportError:
natlinkstatus = None
try:
from natlinkcore import natlinkstatus
except ImportError:
natlinkstatus = None
running_via_natspeak = (
sys.executable.endswith("natspeak.exe") and
natlinkstatus is not None
Expand Down
30 changes: 21 additions & 9 deletions dragonfly/test/suites.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,33 @@
"test_language_nl_number",
]

# Use different test names depending on the DNS version. Fallback on v11 if
# the version is unknown.
try:
import natlinkstatus
dns_version = int(natlinkstatus.NatlinkStatus().getDNSVersion())
except:
# Couldn't get the DNS version for whatever reason.
dns_version = None

# Define Natlink test names.
natlink_names = common_names + language_names + [
"test_compiler_natlink",
"test_dictation",
"test_engine_natlink",
]

# Import the `natlinkstatus' module. The module is in a different place in
# newer versions of Natlink.
try:
import natlinkstatus
except ImportError:
try:
from natlinkcore import natlinkstatus
except:
natlinkstatus = None

# If `natlinkstatus' was found it, use it to check the DNS version.
if natlinkstatus:
try:
dns_version = int(natlinkstatus.NatlinkStatus().getDNSVersion())
except:
# Couldn't get the DNS version for whatever reason.
dns_version = None

# Add the appropriate DNS word formatting doctest to the `natlink_names'
# list, assuming v11 if the DNS version was indeterminable.
if dns_version and dns_version <= 10:
natlink_names += ["documentation/test_word_formatting_v10_doctest.txt"]
else:
Expand Down

0 comments on commit 17b4e35

Please sign in to comment.