You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

conftest.py 1.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright 2019 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. """The st config."""
  16. import os
  17. import shutil
  18. import sys
  19. import tempfile
  20. import types
  21. import pytest
  22. OUTPUT_DIR = tempfile.mktemp(prefix='test_mindconverter_output_dir_')
  23. sys.modules['torch'] = types.ModuleType('torch')
  24. nn = types.ModuleType('torch.nn')
  25. sys.modules['torch.nn'] = nn
  26. nn.Module = type('Module', (object,), dict())
  27. sys.modules['torch.nn.functional'] = types.ModuleType('torch.nn.functional')
  28. @pytest.fixture(scope='session')
  29. def create_output_dir():
  30. """Create output directory."""
  31. try:
  32. if os.path.exists(OUTPUT_DIR):
  33. shutil.rmtree(OUTPUT_DIR)
  34. permissions = os.R_OK | os.W_OK | os.X_OK
  35. mode = permissions << 6
  36. if not os.path.exists(OUTPUT_DIR):
  37. os.mkdir(OUTPUT_DIR, mode=mode)
  38. yield
  39. finally:
  40. if os.path.exists(OUTPUT_DIR):
  41. shutil.rmtree(OUTPUT_DIR)
  42. @pytest.fixture()
  43. def output():
  44. """Get the output directory."""
  45. return OUTPUT_DIR