1. Gary Bernhardt
  2. pycomplexity

Commits

Gary Bernhardt  committed e838ebb

Added some manual tests

  • Participants
  • Parent commits 607d83f
  • Branches default

Comments (0)

Files changed (3)

File complexity.py

View file
                              score=complexity.score,
                              start_line=node.lineno,
                              end_line=self.highest_line_in_node(node)))
-        for stats_instance in complexity.stats.all():
+        for stats_instance in complexity.stats.ordered_by_line():
             stats_instance.name = '%s.%s' % (node.name, stats_instance.name)
             self.stats.add(stats_instance)
 
     def add(self, stats):
         self._stats.append(stats)
 
-    def all(self):
-        return self._stats[:]
+    def ordered_by_line(self):
+        return sorted(self._stats, key=lambda stats: stats.start_line)
 
     def named(self, name):
         return [s for s in self._stats if s.name == name][0]
     current_file = vim.eval('expand("%:p")')
     code = open(current_file).read()
     try:
-        stats = Complexity(code).stats
+        stats = Complexity(code).stats.ordered_by_line()
     except (IndentationError, SyntaxError):
         return
 

File tests/manual/test_functions.py

View file
+def one():
+    pass
+
+def two():
+    a if a else a
+
+def three():
+    a if a else a if a else a
+
+def four():
+    a if a else a if a else a if a else a
+
+def five():
+    a if a else a if a else a if a else a if a else a
+
+def six():
+    a if a else a if a else a if a else a if a else a if a else a
+
+def seven():
+    a if a else a if a else a if a else a if a else a if a else a if a else a
+
+def eight():
+    a if a else a if a else a if a else a if a else a if a else a if a else a if a else a
+
+def nine():
+    a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a
+
+def ten():
+    a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a
+
+def eleven():
+    a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a
+
+def twelve():
+    a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a
+
+def thirteen():
+    a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a
+
+def fourteen():
+    a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a
+
+def fifteen():
+    a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a
+

File tests/manual/test_high_complexity_module.py

View file
+a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a if a else a
+