Пример #1
0
class FileMetrics:
    def __init__(self):
        self.nodes = []
        self.lineCounter = LineCounter()
        self.__fileLineCountCache = None

    def addNode(self, node):
        self.nodes.append(node)

    def compiledLines(self):
        return sum(node.totalLines() for node in self.nodes)

    def file(self):
        return self.nodes[0].file()

    def name(self):
        return self.nodes[0].name()

    def fileLines(self):
        if len(self.nodes) != 0:
            if self.__fileLineCountCache is None:
                self.__fileLineCountCache = self.lineCounter.countLines(
                    self.nodes[0].file())
            return self.__fileLineCountCache
        else:
            return 0

    def includedFrom(self):
        return len([node for node in self.nodes if node.parent() is not None])
Пример #2
0
class FileMetrics:
  def __init__(self):
    self.nodes = []
    self.lineCounter = LineCounter()
    self.__fileLineCountCache = None

  def addNode(self, node):
    self.nodes.append(node)

  def compiledLines(self):
    return sum(node.totalLines() for node in self.nodes)

  def file(self):
    return self.nodes[0].file()

  def name(self):
    return self.nodes[0].name()

  def fileLines(self):
    if len(self.nodes) != 0:
      if self.__fileLineCountCache is None:
        self.__fileLineCountCache = self.lineCounter.countLines(self.nodes[0].file())
      return self.__fileLineCountCache
    else:
      return 0

  def includedFrom(self):
    return len([node for node in self.nodes if node.parent() is not None])
Пример #3
0
class TestLineCounter(MockTestCase):
  def setUp(self):
    self.counter = LineCounter()
    self.file = self.mock()
    self.counter.fileOpener = self.mock()
    self.counter.fileOpener.expects(once()).open(eq("test.h")).will(return_value(self.file))

  def loadLines(self, lines):
    self.file.expects(once()).xreadlines().will(return_value(lines))

  def testCountEmptyFile(self):
    self.loadLines([])
    self.assertEqual(self.counter.countLines("test.h"), 0)

  def testOneLine(self):
    self.loadLines(["a line"])
    self.assertEqual(self.counter.countLines("test.h"), 1)

  def testTwoLines(self):
    self.loadLines(["a line", "another"])
    self.assertEqual(self.counter.countLines("test.h"), 2)
Пример #4
0
class TestLineCounter(MockTestCase):
    def setUp(self):
        self.counter = LineCounter()
        self.file = self.mock()
        self.counter.fileOpener = self.mock()
        self.counter.fileOpener.expects(once()).open(eq("test.h")).will(
            return_value(self.file))

    def loadLines(self, lines):
        self.file.expects(once()).xreadlines().will(return_value(lines))

    def testCountEmptyFile(self):
        self.loadLines([])
        self.assertEqual(self.counter.countLines("test.h"), 0)

    def testOneLine(self):
        self.loadLines(["a line"])
        self.assertEqual(self.counter.countLines("test.h"), 1)

    def testTwoLines(self):
        self.loadLines(["a line", "another"])
        self.assertEqual(self.counter.countLines("test.h"), 2)