return False


def relpath(path):
    """Returns the relative path to :param:`path` from BASEDIR.

    :param str path: The full path.
    :returns: str

    """

    return os.path.relpath(path, BASEDIR)


assertTrue(os.path.isdir(GNAThub.root()))
assertEqual(relpath(GNAThub.root()), os.path.join('obj', 'gnathub'))

assertTrue(os.path.isdir(GNAThub.logs()))
assertEqual(relpath(GNAThub.logs()), os.path.join('obj', 'gnathub', 'logs'))

assertTrue(os.path.isfile(GNAThub.database()))
assertEqual(relpath(GNAThub.database()),
            os.path.join('obj', 'gnathub', 'gnathub.db'))

#DB content check

# Check tool exists
TOOL = 'gnatcheck'
assertTrue(contains(TOOL))

# Tools dictionary fron DB
Exemple #2
0
# The base directory for PATH comparisons
BASEDIR = os.path.dirname(os.path.realpath(sys.argv[0]))


def relpath(path):
    """Return the relative path to :param:`path` from BASEDIR.

    :param str path: The full path.
    :returns: str
    """

    return os.path.relpath(path, BASEDIR)


# GNAThub.Project.name
assertEqual(GNAThub.Project.name(), 'Disabled')

# GNAThub.Project.path
assertEqual(relpath(GNAThub.Project.path()), 'disabled.gpr')

# GNAThub.Project.object_dir
assertEqual(relpath(GNAThub.Project.object_dir()), 'obj')
assertTrue(os.path.isdir(GNAThub.Project.object_dir()))

# GNAThub.Project.source_dirs
source_dirs = GNAThub.Project.source_dirs()
assertEqual(len(source_dirs), 1)
assertIn('Disabled', source_dirs)
assertEqual(relpath(source_dirs['Disabled'][0]), 'src')

