From 025b799afdb279407b62dafa80f29c5c7fef5bd2 Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Tue, 16 Feb 2016 16:54:08 +0300 Subject: [PATCH] Generate tests by fixtures --- .../tests/fixtures/min_only.yaml | 32 +++++++++ .../tests/test_allocator_integration_test.py | 65 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 bareon_dynamic_allocator/tests/fixtures/min_only.yaml create mode 100644 bareon_dynamic_allocator/tests/test_allocator_integration_test.py diff --git a/bareon_dynamic_allocator/tests/fixtures/min_only.yaml b/bareon_dynamic_allocator/tests/fixtures/min_only.yaml new file mode 100644 index 0000000..c33fe98 --- /dev/null +++ b/bareon_dynamic_allocator/tests/fixtures/min_only.yaml @@ -0,0 +1,32 @@ +name: Minimal size with a single disk + +dynamic_schema: + - id: lv1 + type: lv + min_size: 50 + + - id: lv2 + type: lv + min_size: 50 + + - id: vg1 + type: vg + contains: + - lv1 + - lv2 + +hw_info: + disks: + - id: sda + size: 100 + +expected: + - disk_id: sda + size: 100 + spaces: + - space_id: lv1 + size: 50 + - space_id: lv2 + size: 50 + - space_id: unallocated + size: 0 diff --git a/bareon_dynamic_allocator/tests/test_allocator_integration_test.py b/bareon_dynamic_allocator/tests/test_allocator_integration_test.py new file mode 100644 index 0000000..70c0e46 --- /dev/null +++ b/bareon_dynamic_allocator/tests/test_allocator_integration_test.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Integration test for bareon allocation system. + +Checks that high level abstraction works together +including the solver. +""" + +import glob +import os + +import six +import yaml + +from bareon_dynamic_allocator.allocators import DynamicAllocator +from bareon_dynamic_allocator.tests import base + +fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures', '*.yaml') + + +class TestGeneratorMeta(type): + """Autogenerate tests from fixtures.""" + + def __new__(mcs, name, bases, cls_dict): + + def gen_test(hw_info, dynamic_schema, expected): + def test(self): + result = DynamicAllocator( + hw_info, + dynamic_schema).generate_static() + self.assertEqual(expected, result) + return test + + for f in glob.glob(fixtures_path): + with open(f, 'r') as fd: + data = yaml.load(fd) + + method_name = data['name'].replace(' ', '_').lower() + test_name = 'test_{0}'.format(method_name) + cls_dict[test_name] = gen_test( + data['hw_info'], + data['dynamic_schema'], + data['expected']) + + return type.__new__(mcs, name, bases, cls_dict) + + +@six.add_metaclass(TestGeneratorMeta) +class TestAllocatorIntegration(base.TestCase): + pass