Skip to content

Commit

Permalink
Fix more minor coding issues from Codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
fchauvel committed Nov 18, 2019
1 parent b3cfb31 commit 277376d
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 49 deletions.
2 changes: 1 addition & 1 deletion camp/codecs/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def _parse_goals(self, data):
if not isinstance(item, list):
self._wrong_type(list, type(item), Keys.GOALS, key)
continue
for index, each_name in enumerate(item, 1):
for each_name in item:
running_services.append(Service(str(each_name)))
else:
self._ignore(Keys.GOALS, key)
Expand Down
2 changes: 1 addition & 1 deletion camp/entities/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class NoServiceAndNoFeature(Error):
HINT = "Do we miss required/provided services or features?"

def __init__(self, service):
super(NoServiceProvider, self).__init__(
super(NoServiceAndNoFeature, self).__init__(
self.PROBLEM % service.name,
self.HINT)

Expand Down
5 changes: 2 additions & 3 deletions camp/execute/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from os import listdir
from os.path import isdir, join as join_paths

from re import search

from shlex import split
from subprocess import Popen, PIPE

Expand Down Expand Up @@ -399,14 +397,15 @@ class ReportFormatNotSupported(Exception):
def __init__(self, technology):
self._technology = technology


@property
def technology(self):
return self._technology


@property
def options(self):
return [ each_name for each_name, _ in SUPPORTED_TECHNOLOGIES ]
return [ each_name for each_name, _ in SUPPORTED_REPORT_FORMAT ]



Expand Down
17 changes: 10 additions & 7 deletions camp/realize.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from os import listdir, makedirs, remove, sep as path_separator
from os.path import exists, isdir, isfile, join as join_paths, \
normpath, split as split_path, relpath
normpath, relpath

from pkgutil import get_data

Expand Down Expand Up @@ -120,9 +120,9 @@ def _adjust_docker_compose_file(self, configuration):
# Issue 82: Here we replace "build" clauses by
# "images" clauses to avoid generating additional
# dangling images
content, count = subn(r"build:\s*\./" + each_instance.definition.name,
"image: " + self._docker_tag_for(each_instance),
content)
content = sub(r"build:\s*\./" + each_instance.definition.name,
"image: " + self._docker_tag_for(each_instance),
content)

with open(orchestration, "w") as target:
target.write(content)
Expand Down Expand Up @@ -218,7 +218,8 @@ def _realize_component(self, instance):
self._delete(instance, each_alternative)

else:
message = UNSUPPORTED_COMPONENT_REALIZATION.format(type(any_action))
message = self.UNSUPPORTED_COMPONENT_REALIZATION \
.format(type(any_action))
raise RuntimeError(message)

UNSUPPORTED_COMPONENT_REALIZATION = \
Expand Down Expand Up @@ -269,7 +270,8 @@ def _select_replacement(variable, substitution, value):
raise RuntimeError("Invalid replacements for variable '%s'!" % variable.name)


def _replace_in(self, path, instance, pattern, replacement, escape_pattern=False):
@staticmethod
def _replace_in(path, instance, pattern, replacement, escape_pattern=False):
with open(path, "r+") as resource_file:
content = resource_file.read()

Expand Down Expand Up @@ -370,7 +372,8 @@ def _generate_build_script(self):

OBSELETE_IMAGES_MARKER = "{obselete_images}"

def _fetch_script_template(self):
@staticmethod
def _fetch_script_template():
return get_data('camp', 'data/manage_images.sh').decode("utf-8")


Expand Down
2 changes: 0 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

from camp.util import redirect_stderr_to

from io import StringIO

from os import remove
from os.path import isfile

Expand Down
4 changes: 1 addition & 3 deletions tests/unit/codecs/test_yaml_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@

from __future__ import unicode_literals

from camp.codecs.yaml import YAML, InvalidYAMLModel
from camp.codecs.yaml import YAML
from camp.entities.model import DockerFile, DockerImage, Substitution, \
TestSettings, ResourceSelection, ComponentResourceSelection
from camp.entities.report import SuccessfulTest, FailedTest, ErroneousTest, \
TestSuite, TestReport

from sys import version_info

from unittest import TestCase

try:
Expand Down
23 changes: 2 additions & 21 deletions tests/unit/codecs/test_yaml_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
from camp.codecs.yaml import YAML, InvalidYAMLModel
from camp.entities.model import DockerFile, DockerImage, Substitution, \
TestSettings
from camp.entities.report import SuccessfulTest, FailedTest, ErroneousTest, \
TestReport
from camp.entities.report import SuccessfulTest, FailedTest, ErroneousTest

from unittest import TestCase

Expand Down Expand Up @@ -420,24 +419,6 @@ def test_with_a_number_as_selected_resource_final_name(self):
warning_count=1)