# GNAThub.Project.source_files
    :param tool_name: the name of the tool to check existence for
    :type tool_name: str
    :return: `True` if the tool exists, `False` otherwise
    :rtype: boolean
    """
    for tool in GNAThub.Tool.list():
        if tool.name == tool_name:
            return True
    return False


# Check that spark2014 tool exists in the DB
TOOL_NAME = 'spark2014'
assertTrue(contains(TOOL_NAME))
tool = GNAThub.Tool(TOOL_NAME)

# Check that rules were created in the Rules table
rules = [rule.id for rule in GNAThub.Rule.list() if rule.tool_id == tool.id]
assertNotEmpty(rules)
assertEqual(len(rules), 12)

# Check that messages were recorded in Messages table
messages = GNAThub.Message.list()
assertNotEmpty(messages)
assertNotEmpty([msg for msg in GNAThub.Message.list() if msg.rule_id in rules])

# Check that all resources were recorded in Ressources table
resources = GNAThub.Resource.list()
assertNotEmpty(resources)
assertEqual(len(resources), 4)
Exemple #4
0
        """Overridden."""
        global MY_REPORT_VARIABLE
        MY_REPORT_VARIABLE = True


# GNAThub.Runner interface not implemented
with assertRaises(TypeError):
    # A type error occurs when the RUN method is not overridden
    MyIncompleteRunnerPlugin()

# GNAThub.Reporter interface not implemented
with assertRaises(TypeError):
    # A type error occurs when the REPORT method is not overridden
    MyIncompleteReporterPlugin()

MyCustomRunnerPlugin()  # Fails if it raises an exception
MyCustomReporterPlugin()  # Fails if it raises an exception
PLUGIN = MyCustomPlugin()

# GNAThub.Plugin.name
assertEqual(PLUGIN.name, 'My Custom Plugin')

# GNAThub.Plugin.exec_status (getter)
assertEqual(PLUGIN.exec_status, GNAThub.NOT_EXECUTED)

# GNAThub.Plugin.exec_status (setter)
with assertRaises(GNAThub.Error):
    PLUGIN.exec_status = 'invalid value'

PLUGIN.exec_status = GNAThub.EXEC_SUCCESS
            return True
    return False

def relpath(path):
    """Returns the relative path to :param:`path` from BASEDIR.

    :param str path: The full path.
    :returns: str

    """

    return os.path.relpath(path, BASEDIR)


assertTrue(os.path.isdir(GNAThub.root()))
assertEqual(relpath(GNAThub.root()), os.path.join('obj', 'gnathub'))

assertTrue(os.path.isdir(GNAThub.logs()))
assertEqual(relpath(GNAThub.logs()), os.path.join('obj', 'gnathub', 'logs'))

assertTrue(os.path.isfile(GNAThub.database()))
assertEqual(
    relpath(GNAThub.database()),
    os.path.join('obj', 'gnathub', 'gnathub.db')
)

#DB content check

# Check tool exists
TOOL = 'gnatmetric'
assertTrue(contains(TOOL))
Exemple #6
0
assertIsNotNone(resource)
tool = GNAThub.Tool('test-tool')
assertIsNotNone(tool)
rule = GNAThub.Rule('test-rule', 'test-rule-name', GNAThub.RULE_KIND, tool)
assertIsNotNone(rule)
prop0 = GNAThub.Property('test-prop-0', 'test-prop-name-0')
assertIsNotNone(prop0)
prop1 = GNAThub.Property('test-prop-1', 'test-prop-name-1')
assertIsNotNone(prop1)

msg0 = GNAThub.Message(rule, 'test message', properties=None)
assertIsNotNone(msg0)
assertEmpty(msg0.get_properties())

msg1 = GNAThub.Message(rule, 'test message', properties=[prop0, prop1])
assertIsNotNone(msg1)

for msg in msg0, msg1:
    resource.add_message(msg)

assertNotEmpty(msg1.get_properties())
msg1_prop0 = msg1.get_properties()[0]
assertEqual(prop0.name, msg1_prop0.name)
assertEqual(prop0.identifier, msg1_prop0.identifier)

with assertRaises(Exception):
    GNAThub.Message(rule, 'test message', properties=0)

with assertRaises(Exception):
    GNAThub.Message(rule, 'test message', properties=prop0)
"""Check the integrity of the GNAThub Python module."""

import GNAThub
from support.asserts import assertEqual

# GNAThub.Project.target (overridden by switches)
assertEqual(GNAThub.Project.target(), 'my-custom-target')

# GNAThub.Project.runtime (overridden by switches)
assertEqual(GNAThub.Project.runtime(), 'my-custom-runtime')
Exemple #8
0
        """Overridden."""
        global MY_REPORT_VARIABLE
        MY_REPORT_VARIABLE = True


# GNAThub.Runner interface not implemented
with assertRaises(TypeError):
    # A type error occurs when the RUN method is not overridden
    MyIncompleteRunnerPlugin()

# GNAThub.Reporter interface not implemented
with assertRaises(TypeError):
    # A type error occurs when the REPORT method is not overridden
    MyIncompleteReporterPlugin()

MyCustomRunnerPlugin()    # Fails if it raises an exception
MyCustomReporterPlugin()  # Fails if it raises an exception
PLUGIN = MyCustomPlugin()

# GNAThub.Plugin.name
assertEqual(PLUGIN.name, 'My Custom Plugin')

# GNAThub.Plugin.exec_status (getter)
assertEqual(PLUGIN.exec_status, GNAThub.NOT_EXECUTED)

# GNAThub.Plugin.exec_status (setter)
with assertRaises(GNAThub.Error):
    PLUGIN.exec_status = 'invalid value'

PLUGIN.exec_status = GNAThub.EXEC_SUCCESS
"""Check the integrity of the GNAThub Python module."""

import GNAThub
from support.asserts import assertEqual

# GNAThub.Project.target (not overridden)
assertEqual(GNAThub.Project.target(), 'arm-eabi')

# GNAThub.Project.runtime (not overridden)
assertEqual(GNAThub.Project.runtime(), 'ravenscar-sfp-stm32f4')
Exemple #10
0
BASEDIR = os.path.dirname(os.path.realpath(sys.argv[0]))


def relpath(path):
    """Returns the relative path to :param:`path` from BASEDIR.

    :param str path: The full path.
    :returns: str

    """

    return os.path.relpath(path, BASEDIR)


assertTrue(os.path.isdir(GNAThub.root()))
assertEqual(relpath(GNAThub.root()), os.path.join('obj', 'gnathub'))

assertTrue(os.path.isdir(GNAThub.logs()))
assertEqual(relpath(GNAThub.logs()), os.path.join('obj', 'gnathub', 'logs'))

assertTrue(GNAThub.quiet())
assertFalse(GNAThub.verbose())
assertFalse(GNAThub.dry_run())
assertTrue(GNAThub.runners_only())
assertFalse(GNAThub.reporters_only())

assertTrue(os.path.isfile(GNAThub.database()))
assertEqual(
    relpath(GNAThub.database()),
    os.path.join('obj', 'gnathub', 'gnathub.db')
)
Exemple #11
0
# The base directory for PATH comparisons
BASEDIR = os.path.dirname(os.path.realpath(sys.argv[0]))


def relpath(path):
    """Return the relative path to :param:`path` from BASEDIR.

    :param str path: The full path.
    :returns: str
    """

    return os.path.relpath(path, BASEDIR)


# GNAThub.Project.name
assertEqual(GNAThub.Project.name(), 'Disabled')

# GNAThub.Project.path
assertEqual(relpath(GNAThub.Project.path()), 'disabled.gpr')

# GNAThub.Project.object_dir
assertEqual(relpath(GNAThub.Project.object_dir()), 'obj')
assertTrue(os.path.isdir(GNAThub.Project.object_dir()))

# GNAThub.Project.source_dirs
source_dirs = GNAThub.Project.source_dirs()
assertEqual(len(source_dirs), 1)
assertIn('Disabled', source_dirs)
assertEqual(relpath(source_dirs['Disabled'][0]), 'src')

# GNAThub.Project.source_files