Skip to content

Commit 36bc97b

Browse files
author
Dorian Birraux
committed
use items instead of iteritems.
Use platform.system instead of os.name. Update comment on sample json config. Move configuration to dedicated script.
1 parent 5375d22 commit 36bc97b

File tree

5 files changed

+54
-46
lines changed

5 files changed

+54
-46
lines changed

wolframclient/evaluation/kernel/kernelsession.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929
3: logging.WARN,
3030
4: logging.FATAL
3131
}
32-
if six.PY2:
33-
FROM_PY_LOG_LEVEL = dict((v, k) for k, v in TO_PY_LOG_LEVEL.iteritems())
34-
else:
35-
FROM_PY_LOG_LEVEL = dict((v, k) for k, v in TO_PY_LOG_LEVEL.items())
32+
FROM_PY_LOG_LEVEL = dict((v, k) for k, v in TO_PY_LOG_LEVEL.items())
3633

3734
class KernelLogger(Thread):
3835

wolframclient/tests/__init__.py

+3-36
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,6 @@
11
# -*- coding: utf-8 -*-
2-
import json
3-
from wolframclient.logger.utils import setup_logging_to_file
4-
from wolframclient.utils.api import os
5-
__all__ = [ 'create_dir_if_missing', 'dir_test_data', 'json_config' ]
2+
from __future__ import absolute_import, print_function, unicode_literals
63

7-
def create_dir_if_missing(path):
8-
''' Create the directory structure represented by a `path`.
9-
10-
Path can represent a file or a directory depending if it ends with
11-
a path separator.
12-
13-
If the path represents a file, the parent directory is created, otherwise
14-
the directory itself is created.
15-
'''
16-
file_dir = os.dirname(path)
17-
if not os.exists(file_dir):
18-
os.makedirs(file_dir)
4+
from wolframclient.tests.configure import json_config, create_dir_if_missing, dir_test_data
195

20-
def dir_test_data():
21-
''' Return path to the data directory in tests'''
22-
current_file_dir = os.dirname(__file__)
23-
return os.path_join(current_file_dir, 'data')
24-
25-
26-
log_file = os.environ.get('WOLFRAMCLIENT_PY_LOG_FILE', None)
27-
if log_file is not None:
28-
create_dir_if_missing(log_file)
29-
setup_logging_to_file(log_file)
30-
31-
json_config=None
32-
json_config_path = os.environ.get('WOLFRAMCLIENT_PY_JSON_CONFIG', None)
33-
if json_config_path is not None:
34-
expended_path = os.expanduser(os.expandvars(json_config_path))
35-
try:
36-
with open(expended_path, 'r') as fp:
37-
json_config = json.load(fp)
38-
except:
39-
raise ValueError('Failed to find json configuration file %s' % json_config_path)
6+
__all__ = ['create_dir_if_missing', 'dir_test_data', 'json_config']

wolframclient/tests/configure.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import absolute_import, print_function, unicode_literals
3+
import json
4+
5+
from wolframclient.logger.utils import setup_logging_to_file
6+
from wolframclient.utils.api import os
7+
8+
__all__ = ['create_dir_if_missing', 'dir_test_data', 'json_config']
9+
10+
11+
def create_dir_if_missing(path):
12+
''' Create the directory structure represented by a `path`.
13+
14+
Path can represent a file or a directory depending if it ends with
15+
a path separator.
16+
17+
If the path represents a file, the parent directory is created, otherwise
18+
the directory itself is created.
19+
'''
20+
file_dir = os.dirname(path)
21+
if not os.exists(file_dir):
22+
os.makedirs(file_dir)
23+
24+
25+
def dir_test_data():
26+
''' Return path to the data directory in tests'''
27+
current_file_dir = os.dirname(__file__)
28+
return os.path_join(current_file_dir, 'data')
29+
30+
log_file = os.environ.get('WOLFRAMCLIENT_PY_LOG_FILE', None)
31+
if log_file is not None:
32+
create_dir_if_missing(log_file)
33+
setup_logging_to_file(log_file)
34+
35+
json_config = None
36+
_json_config_path = os.environ.get('WOLFRAMCLIENT_PY_JSON_CONFIG', None)
37+
if _json_config_path is not None:
38+
expended_path = os.expanduser(os.expandvars(_json_config_path))
39+
try:
40+
with open(expended_path, 'r') as fp:
41+
json_config = json.load(fp)
42+
except:
43+
raise ValueError(
44+
'Failed to find json configuration file %s' % _json_config_path)

wolframclient/tests/local_config_sample.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// this json file is used by the test suite to connect to the Wolfram
2-
// public cloud and to evaluate expressions to a local kernel.
3-
// It has to be renamed to local_config.json and edited with correct
4-
// local configuration.
1+
// this json file is used by the test suite to connect to the Wolfram public cloud
2+
// and to evaluate expressions to a local kernel.
3+
// It's path is specified with the environment variable WOLFRAMCLIENT_PY_JSON_CONFIG
54
{
65
"kernel" : "/path/to/WolframKernel",
76
"cloud_credentials" : {

wolframclient/utils/six.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from itertools import chain
66

77
import datetime
8+
import platform
89
import decimal
910
import sys
1011
import os
@@ -15,7 +16,7 @@
1516
PY2 = sys.version_info[0] == 2
1617
PY3 = sys.version_info[0] == 3
1718

18-
WINDOWS = os.name == 'nt'
19+
WINDOWS = platform.system() == 'Windows'
1920

2021
JYTHON = sys.platform.startswith('java')
2122

@@ -62,4 +63,4 @@
6263
integer_types,
6364
(float, decimal.Decimal, datetime.date, datetime.datetime, datetime.time, bool, none_type)
6465
)
65-
)
66+
)

0 commit comments

Comments
 (0)