def test_with_a_number_as_component_selected_resource(self):
self.assert_warning(
"components:\n"
" server:\n"
" provides_services: [ Wonderful ]\n"
" realization:\n"
" - select: 1234\n"
" instead_of:\n"
" - nginx_docker-compose.yml\n"
" as: docker-compose.yml\n"
"goals:\n"
" running: [ Wonderful ]\n",
expected="str",
found="int",
path="components/server/realization/#1/select",
warning_count=2)


def test_with_a_number_as_component_resource_alternatives(self):
self.assert_warning(
"components:\n"
Expand Down Expand Up @@ -521,7 +502,7 @@ def setUp(self):
self._codec = YAML()

def assert_no_warning_in(self, text):
model = self._codec.load_model_from(StringIO(text))
self._codec.load_model_from(StringIO(text))

self.assertEqual(0, len(self._codec.warnings))

Expand Down
2 changes: 0 additions & 2 deletions tests/unit/execute/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from os import makedirs, getcwd
from os.path import isdir, join as join_paths

from re import search

from tempfile import gettempdir

from shutil import rmtree
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/generate/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def setUp(self):
self._context.load_metamodel()
self._context.load_model(self._model)

def test_all_metaclasses(self):

def test_all_metaclasses(self):
for each in self.EXPECTED_CLASSES:
self.assertIn(each, self._context)

EXPECTED_CLASSES = ["Value", "Variable", "Service",
"Feature", "Component", "CInstance"]


def test_all_services(self):
for each in self._model.services:
self.assertIn(each.name, self._context)
Expand All @@ -69,4 +69,3 @@ def test_all_values_slots_with_qualified_names(self):
for each_variable in each_component.variables:
qualified_name = "_".join([each_component.name, "0", each_variable.name])
self.assertIn(qualified_name, self._context)

10 changes: 8 additions & 2 deletions tests/unit/generate/test_new_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ def test_given_integer_variables(self):
" max_thread:\n"
" type: Integer\n"
"constraints:\n"
" - CInstance.forall(ci, ci.configuration.exists(val, And([val.variable == variable('server', 'memory'), val.value == 4])))\n"
" - CInstance.forall(ci, ci.configuration.exists(val1, And([val1.variable == variable('server', 'max_thread'), ci.configuration.exists(val2, And([val2.variable == variable('server', 'memory'), val1.value * 2 == val2.value]))])))\n"
" - CInstance.forall(ci, ci.configuration.exists(val,"
"And([val.variable == variable('server', 'memory'),"
" val.value == 4])))\n"
" - CInstance.forall(ci, ci.configuration.exists(val1, "
"And([val1.variable == variable('server', 'max_thread'), "
"ci.configuration.exists(val2, "
"And([val2.variable == variable('server', 'memory'), "
"val1.value * 2 == val2.value]))])))\n"
"goals:\n"
" running: \n"
" - MyService \n",
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/realize/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def verify_script(self):

self.assert_generated(
"config_0/images/build_images.sh",
with_patterns=[
expected_command_order
])
with_patterns=[
expected_command_order
])


def test_ordering_jdk_tc_svr(self):
Expand Down

0 comments on commit 277376d

Please sign in to comment.