def test_with_arguments(self) -> None: """ If passing additional arguments (relative paths) results in a correct result """ self.assertEqual( os.path.join(DEFAULT_PATH, "archive/test/report.json"), get_path('archive', 'test', 'report.json'))
def test_without_arguments(self) -> None: """ If the function generally works """ # Without explicitly setting the environmental variable to specify a different installation path, the call of # the function without any arguments should return the default path self.assertEqual(DEFAULT_PATH, get_path())
def tearDown(self) -> None: super(UfotestBuildTestMixin, self).tearDown() # After every test we need to make sure that the build lock is released again or it will have an effect on all # the test which come after. if BuildLock.is_locked(): BuildLock.release() # Additionally we need to clear the entire test and build archive for root, folders, files in os.walk(get_path('archive')): for folder in folders: folder_path = os.path.join(root, folder) shutil.rmtree(folder_path) for root, folders, files in os.walk(get_path('builds')): for folder in folders: folder_path = os.path.join(root, folder) shutil.rmtree(folder_path)
def __init__(self, config: Config): AbstractCamera.__init__(self, config) InternalDictMixin.__init__(self) self.enabled = False # -- loading the sample image self.image_path = get_path('static', 'mock.jpg') self.image = self.load_image(self.image_path)
def save_config(): try: data = request.get_json() content = data['content'] with open(get_path('config.toml'), mode='w') as config_file: config_file.write(content) return 'Config file saved', 200 except: return 'There has been an error', 400
def __init__(self, repository_url: str, branch_name: str, commit_name: str, test_suite: str, config: Config = Config()): # constructed attributes self.repository_url = repository_url self.branch = branch_name self.commit = commit_name self.test_suite = test_suite # calculated attributes self.config = config self.creation_datetime = datetime.datetime.now() self.version = get_version() self.test_context = TestContext() # derived attributes self.repository_name = get_repository_name(repository_url) self.repository_path = get_path(self.repository_name) # Adding a portion of the commit hash to the folder name has been a recent addition, because I noticed that the # program crashes if there are two build triggered in the same minute. Also: Adding the commit also has the # advantage of additional information. self.folder_name = '{}__{}__{}'.format( self.repository_name, self.commit[:6], self.creation_datetime.strftime('%Y_%m_%d__%H_%M_%S')) self.folder_path = get_path('builds', self.folder_name) # non initialized attributes # These are the attributes, which have to be declared, but which cannot be initialized in the constructor. # The start and end time of course can only be acquired during the actual start and end. # The bitfile path actually has to be set by the BuildRunner. It is not known in before hand! The test report # as well can obviously only be added after the actual test are done. self.start_datetime: Optional[datetime.datetime] = None self.end_datetime: Optional[datetime.datetime] = None self.bitfile_path = None self.test_report: Optional[TestReport] = None # This is a flag, which is supposed to be set by the build runner, after the build process is over. This would # signify that the build context indeed contains information about a valid build process. self.completed = False
def config(): template = get_template('config.html') with open(get_path('config.toml')) as config_file: config_lines = config_file.readlines() context = { 'line_count': len(config_lines), 'config_content': ''.join(config_lines) } return template.render(context), 200
def test_with_custom_installation_path(self) -> None: """ If a correct path is returned when defining a custom installation path with the env variable """ temp_folder = tempfile.TemporaryDirectory() os.environ['UFOTEST_PATH'] = temp_folder.name self.assertEqual(temp_folder.name, get_path()) # Cleaning up to not influence other tests temp_folder.cleanup() del os.environ['UFOTEST_PATH']
def get_path(self, *sub_paths): return get_path('archive', self.folder_name, *sub_paths)
import click from flask import Flask, request, send_from_directory, jsonify from ufotest.config import Config, get_path from ufotest.util import get_template, get_version from ufotest.util import cerror, cprint, cresult from ufotest.util import get_build_reports, get_test_reports from ufotest.util import get_folder_size, format_byte_size from ufotest.exceptions import BuildError from ufotest.camera import UfoCamera from ufotest.ci.build import BuildQueue, BuildLock, BuildRunner, BuildReport, build_context_from_request from ufotest.ci.mail import send_report_mail CONFIG = Config() PATH = get_path() ARCHIVE_PATH = os.path.join(PATH, 'archive') BUILDS_PATH = os.path.join(PATH, 'builds') STATIC_PATH = os.path.join(PATH, 'static') PLUGINS_PATH = os.path.join(PATH, 'plugins') class BuildAdapterGitlab(object): def __init__(self, data: dict): self.data = data def get(self): build = { 'repository': { 'name': self.data['repository']['name'],
def test_lock_path_is_relative(self) -> None: """ If the lock file is actually within the correct installation folder. """ self.assertEqual(os.path.dirname(BuildLock.get_lock_path()), get_path())
def get_lock_path(cls) -> str: """Returns the path of the lock file. :return: The string path of the file which is used as the build lock """ return get_path(cls.LOCK_FILE_NAME)
import datetime import shutil import json import traceback from contextlib import AbstractContextManager from typing import Optional from ufotest.config import Config, get_path, get_builds_path from ufotest.exceptions import raise_if, IncompleteBuildError, BuildError from ufotest.util import cprint, cresult, cerror from ufotest.util import (AbstractRichOutput, get_repository_name, execute_command, run_command, get_command_output, get_template, get_version) from ufotest.testing import TestRunner, TestReport, TestContext UFOTEST_PATH = get_path() BUILDS_PATH = get_builds_path() # FUNCTIONS def build_context_from_config(config: Config) -> BuildContext: """Creates a new BuildContext instance from the provided *config*. This function is mainly for the purpose of a manual build trigger. For manually triggering a build there obviously is no request data from which to get the repo url / commit hash from, which is why it will use the information which were defined in the config file. :return: The build context which was based on the information in the config file in the ufotest folder """ repository_url = config.get_ci_repository_url()