Generate tests by fixtures
This commit is contained in:
parent
1089aa3b8a
commit
025b799afd
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue