Skip to content
Snippets Groups Projects
render-test-case 2.67 KiB
Newer Older
Luis Araujo's avatar
Luis Araujo committed
###################################################################################
# render-test-case: Main program to render test case files.
# Create a HTML page from a YAML test case file.
Luis Araujo's avatar
Luis Araujo committed
# Copyright (C) 2018
# Luis Araujo <luis.araujo@collabora.co.uk>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  US
###################################################################################
import os
import shutil
from argparse import ArgumentParser
from renderer import generate_test_case
if '__main__' == __name__:
    cli_parser = ArgumentParser(description="render-test-case")
    cli_parser.add_argument('-d', '--test-case-dir',
                            help="Directory path for generated test cases")
    cli_parser.add_argument('yaml_files',
                            help="YAML file or files directory")
    args = cli_parser.parse_args()

    directory = '.'
    if args.test_case_dir:
        directory = args.test_case_dir
        try:
            os.mkdir(directory)
        except FileExistsError:
            print("Directory '{}' already exists".format(directory))
        except e:
            print("Error:", e)

    if os.path.isfile(args.yaml_files):
        generate_test_case(args.yaml_files, directory)
    else:
        for root, _, files in os.walk(args.yaml_files):
            for f in files:
                tc_file = os.path.join(root, f)
                if os.path.isfile(tc_file):
                    generate_test_case(tc_file, directory)
                    c += 1
        print("Total of test cases processed:", c)
    # Copy CSS and images directory
    cssdir = os.path.join(directory, 'css')
    if not (os.path.exists(cssdir) and os.path.isdir(cssdir)):
        print("Copying css style to", cssdir)
        shutil.copytree('css/', cssdir)

    imagesdir = os.path.join(directory, 'images')
    if not (os.path.exists(imagesdir) and os.path.isdir(imagesdir)):
        print("Copying images to", imagesdir)
        shutil.copytree('images/', imagesdir)