|
| 1 | +# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. |
| 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 | +import unittest |
| 16 | +import os |
| 17 | +import sys |
| 18 | +import paddle.fluid as fluid |
| 19 | +import importlib |
| 20 | +import cStringIO |
| 21 | + |
| 22 | + |
| 23 | +def main(): |
| 24 | + sys.path.append(os.getcwd()) |
| 25 | + some_test_failed = False |
| 26 | + for module_name in sys.argv[1:]: |
| 27 | + buffer = cStringIO.StringIO() |
| 28 | + main = fluid.Program() |
| 29 | + startup = fluid.Program() |
| 30 | + scope = fluid.core.Scope() |
| 31 | + with fluid.program_guard(main, startup): |
| 32 | + with fluid.scope_guard(scope): |
| 33 | + with fluid.unique_name.guard(): |
| 34 | + test_loader = unittest.TestLoader() |
| 35 | + module = importlib.import_module(module_name) |
| 36 | + tests = test_loader.loadTestsFromModule(module) |
| 37 | + res = unittest.TextTestRunner(stream=buffer).run(tests) |
| 38 | + if not res.wasSuccessful(): |
| 39 | + some_test_failed = True |
| 40 | + print >> sys.stderr, module_name, 'failed\n', buffer.getvalue( |
| 41 | + ) |
| 42 | + |
| 43 | + if some_test_failed: |
| 44 | + exit(1) |
| 45 | + |
| 46 | + |
| 47 | +if __name__ == '__main__': |
| 48 | + main() |
0 commit comments