Lianhao Lu | 4e3368b | 2018-08-09 16:45:49 +0800 | [diff] [blame] | 1 | # Copyright (c) 2018 Intel Corp. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # 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, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | # |
| 15 | |
| 16 | import os |
| 17 | |
| 18 | from ruamel import yaml |
| 19 | import pytest |
| 20 | |
| 21 | from vnfsdk_pkgtools.validator import utils |
| 22 | |
| 23 | CONTENT = "---\n1" |
| 24 | |
| 25 | BAD_CONTENT = "---\na: b\n- d" |
| 26 | |
| 27 | def test_load_definition(tmpdir): |
| 28 | p = tmpdir.join("test_definition.yaml") |
| 29 | p.write(CONTENT) |
| 30 | assert 1 == utils.load_definitions(str(p)) |
| 31 | |
| 32 | |
| 33 | def test_load_bad_definition(tmpdir): |
| 34 | p = tmpdir.join("test_definition.yaml") |
| 35 | p.write(BAD_CONTENT) |
| 36 | with pytest.raises(yaml.YAMLError): |
| 37 | utils.load_definitions(str(p)) |
| 38 | |
| 39 | |
| 40 | def test_load_defualt_definition(tmpdir): |
| 41 | p = tmpdir.join("non_exist") |
| 42 | assert 1 == utils.load_definitions(str(p),defaults=1) |