1# Copyright 2020 Huawei Technologies Co., Ltd 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15""" 16Test No-op mode support with Dummy Iterator 17""" 18import os 19import mindspore.dataset as ds 20from mindspore import context 21 22DATA_DIR = "../data/dataset/testVOC2012" 23 24def test_noop_pserver(): 25 os.environ['MS_ROLE'] = 'MS_PSERVER' 26 context.set_ps_context(enable_ps=True) 27 data1 = ds.VOCDataset(DATA_DIR, task="Segmentation", usage="train", shuffle=False, decode=True) 28 num = 0 29 for _ in data1.create_dict_iterator(num_epochs=1): 30 num += 1 31 assert num == 0 32 del os.environ['MS_ROLE'] 33 context.set_ps_context(enable_ps=False) 34 35 36def test_noop_sched(): 37 os.environ['MS_ROLE'] = 'MS_SCHED' 38 context.set_ps_context(enable_ps=True) 39 data1 = ds.VOCDataset(DATA_DIR, task="Segmentation", usage="train", shuffle=False, decode=True) 40 num = 0 41 for _ in data1.create_dict_iterator(num_epochs=1): 42 num += 1 43 assert num == 0 44 del os.environ['MS_ROLE'] 45 context.set_ps_context(enable_ps=False) 46 47 48if __name__ == '__main__': 49 test_noop_pserver() 50 test_noop_sched() 51