Skip to content

Commit

Permalink
Fix Issue #25
Browse files Browse the repository at this point in the history
  • Loading branch information
fchauvel committed Nov 22, 2018
1 parent 46022e7 commit cb1fc50
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 66 deletions.
7 changes: 2 additions & 5 deletions .github/ISSUE_DOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ the role of the user and the business benefit that the new
functionality provides. For bugs, this section should describe as
well:

- the observed execution behavior and obtained results;

- the expected execution behavior and results.
- the observed execution behavior and obtained results;
- the expected execution behavior and results.

#### Steps to reproduce
A detailed description, step-by-step of the procedure followed by the
Expand All @@ -63,7 +62,5 @@ relationships can be used to structure them, grouping related
features. Possible relationships:

- Child of / Parent of

- Related to

- Depends on
5 changes: 0 additions & 5 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#### Characteristics

- **Issue Type**: \[bug, feature, test report]

- **Reproducibility**: \[always, sometimes, random]

- **Severity**: \[feature, minor, major, crash, block]

- **Tool/Service/Component**: \[name, version]

- **Execution Environment**: \[platform, OS, etc]

- **Reporter**: \[name, mail]

#### Description
Expand Down
25 changes: 17 additions & 8 deletions camp/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@



from camp.directories import InputDirectory, OutputDirectory
from camp.directories import InputDirectory, OutputDirectory, MissingModel
from camp.entities.validation import Checker
from camp.execute.parsers import ConfigINIParser
from camp.execute.command.commands import ConductExperimentRunner
Expand All @@ -30,10 +30,17 @@ def __init__(self, codec, solver, realize):

def generate(self, arguments):
self._prepare_directories(arguments)
model = self._load_model()
configurations = self._generate_configurations(arguments, model)
for index, each_configuration in enumerate(configurations, 1):
self._save(index, each_configuration)
try:
model = self._load_model()
configurations = self._generate_configurations(arguments, model)
for index, each_configuration in enumerate(configurations, 1):
self._save(index, each_configuration)

except MissingModel as error:
print "Error:"
print " -", error.problem
print " ", error.hint



def _prepare_directories(self, arguments):
Expand All @@ -48,8 +55,8 @@ def _load_model(self):
print "Model loaded from '%s'." % file_name
for each_warning in warnings:
print " - WARNING: ", str(each_warning)

checker = Checker(workspace=self._input.path)

model.accept(checker)
if checker.errors:
for each_error in checker.errors:
Expand All @@ -73,7 +80,8 @@ def _save(self, index, configuration):
self._summarize(configuration)


def _summarize(self, configuration):
@staticmethod
def _summarize(configuration):
components = set()
for each in configuration.instances:
name = each.definition.name
Expand Down Expand Up @@ -101,8 +109,9 @@ def _load_configurations(self, model):
return self._output.existing_configurations(model)


@staticmethod
def execute(self, arguments):
parser = ConfigINIParser()
config = parser.parse(arguments.configuration_file)
experiment = ConductExperimentRunner(config)
result = experiment.run()
experiment.run()
40 changes: 31 additions & 9 deletions camp/directories.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,32 @@
from re import search


class MissingModel(Exception):


def __init__(self, directory):
self._directory = directory


@property
def problem(self):
return self.PROBLEM % self._directory

PROBLEM = "Cannot find any model in '%s'."


@property
def hint(self):
candidates = ", ".join(InputDirectory.MODEL_NAMES)
return self.HINT % candidates

HINT = "CAMP looks for one of the following files: %s."



class Directory(object):


def __init__(self, path):
self._path = path

Expand All @@ -31,7 +53,7 @@ def __init__(self, path):
def path(self):
return self._path




class InputDirectory(Directory):
Expand All @@ -56,7 +78,7 @@ def _find_model(self):
for any_valid_name in self.MODEL_NAMES:
if any_file == any_valid_name:
return any_file
raise ValueError("Unable to find the CAMP model")
raise MissingModel(self._path)


MODEL_NAMES = [
Expand All @@ -65,9 +87,9 @@ def _find_model(self):
"input.yml", "input.yml"
]


def create_template_file(self, component_name, path, content):
resource = join_paths(self._path, self.TEMPLATE_FOLDER, component_name, path)
resource = join_paths(self._path, self.TEMPLATE_FOLDER, component_name, path)
folder = dirname(resource)
if not isdir(folder):
makedirs(folder)
Expand All @@ -84,12 +106,12 @@ def component_templates(self):
if isdir(any_file):
templates.append(any_file)
return templates



class OutputDirectory(Directory):


