Skip to content

Commit 48a734e

Browse files
icywang86ruiEliza Zhang
authored andcommitted
Add tox.ini and configure coverage and flake runs (aws#80)
* Add tox.ini and configure coverage and flake runs * Add more unit tests * Configure unit tests to run with both py2 and py3 * Add flake checks * Fix broken integ tests * Add import style check * Add .flake8 * Add source module in coverage command * Add newlines
1 parent 2bf7f6d commit 48a734e

File tree

7 files changed

+49
-59
lines changed

7 files changed

+49
-59
lines changed

src/tf_container/training.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

test/conftest.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
#
2+
#
33
# Licensed under the Apache License, Version 2.0 (the "License").
44
# You may not use this file except in compliance with the License.
55
# A copy of the License is located at
6-
#
6+
#
77
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# or in the "license" file accompanying this file. This file is distributed
10-
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11-
# express or implied. See the License for the specific language governing
8+
#
9+
# or in the "license" file accompanying this file. This file is distributed
10+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
# express or implied. See the License for the specific language governing
1212
# permissions and limitations under the License.
1313
from __future__ import absolute_import
1414

@@ -17,7 +17,6 @@
1717

1818
import boto3
1919
import pytest
20-
2120
from sagemaker import LocalSession, Session
2221

2322
logger = logging.getLogger(__name__)
@@ -92,4 +91,3 @@ def skip_by_device_type(request, processor):
9291
@pytest.fixture(scope='session')
9392
def docker_image(docker_base_name, tag):
9493
return '{}:{}'.format(docker_base_name, tag)
95-

test/integration/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
#
2+
#
33
# Licensed under the Apache License, Version 2.0 (the "License").
44
# You may not use this file except in compliance with the License.
55
# A copy of the License is located at
6-
#
6+
#
77
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# or in the "license" file accompanying this file. This file is distributed
10-
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11-
# express or implied. See the License for the specific language governing
8+
#
9+
# or in the "license" file accompanying this file. This file is distributed
10+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
# express or implied. See the License for the specific language governing
1212
# permissions and limitations under the License.
1313
from __future__ import absolute_import
1414

test/integration/docker_utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2-
#
2+
#
33
# Licensed under the Apache License, Version 2.0 (the "License").
44
# You may not use this file except in compliance with the License.
55
# A copy of the License is located at
6-
#
6+
#
77
# http://www.apache.org/licenses/LICENSE-2.0
8-
#
9-
# or in the "license" file accompanying this file. This file is distributed
10-
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11-
# express or implied. See the License for the specific language governing
8+
#
9+
# or in the "license" file accompanying this file. This file is distributed
10+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
# express or implied. See the License for the specific language governing
1212
# permissions and limitations under the License.
1313
from __future__ import absolute_import
1414

@@ -92,13 +92,13 @@ def execute_command(self, cmd):
9292
lines = []
9393
process = subprocess.Popen(docker_cmd, stdout=subprocess.PIPE)
9494
print(
95-
'{}============================= container output ============================='.format(
96-
CYAN_COLOR))
95+
'{}========================= container output ========================='.format(
96+
CYAN_COLOR))
9797
for line in iter(process.stdout.readline, b''):
9898
sys.stdout.write(line.decode('utf-8'))
9999
sys.stdout.flush()
100100
lines.append(line.decode('utf-8'))
101-
msg = '\n{}============================= end of container output ============================='
101+
msg = '\n{}========================= end of container output ========================='
102102
print(msg.format(CYAN_COLOR))
103103

104104
process.wait()

test/integration/local/test_training.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
<<<<<<< HEAD
21
# Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
=======
4-
# Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5-
>>>>>>> Scriptmode single machine training implementation (#78)
62
#
73
# Licensed under the Apache License, Version 2.0 (the "License"). You
84
# may not use this file except in compliance with the License. A copy of

test/unit/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# permissions and limitations under the License.
1313
from __future__ import absolute_import
1414
<<<<<<< HEAD
15+
<<<<<<< HEAD
1516
=======
1617

1718
>>>>>>> Scriptmode single machine training implementation (#78)
19+
=======
20+
>>>>>>> Add tox.ini and configure coverage and flake runs (#80)

test/unit/test_training.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# language governing permissions and limitations under the License.
2222
from __future__ import absolute_import
2323

24+
<<<<<<< HEAD
2425
<<<<<<< HEAD
2526
import os
2627
import sys
@@ -308,12 +309,17 @@ def test_main_tuning_mpi_model_dir(configure_s3_env, read_hyperparameters, train
308309
configure_s3_env.assert_called_once_with('/opt/ml/model', REGION)
309310
=======
310311
import pytest
312+
=======
313+
>>>>>>> Add tox.ini and configure coverage and flake runs (#80)
311314
from mock import MagicMock, patch
315+
import pytest
312316

313-
from tf_container import training
317+
from sagemaker_tensorflow_container import training
314318

315319
MODULE_DIR = 's3://my/bucket'
316320
MODULE_NAME = 'script_name'
321+
LOG_LEVEL = 'Debug'
322+
317323

318324
@pytest.fixture
319325
def single_machine_training_env():
@@ -322,12 +328,30 @@ def single_machine_training_env():
322328
env.module_dir = MODULE_DIR
323329
env.module_name = MODULE_NAME
324330
env.hyperparameters = {}
331+
env.log_level = LOG_LEVEL
325332

326333
return env
327334

335+
328336
@patch('sagemaker_containers.beta.framework.modules.run_module')
329337
def test_single_machine(run_module, single_machine_training_env):
330338
training.train(single_machine_training_env)
331339
run_module.assert_called_with(MODULE_DIR, single_machine_training_env.to_cmd_args(),
332340
single_machine_training_env.to_env_vars(), MODULE_NAME)
341+
<<<<<<< HEAD
333342
>>>>>>> Scriptmode single machine training implementation (#78)
343+
=======
344+
345+
346+
@patch('sagemaker_tensorflow_container.training.train')
347+
@patch('logging.Logger.setLevel')
348+
@patch('sagemaker_containers.beta.framework.training_env')
349+
@patch('sagemaker_containers.beta.framework.env.read_hyperparameters', return_value={})
350+
def test_main(read_hyperparameters, training_env, set_level, train, single_machine_training_env):
351+
training_env.return_value = single_machine_training_env
352+
training.main()
353+
read_hyperparameters.assert_called_once_with()
354+
training_env.assert_called_once_with(hyperparameters={})
355+
set_level.assert_called_once_with(LOG_LEVEL)
356+
train.assert_called_once_with(single_machine_training_env)
357+
>>>>>>> Add tox.ini and configure coverage and flake runs (#80)

0 commit comments

Comments
 (0)