Skip to content

Commit

Permalink
Merge pull request #377 from JrGoodle/coverage
Browse files Browse the repository at this point in the history
Add support for code coverage
  • Loading branch information
JrGoodle committed Nov 7, 2017
2 parents 643479b + 91ea031 commit 80badd1
Show file tree
Hide file tree
Showing 77 changed files with 818 additions and 818 deletions.
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[run]
branch = True
concurrency = multiprocessing
parallel = True
omit =
# omit everything in /usr
/usr/*
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ before_script:
- script/test

script:
- if [ "$TARGET" = "cats" ]; then clowder-test unittests "$PYVERSION" || exit 1; clowder-test cats all; fi
- if [ "$TARGET" = "cats" ]; then clowder-test --coverage cats all; fi
- if [ "$TARGET" = "cocos2d" ]; then clowder-test cocos2d all; fi
- if [ "$TARGET" = "llvm" ]; then clowder-test llvm all; fi
- if [ "$TARGET" = "parallel" ]; then clowder-test parallel; fi
- if [ "$TARGET" = "swift" ]; then clowder-test swift all; fi

after_script:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then coverage combine examples/cats; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then coverage xml; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi

after_success: if [ "$TRAVIS_OS_NAME" = "osx" ]; then script/deploy; fi

branches:
Expand Down
11 changes: 11 additions & 0 deletions clowder/clowder/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
"""Clowder module __init__
.. codeauthor:: Joe Decapo <joe@polka.cat>
"""

import os


ROOT_DIR = os.getcwd()
4 changes: 1 addition & 3 deletions clowder/clowder/cli/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"""

import os

from clowder.clowder_controller import ClowderController


CLOWDER_CONTROLLER = ClowderController(os.getcwd())
CLOWDER_CONTROLLER = ClowderController()
3 changes: 2 additions & 1 deletion clowder/clowder/cli/save_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from cement.ext.ext_argparse import ArgparseController, expose

import clowder.util.formatting as fmt
from clowder import ROOT_DIR
from clowder.cli.globals import CLOWDER_CONTROLLER
from clowder.cli.util import (
validate_groups,
Expand Down Expand Up @@ -58,7 +59,7 @@ def _save(self):
validate_groups(CLOWDER_CONTROLLER.groups)

version_name = self.app.pargs.version.replace('/', '-') # Replace path separators with dashes
version_dir = os.path.join(CLOWDER_CONTROLLER.root_directory, '.clowder', 'versions', version_name)
version_dir = os.path.join(ROOT_DIR, '.clowder', 'versions', version_name)
_make_dir(version_dir)

yaml_file = os.path.join(version_dir, 'clowder.yaml')
Expand Down
4 changes: 2 additions & 2 deletions clowder/clowder/cli/yaml_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _yaml(self):
"""Clowder yaml command private implementation"""

if self.app.pargs.resolved:
print(fmt.yaml_string(CLOWDER_CONTROLLER.get_yaml_resolved()))
print(fmt.yaml_string(CLOWDER_CONTROLLER.get_yaml(resolved=True)))
else:
print_yaml(CLOWDER_CONTROLLER.root_directory)
print_yaml()
sys.exit() # exit early to prevent printing extra newline
36 changes: 14 additions & 22 deletions clowder/clowder/clowder_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@
class ClowderController(object):
"""Class encapsulating project information from clowder.yaml for controlling clowder
:ivar str root_directory: Root directory of clowder projects
:ivar dict defaults: Global clowder.yaml defaults
:ivar list[Group] groups: List of all Groups
:ivar list[Source] sources: List of all Sources
"""

def __init__(self, root_directory):
"""ClowderController __init__
def __init__(self):
"""ClowderController __init__"""

:param str root_directory: Root directory of clowder projects
"""

self.root_directory = root_directory
self.defaults = None
self.groups = []
self.sources = []
Expand Down Expand Up @@ -114,36 +109,33 @@ def get_timestamp(self, timestamp_project):

return timestamp

def get_yaml(self):
"""Return python object representation for saving yaml
:return: YAML python object
:rtype: dict
"""

return {'defaults': self.defaults.get_yaml(),
'sources': [s.get_yaml() for s in self.sources],
'groups': [g.get_yaml() for g in self.groups]}
def get_yaml(self, resolved=False):
"""Return python object representation of model objects
def get_yaml_resolved(self):
"""Return python object representation for resolved yaml
.. py:function:: get_yaml(self, resolved=False)
:param Optional[bool] resolved: Whether to return resolved yaml
:return: YAML python object
:rtype: dict
"""

if resolved:
groups = [g.get_yaml(resolved=True) for g in self.groups]
else:
groups = [g.get_yaml() for g in self.groups]

return {'defaults': self.defaults.get_yaml(),
'sources': [s.get_yaml() for s in self.sources],
'groups': [g.get_yaml_resolved() for g in self.groups]}
'groups': groups}

def _load_yaml(self):
"""Load clowder.yaml"""
try:
yaml = load_yaml(self.root_directory)
yaml = load_yaml()
self.defaults = Defaults(yaml['defaults'])
self.sources = [Source(s) for s in yaml['sources']]
for group in yaml['groups']:
self.groups.append(Group(self.root_directory, group, self.defaults, self.sources))
self.groups.append(Group(group, self.defaults, self.sources))
except (AttributeError, TypeError):
self.defaults = None
self.sources = []
Expand Down
35 changes: 16 additions & 19 deletions clowder/clowder/clowder_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from termcolor import colored

import clowder.util.formatting as fmt
from clowder import ROOT_DIR
from clowder.error.clowder_error import ClowderError
from clowder.error.clowder_yaml_error import ClowderYAMLError
from clowder.git.project_repo import ProjectRepo
Expand All @@ -35,34 +36,29 @@
class ClowderRepo(object):
"""Class encapsulating clowder repo information
:ivar str root_directory: Root directory of clowder projects
:ivar str default_ref: Default ref
:ivar str remote: Remote name
:ivar str clowder_path: Absolute path to clowder repo
"""

def __init__(self, root_directory):
"""ClowderController __init__
def __init__(self):
"""ClowderController __init__"""

:param str root_directory: Root directory of clowder projects
"""

self.root_directory = root_directory
self.default_ref = 'refs/heads/master'
self.remote = 'origin'
self.clowder_path = os.path.join(self.root_directory, '.clowder')
self.clowder_path = os.path.join(ROOT_DIR, '.clowder')
self.repo = ProjectRepo(self.clowder_path, self.remote, self.default_ref)

# Create clowder.yaml symlink if .clowder dir and yaml file exist
clowder_symlink = os.path.join(self.root_directory, 'clowder.yaml')
clowder_symlink = os.path.join(ROOT_DIR, 'clowder.yaml')
if os.path.isdir(self.clowder_path):
if not os.path.islink(clowder_symlink):
self.link()

self.error = None
if os.path.islink(clowder_symlink):
try:
validate_yaml(os.path.join(self.root_directory, 'clowder.yaml'), self.root_directory)
validate_yaml(os.path.join(ROOT_DIR, 'clowder.yaml'))
except ClowderYAMLError as err:
self.error = err
except (KeyboardInterrupt, SystemExit):
Expand Down Expand Up @@ -139,7 +135,7 @@ def init_exit_handler(self):
"""Exit handler for deleting files if init fails"""

if os.path.isdir(self.clowder_path):
clowder_yaml = os.path.join(self.root_directory, 'clowder.yaml')
clowder_yaml = os.path.join(ROOT_DIR, 'clowder.yaml')
if not os.path.islink(clowder_yaml):
remove_directory(self.clowder_path)
sys.exit(1)
Expand All @@ -153,7 +149,8 @@ def is_dirty(self):

return self.repo.is_dirty()

def link(self, version=None):
@staticmethod
def link(version=None):
"""Create symlink pointing to clowder.yaml file
.. py:function:: link(version=None)
Expand All @@ -162,18 +159,18 @@ def link(self, version=None):
"""

if version is None:
yaml_file = os.path.join(self.root_directory, '.clowder', 'clowder.yaml')
yaml_file = os.path.join(ROOT_DIR, '.clowder', 'clowder.yaml')
path_output = fmt.get_path('.clowder/clowder.yaml')
else:
relative_path = os.path.join('.clowder', 'versions', version, 'clowder.yaml')
path_output = fmt.get_path(relative_path)
yaml_file = os.path.join(self.root_directory, relative_path)
yaml_file = os.path.join(ROOT_DIR, relative_path)

if not os.path.isfile(yaml_file):
print('\n' + path_output + " doesn't seem to exist\n")
sys.exit(1)

yaml_symlink = os.path.join(self.root_directory, 'clowder.yaml')
yaml_symlink = os.path.join(ROOT_DIR, 'clowder.yaml')
print(' - Symlink ' + path_output)
force_symlink(yaml_file, yaml_symlink)

Expand All @@ -185,7 +182,7 @@ def print_status(self, fetch=False):
:param Optional[str] fetch: Fetch before printing status
"""

repo_path = os.path.join(self.root_directory, '.clowder')
repo_path = os.path.join(ROOT_DIR, '.clowder')
if not existing_git_repository(repo_path):
output = colored('.clowder', 'green')
print(output)
Expand All @@ -198,14 +195,14 @@ def print_status(self, fetch=False):
project_output = format_project_string(self.repo, '.clowder')
current_ref_output = format_project_ref_string(self.repo)

clowder_symlink = os.path.join(self.root_directory, 'clowder.yaml')
clowder_symlink = os.path.join(ROOT_DIR, 'clowder.yaml')
if not os.path.islink(clowder_symlink):
print(project_output + ' ' + current_ref_output)
return

real_path = os.path.realpath(clowder_symlink)
symlink_output = fmt.get_path('clowder.yaml')
clowder_path = fmt.remove_prefix(real_path + '/', self.root_directory)
clowder_path = fmt.remove_prefix(real_path + '/', ROOT_DIR)
path_output = fmt.get_path(clowder_path[1:-1])
print(project_output + ' ' + current_ref_output)
print(symlink_output + ' -> ' + path_output + '\n')
Expand Down Expand Up @@ -243,7 +240,7 @@ def _validate_groups(self):
sys.exit(1)


CLOWDER_REPO = ClowderRepo(os.getcwd())
CLOWDER_REPO = ClowderRepo()


def print_clowder_repo_status(func):
Expand Down
7 changes: 3 additions & 4 deletions clowder/clowder/model/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from termcolor import colored

from clowder import ROOT_DIR
from clowder.git.project_repo import ProjectRepo
from clowder.git.util import (
existing_git_repository,
Expand All @@ -27,16 +28,14 @@ class Fork(object):
:ivar str remote_name: Git remote name
"""

def __init__(self, fork, root_directory, path, source):
def __init__(self, fork, path, source):
"""Project __init__
:param dict fork: Parsed YAML python object for fork
:param str root_directory: Root directory of clowder projects
:param str path: Fork relative path
:param Source source: Source instance
"""

self._root_directory = root_directory
self.path = path
self.name = fork['name']
self.remote_name = fork['remote']
Expand All @@ -49,7 +48,7 @@ def full_path(self):
:rtype: str
"""

return os.path.join(self._root_directory, self.path)
return os.path.join(ROOT_DIR, self.path)

def get_yaml(self):
"""Return python object representation for saving yaml
Expand Down
27 changes: 10 additions & 17 deletions clowder/clowder/model/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from __future__ import print_function

import clowder.util.formatting as fmt
from clowder.git.project_repo import ProjectRepo
from clowder.git.util import existing_git_repository
from clowder.model.project import Project

Expand All @@ -26,10 +25,9 @@ class Group(object):
:ivar list[Project] projects: List of group's projects
"""

def __init__(self, root_directory, group, defaults, sources):
def __init__(self, group, defaults, sources):
"""Groups __init__
:param str root_directory: Root directory of clowder projects
:param dict group: Parsed YAML python object for group
:param Defaults defaults: Defaults instance
:param list[Source] sources: List of Source instances
Expand All @@ -47,7 +45,7 @@ def __init__(self, root_directory, group, defaults, sources):
if source.name == source_name:
self.source = source

self.projects = [Project(root_directory, p, group, defaults, sources) for p in group['projects']]
self.projects = [Project(p, group, defaults, sources) for p in group['projects']]
self.projects.sort(key=lambda p: p.path)

def existing_branch(self, branch, is_remote):
Expand All @@ -70,32 +68,27 @@ def existing_projects(self):

return all([existing_git_repository(project.full_path()) for project in self.projects])

def get_yaml(self):
"""Return python object representation for saving yaml
def get_yaml(self, resolved=False):
"""Return python object representation of model objects
:return: YAML python object
:rtype: dict
"""

projects_yaml = [p.get_yaml() for p in self.projects]
return {'name': self.name, 'projects': projects_yaml}

def get_yaml_resolved(self):
"""Return python object representation for resolved yaml
.. py:function:: get_yaml(self, resolved=False)
:param Optional[bool] resolved: Whether to return resolved yaml
:return: YAML python object
:rtype: dict
"""

projects_yaml = [p.get_yaml(resolved=True) for p in self.projects]
if not resolved:
return {'name': self.name,
'projects': [p.get_yaml() for p in self.projects]}

group = {'name': self.name,
'depth': self.depth,
'ref': self.ref,
'recursive': self.recursive,
'remote': self.remote_name,
'source': self.source.name,
'projects': projects_yaml}
'projects': [p.get_yaml(resolved=True) for p in self.projects]}

if self.timestamp_author:
group['timestamp_author'] = self.timestamp_author
Expand Down

0 comments on commit 80badd1

Please sign in to comment.