def __init__(self, path, codec=None):
super(OutputDirectory, self).__init__(path)
self._codec = codec or YAML()
Expand Down Expand Up @@ -154,8 +176,8 @@ def images_generated_for(self, index):
if isdir(any_file):
images.append(any_file)
return images


def create_file(self, path, content):
folder = dirname(path)
self._create(folder)
Expand Down
90 changes: 55 additions & 35 deletions docs/pages/changelog.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,59 @@
# CAMP Versions

Below is the list of CAMP version, along with a quick summary of the
Below is the list of CAMP versions, along with a quick summary of the
changes that were made.

* CAMP v0.2

* CAMP v0.2.2
* Update the documentation of the CityGo case to explain why there
are only 10 configurations possible, as noted in [Issue
#24](https://github.com/STAMP-project/camp/issues/23)
* Fix issue with the "buildall.sh" script as per [Issue
23](https://github.com/STAMP-project/camp/issues/23)
* New documentation page that explains how to contribute to the
code and documentation.

* CAMP v0.2.1
* Fix issue in the setup.py that prevented building a correct Docker
image.
* CAMP v0.2.0

* Consolidated input files (now only one, as per [Issue
#19](https://github.com/STAMP-project/camp/issues/19))
* Input Validation (as per [Issue
#20](https://github.com/STAMP-project/camp/issues/20) and
[Issue 21](https://github.com/STAMP-project/camp/issues/21))
* Support for coverage over integer variables (see Atos case-study,
[Issue #22](https://github.com/STAMP-project/camp/issues/22))
* Integrate the solution of both case-study, so that both are solved
with the same code.
* Revised the documentation ([Issue
#18](https://github.com/STAMP-project/camp/issues/18))

* CAMP v0.1
* First complete draft
* Common command line interface for all three commands, generate,
realize and execute.

* CAMP v0.2

* CAMP v0.2.3 (under development)

* Fix reporting of missing CAMP model, as per [Issue
#25](https://github.com/STAMP-project/camp/issues/25)

* Activating Codecov to monitor test code coverage

* Removing code duplication in tests

* CAMP v0.2.2

* Update the documentation of the CityGo case to explain why
there are only 10 possible configurations, as noted in
[Issue
#24](https://github.com/STAMP-project/camp/issues/24)

* Fix the generation of the `build_images.sh` script as per
[Issue
#23](https://github.com/STAMP-project/camp/issues/23)

* New documentation page that explains how to contribute to
the code and documentation.

* CAMP v0.2.1

* Fix issue in the setup.py that prevented building a correct
Docker imag

* CAMP v0.2.0

* Consolidated input files (now only one, as per [Issue
#19](https://github.com/STAMP-project/camp/issues/19))

* Input Validation (as per [Issue
#20](https://github.com/STAMP-project/camp/issues/20) and
[Issue #21](https://github.com/STAMP-project/camp/issues/21))

* Support for coverage over integer variables (see Atos case-study,
[Issue #22](https://github.com/STAMP-project/camp/issues/22))

* Integrate the solution of both case-study, so that both are solved
with the same code.

* Revised the documentation ([Issue
#18](https://github.com/STAMP-project/camp/issues/18))

* CAMP v0.1

* First complete draft

* Common command line interface for all three commands,
generate, realize and execute.
16 changes: 12 additions & 4 deletions tests/acceptance/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from camp.realize import Builder
from camp.run import Runner

from os import listdir
from os import listdir, makedirs
from os.path import exists, isdir, join as join_paths, basename

from shutil import copytree, rmtree
Expand All @@ -39,12 +39,20 @@ def __init__(self, path, workspace):
@staticmethod
def _copy(source, workspace):
destination = join_paths(workspace, basename(source))
if isdir(destination):
rmtree(destination)
copytree(source, destination)
if source and exists(source):
if isdir(destination):
rmtree(destination)
copytree(source, destination)
else:
raise RuntimeError("Source '%s' is not a folder!" % source)
else:
if isdir(destination):
rmtree(destination)
makedirs(destination)
return destination



@property
def directory(self):
return self._input.path
Expand Down
29 changes: 29 additions & 0 deletions tests/acceptance/test_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# CAMP
#
# Copyright (C) 2017, 2018 SINTEF Digital
# All rights reserved.
#
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE file for details.
#



from tests.acceptance.commons import Sample, CampTests


class MissingCAMPModelIsReported(CampTests):


def setUp(self):
self.sample = Sample("no_camp_model", self.WORKSPACE)

WORKSPACE = "tmp/acceptance/errors"


def test_when_we_generate_all(self):
self.generate_all()



0 comments on commit cb1fc50

Please sign in to comment.