Moved get_scenarios() function to a base module to make it easier to reuse

This will let other tests use it to find fixtures

Change-Id: I4253bb0f742373f8f79dd4bb5886ef98ba81538c
This commit is contained in:
Felipe Reyes 2013-10-01 18:15:21 -03:00
parent dbceb33dac
commit 7d4d411676
2 changed files with 47 additions and 26 deletions

45
tests/base.py Normal file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env python
#
# Joint copyright:
# - Copyright 2012,2013 Wikimedia Foundation
# - Copyright 2012,2013 Antoine "hashar" Musso
# - Copyright 2013 Arnaud Fabre
#
# 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.
import os
import re
def get_scenarios(fixtures_path):
"""Returns a list of scenarios, each scenario being described
by two parameters (yaml and xml filenames).
- content of the fixture .xml file (aka expected)
"""
scenarios = []
files = os.listdir(fixtures_path)
yaml_files = [f for f in files if re.match(r'.*\.yaml$', f)]
for yaml_filename in yaml_files:
xml_candidate = re.sub(r'\.yaml$', '.xml', yaml_filename)
# Make sure the yaml file has a xml counterpart
if xml_candidate not in files:
raise Exception(
"No XML file named '%s' to match " +
"YAML file '%s'" % (xml_candidate, yaml_filename))
scenarios.append((yaml_filename, {
'yaml_filename': yaml_filename, 'xml_filename': xml_candidate
}))
return scenarios

View File

@ -19,7 +19,6 @@
import doctest
import os
import re
from testscenarios.testcase import TestWithScenarios
import testtools
import xml.etree.ElementTree as XML
@ -27,37 +26,14 @@ import yaml
from jenkins_jobs.builder import XmlJob, YamlParser, ModuleRegistry
from jenkins_jobs.modules import publishers
from ..base import get_scenarios
FIXTURES_PATH = os.path.join(
os.path.dirname(__file__), 'fixtures')
def get_scenarios():
"""Returns a list of scenarios, each scenario being described
by two parameters (yaml and xml filenames).
- content of the fixture .xml file (aka expected)
"""
scenarios = []
files = os.listdir(FIXTURES_PATH)
yaml_files = [f for f in files if re.match(r'.*\.yaml$', f)]
for yaml_filename in yaml_files:
xml_candidate = re.sub(r'\.yaml$', '.xml', yaml_filename)
# Make sure the yaml file has a xml counterpart
if xml_candidate not in files:
raise Exception(
"No XML file named '%s' to match " +
"YAML file '%s'" % (xml_candidate, yaml_filename))
scenarios.append((yaml_filename, {
'yaml_filename': yaml_filename, 'xml_filename': xml_candidate
}))
return scenarios
class TestCaseModulePublisher(TestWithScenarios, testtools.TestCase):
scenarios = get_scenarios()
scenarios = get_scenarios(FIXTURES_PATH)
# TestCase settings:
maxDiff = None # always dump text difference