Skip to content

Commit 60b7462

Browse files
committed
Manually merge migrid-sync PR61 back through trunk/master in line with current clunky code flow. Thanks, @albu.diku .
git-svn-id: svn+ssh://svn.code.sf.net/p/migrid/code/trunk@6049 b75ad72c-e7d7-11dd-a971-7dbc132099af
1 parent c690196 commit 60b7462

File tree

4 files changed

+65
-53
lines changed

4 files changed

+65
-53
lines changed

envhelp/python2

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ if [ -z "${DOCKER_BIN}" ]; then
1616
exit 1
1717
fi
1818

19+
# default PYTHONPATH such that directly executing files in the repo "just works"
20+
# NOTE: this is hard-coded to the mount point used within the container
21+
PYTHONPATH='/usr/app/src'
22+
1923
# default any variables for local development
2024
MIG_ENV=${MIG_ENV:-'local'}
2125

@@ -40,4 +44,8 @@ echo
4044

4145
# execute python2 within the image passing the supplied arguments
4246

43-
${DOCKER_BIN} run -it --rm --mount type=bind,source=.,target=/usr/src/app --env "MIG_ENV=$MIG_ENV" "$IMAGEID" python2 "$@"
47+
${DOCKER_BIN} run -it --rm \
48+
--mount type=bind,source=.,target=/usr/src/app \
49+
--env "PYTHONPATH=$PYTHON_PATH" \
50+
--env "MIG_ENV=$MIG_ENV" \
51+
"$IMAGEID" python2 "$@"

envhelp/python3

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ set -e
66

77
SCRIPT_PATH=$(realpath "$0")
88
SCRIPT_BASE=$(dirname -- "$SCRIPT_PATH")
9+
MIG_BASE=$(realpath "$SCRIPT_BASE/..")
910
PYTHON3_BIN="$SCRIPT_BASE/venv/bin/python3"
1011

1112
if [ ! -f "${PYTHON3_BIN}" ]; then
1213
echo "No python3 binary found - perhaps the virtual env was not created"
1314
exit 1
1415
fi
1516

17+
# default PYTHONPATH such that directly executing files in the repo "just works"
18+
PYTHONPATH=${PYTHONPATH:-"$MIG_BASE"}
19+
1620
# default any variables for local development
1721
MIG_ENV=${MIG_ENV:-'local'}
1822

1923
echo "running with MIG_ENV='$MIG_ENV' under python 3"
2024
echo
2125

22-
MIG_ENV="$MIG_ENV" "$PYTHON3_BIN" "$@"
26+
PYTHONPATH="$PYTHONPATH" MIG_ENV="$MIG_ENV" "$PYTHON3_BIN" "$@"

tests/__init__.py

Whitespace-only changes.

tests/test_mig_shared_fileio.py

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -109,34 +109,34 @@ def test_store_bytes_at_offset(self):
109109
self.assertEqual(content[3:], DUMMY_BYTES)
110110

111111
# TODO: enable again - requires the temporarily disabled auto mode select
112-
# def test_store_bytes_in_text_mode(self):
113-
# fileio.write_chunk(self.tmp_path, DUMMY_BYTES, 0, self.logger,
114-
# mode="r+")
115-
#
116-
# with open(self.tmp_path, 'rb') as file:
117-
# content = file.read(1024)
118-
# self.assertEqual(len(content), DUMMY_BYTES_LENGTH)
119-
# self.assertEqual(content[:], DUMMY_BYTES)
112+
def test_store_bytes_in_text_mode(self):
113+
fileio.write_chunk(self.tmp_path, DUMMY_BYTES, 0, self.logger,
114+
mode="r+")
115+
116+
with open(self.tmp_path, 'rb') as file:
117+
content = file.read(1024)
118+
self.assertEqual(len(content), DUMMY_BYTES_LENGTH)
119+
self.assertEqual(content[:], DUMMY_BYTES)
120120

121121
# TODO: enable again - requires the temporarily disabled auto mode select
122-
# def test_store_unicode(self):
123-
# fileio.write_chunk(self.tmp_path, DUMMY_UNICODE, 0, self.logger,
124-
# mode='r+')
125-
#
126-
# with open(self.tmp_path, 'r') as file:
127-
# content = file.read(1024)
128-
# self.assertEqual(len(content), DUMMY_UNICODE_LENGTH)
129-
# self.assertEqual(content[:], DUMMY_UNICODE)
122+
def test_store_unicode(self):
123+
fileio.write_chunk(self.tmp_path, DUMMY_UNICODE, 0, self.logger,
124+
mode='r+')
125+
126+
with open(self.tmp_path, 'r') as file:
127+
content = file.read(1024)
128+
self.assertEqual(len(content), DUMMY_UNICODE_LENGTH)
129+
self.assertEqual(content[:], DUMMY_UNICODE)
130130

131131
# TODO: enable again - requires the temporarily disabled auto mode select
132-
# def test_store_unicode_in_binary_mode(self):
133-
# fileio.write_chunk(self.tmp_path, DUMMY_UNICODE, 0, self.logger,
134-
# mode='r+b')
135-
#
136-
# with open(self.tmp_path, 'r') as file:
137-
# content = file.read(1024)
138-
# self.assertEqual(len(content), DUMMY_UNICODE_LENGTH)
139-
# self.assertEqual(content[:], DUMMY_UNICODE)
132+
def test_store_unicode_in_binary_mode(self):
133+
fileio.write_chunk(self.tmp_path, DUMMY_UNICODE, 0, self.logger,
134+
mode='r+b')
135+
136+
with open(self.tmp_path, 'r') as file:
137+
content = file.read(1024)
138+
self.assertEqual(len(content), DUMMY_UNICODE_LENGTH)
139+
self.assertEqual(content[:], DUMMY_UNICODE)
140140

141141

142142
class MigSharedFileio__write_file(MigTestCase):
@@ -185,37 +185,37 @@ def test_store_bytes(self):
185185
self.assertEqual(content[:], DUMMY_BYTES)
186186

187187
# TODO: enable again - requires the temporarily disabled auto mode select
188-
# def test_store_bytes_in_text_mode(self):
189-
# did_succeed = fileio.write_file(DUMMY_BYTES, self.tmp_path, self.logger,
190-
# mode="w")
191-
# self.assertTrue(did_succeed)
192-
#
193-
# with open(self.tmp_path, 'rb') as file:
194-
# content = file.read(1024)
195-
# self.assertEqual(len(content), DUMMY_BYTES_LENGTH)
196-
# self.assertEqual(content[:], DUMMY_BYTES)
188+
def test_store_bytes_in_text_mode(self):
189+
did_succeed = fileio.write_file(DUMMY_BYTES, self.tmp_path, self.logger,
190+
mode="w")
191+
self.assertTrue(did_succeed)
192+
193+
with open(self.tmp_path, 'rb') as file:
194+
content = file.read(1024)
195+
self.assertEqual(len(content), DUMMY_BYTES_LENGTH)
196+
self.assertEqual(content[:], DUMMY_BYTES)
197197

198198
# TODO: enable again - requires the temporarily disabled auto mode select
199-
# def test_store_unicode(self):
200-
# did_succeed = fileio.write_file(DUMMY_UNICODE, self.tmp_path,
201-
# self.logger, mode='w')
202-
# self.assertTrue(did_succeed)
203-
#
204-
# with open(self.tmp_path, 'r') as file:
205-
# content = file.read(1024)
206-
# self.assertEqual(len(content), DUMMY_UNICODE_LENGTH)
207-
# self.assertEqual(content[:], DUMMY_UNICODE)
199+
def test_store_unicode(self):
200+
did_succeed = fileio.write_file(DUMMY_UNICODE, self.tmp_path,
201+
self.logger, mode='w')
202+
self.assertTrue(did_succeed)
203+
204+
with open(self.tmp_path, 'r') as file:
205+
content = file.read(1024)
206+
self.assertEqual(len(content), DUMMY_UNICODE_LENGTH)
207+
self.assertEqual(content[:], DUMMY_UNICODE)
208208

209209
# TODO: enable again - requires the temporarily disabled auto mode select
210-
# def test_store_unicode_in_binary_mode(self):
211-
# did_succeed = fileio.write_file(DUMMY_UNICODE, self.tmp_path,
212-
# self.logger, mode='wb')
213-
# self.assertTrue(did_succeed)
214-
#
215-
# with open(self.tmp_path, 'r') as file:
216-
# content = file.read(1024)
217-
# self.assertEqual(len(content), DUMMY_UNICODE_LENGTH)
218-
# self.assertEqual(content[:], DUMMY_UNICODE)
210+
def test_store_unicode_in_binary_mode(self):
211+
did_succeed = fileio.write_file(DUMMY_UNICODE, self.tmp_path,
212+
self.logger, mode='wb')
213+
self.assertTrue(did_succeed)
214+
215+
with open(self.tmp_path, 'r') as file:
216+
content = file.read(1024)
217+
self.assertEqual(len(content), DUMMY_UNICODE_LENGTH)
218+
self.assertEqual(content[:], DUMMY_UNICODE)
219219

220220

221221
if __name__ == '__main__':

0 commit comments

Comments
 (0)