Repository: mathLab/GRAPE (language: python)

Issue:
Codacy Issues
Solve issues from Codacy


Discussion / hints:

Fix patch:
diff --git a/grape/fault_diagnosis.py b/grape/fault_diagnosis.py
index f5a49e7..f5fe61a 100644
--- a/grape/fault_diagnosis.py
+++ b/grape/fault_diagnosis.py
@@ -246,7 +246,7 @@ def optimizer(self, perturbed_nodes, initial_condition, params, weights,
 
         creator.create("FitnessMin", base.Fitness, weights=(-1.0,))
         creator.create("Individual", list, fitness=creator.FitnessMin)
-    
+
         toolbox = base.Toolbox()
         # Attribute generator
         toolbox.register("attribute_bool", random.choice, [True, False])
@@ -255,7 +255,7 @@ def optimizer(self, perturbed_nodes, initial_condition, params, weights,
             toolbox.attribute_bool, len(self.G.switches))
         toolbox.register("population", tools.initRepeat, list,
             toolbox.individual)
-    
+
         toolbox.register("evaluate", self.fitness_evaluation)
         toolbox.register("mate", tools.cxUniform, indpb=params['indpb'])
         toolbox.register("mutate", tools.mutFlipBit, indpb=params['indpb'])
@@ -302,14 +302,14 @@ def optimizer(self, perturbed_nodes, initial_condition, params, weights,
                     invalid_ind.append(child1)
                     del child2.fitness.values
                     invalid_ind.append(child2)
-    
+
             for ind in offspring:
                 if random.random() < params['tresh']:
                     mutant = toolbox.clone(ind)
                     toolbox.mutate(mutant)
                     del mutant.fitness.values
                     invalid_ind.append(mutant)
-    
+
             # Evaluate the individuals with an invalid fitness
             if (not parallel) or (len(invalid_ind) < mp.cpu_count()):
                 fitnesses = [toolbox.evaluate(ind, perturbed_nodes,
@@ -588,7 +588,7 @@ def apply_perturbation(self, perturbed_nodes, params, weights, parallel,
             w = np.asarray(list(weights.values()))
 
             if verbose:
-                with open('results_generations.dat', 'w') as f:
+                with open('results_generations.dat', 'w', encoding='utf8') as f:
                     for r in res:
                         f.write(f'{r[0]} {r[1]}')
                         fit = np.dot(w, np.asarray(r[1]))
@@ -605,7 +605,7 @@ def apply_perturbation(self, perturbed_nodes, params, weights, parallel,
         init_open_edges = {}
         for sw, closed in self.G.init_status.items():
             if not closed:
-                logging.debug(f'Opened switch {sw} in initial configuration')
+                logging.debug('Opened switch %s in initial configuration', sw)
                 init_open_edges[sw] = {}
                 for pred in list(self.G.predecessors(sw)):
                     # if final config is closed for this switch I memorize it
diff --git a/grape/general_graph.py b/grape/general_graph.py
index 88603d3..bb4b920 100644
--- a/grape/general_graph.py
+++ b/grape/general_graph.py
@@ -944,7 +944,7 @@ def shortest_path_list_kernel(self, nodes, shortest_path):
         :rtype: list
         """
 
-        tot_shortest_paths_list = list()
+        tot_shortest_paths_list = []
 
         for n in nodes:
             node_tot_shortest_paths = shortest_path[n]
@@ -1010,7 +1010,7 @@ def closeness_centrality_kernel(self, nodes, shortest_path_length,
         tot_shortest_paths_list, graph_size):
         """
 
-        Compute betweenness centrality, from shortest path list. 
+        Compute betweenness centrality, from shortest path list.
 
         :param list nodes: list of nodes for which to compute the
             efficiency between them and all the other nodes.
@@ -1496,5 +1496,5 @@ def print_graph(self, radius=None, initial_pos=None, fixed_nodes=None,
             plt.savefig(save_to_file, orientation='landscape', transparent=True)
         else:
             plt.show()
-        
+
         return pos
diff --git a/grape/meta.py b/grape/meta.py
index 3418a52..75c54db 100644
--- a/grape/meta.py
+++ b/grape/meta.py
@@ -1,3 +1,5 @@
+"""Package information"""
+
 def get_current_year():
     """ Return current year """
     from datetime import datetime
diff --git a/grape/parallel_general_graph.py b/grape/parallel_general_graph.py
index 774fc74..cf6cbf6 100644
--- a/grape/parallel_general_graph.py
+++ b/grape/parallel_general_graph.py
@@ -46,7 +46,7 @@ def measure_iteration(self, nodes, record, kernel, *measure_args):
         :param multiprocessing.managers.dict record:
             shared dictionary to be updated.
         :param callable kernel: kernel measure to be computed.
-        :param \*measure_args: arguments for kernel measures.
+        :param *measure_args: arguments for kernel measures.
            Have a look at specific kernel measures in GeneralGraph for
            the particular variables/types for each measure.
         """
@@ -64,7 +64,7 @@ def measure_processes(self, record, kernel, *measure_args):
         :param multiprocessing.managers.dict record:
             shared dictionary to be updated
         :param callable kernel: kernel measure to be computed
-        :param \*measure_args: arguments for kernel measures
+        :param *measure_args: arguments for kernel measures
            (have a look at specific kernel measures in GeneralGraph
            for the particular variables/types for each measure)
         """
@@ -329,7 +329,7 @@ def compute_local_efficiency(self):
 
         nodal_efficiency = self.nodal_efficiency
         local_efficiency = self.manager.dict()
-        self.measure_processes(local_efficiency, self.local_efficiency_kernel, 
+        self.measure_processes(local_efficiency, self.local_efficiency_kernel,
             nodal_efficiency)
         return local_efficiency
 
@@ -388,7 +388,7 @@ def compute_betweenness_centrality(self):
         betweenness_centrality = self.manager.dict()
         self.measure_processes(betweenness_centrality,
             self.betweenness_centrality_kernel, tot_shortest_paths_list)
-        
+
         return betweenness_centrality
 
     def compute_closeness_centrality(self):


Test patch:
diff --git a/tests/general_graph.py b/tests/general_graph.py
index e681d5f..db5b78b 100644
--- a/tests/general_graph.py
+++ b/tests/general_graph.py
@@ -3,5 +3,9 @@
 
 
 class TestGeneralGraph(TestCase):
+    """
+    Class TestGeneralGraph to check creating an instance of
+    GeneralGraph object
+    """
     def create_instance(self):
         GeneralGraph()