Example #1
0
    def testMultipleUses(self):
        with processed_builds.ProcessedBuildsStorage(self.testfile) as ps:
            ps.AddProcessedBuild('branch', 'target', 1)
            ps.AddProcessedBuild('branch', 'target', 2)

        self.assertFileContents(self.testfile,
                                '{"branch": {"target": [1, 2]}}')

        with processed_builds.ProcessedBuildsStorage(self.testfile) as ps:
            # Try adding twice, should only happen once.
            ps.AddProcessedBuild('branch', 'target', 3)
            ps.AddProcessedBuild('branch', 'target', 3)

        self.assertFileContents(self.testfile,
                                '{"branch": {"target": [1, 2, 3]}}')

        with processed_builds.ProcessedBuildsStorage(self.testfile) as ps:
            ps.PurgeOldBuilds('branch', 'target', [2, 3])
            ps.AddProcessedBuild('branch', 'target', 4)

        self.assertFileContents(self.testfile,
                                '{"branch": {"target": [2, 3, 4]}}')

        with processed_builds.ProcessedBuildsStorage(self.testfile) as ps:
            self.assertEqual(ps.GetProcessedBuilds('branch', 'target'),
                             [2, 3, 4])
Example #2
0
    def testAddMultipleBranchTargets(self):
        with processed_builds.ProcessedBuildsStorage(self.testfile) as ps:
            ps.AddProcessedBuild('branch1', 'target', 1)
            ps.AddProcessedBuild('branch2', 'target', 1)
            ps.AddProcessedBuild('branch2', 'target', 2)
            ps.AddProcessedBuild('branch2', 'target2', 3)

            self.assertEqual(ps.GetProcessedBuilds('branch2', 'target'),
                             [1, 2])

        self.assertFileContents(
            self.testfile, '{"branch1": {"target": [1]},'
            ' "branch2": {"target": [1, 2], "target2": [3]}}')
  def testAddEmpty(self):
    with processed_builds.ProcessedBuildsStorage(self.testfile) as ps:
      ps.AddProcessedBuild('branch', 'target', 1)

    self.assertFileContents(self.testfile, '{"branch": {"target": [1]}}')
  def testPurgeEmpty(self):
    with processed_builds.ProcessedBuildsStorage(self.testfile) as ps:
      ps.PurgeOldBuilds('branch', 'target', [1, 2, 3])

    self.assertFileContents(self.testfile, '{"branch": {"target": []}}')
  def testFetchEmpty(self):
    with processed_builds.ProcessedBuildsStorage(self.testfile) as ps:
      self.assertEqual(ps.GetProcessedBuilds('branch', 'target'), [])

    self.assertFileContents(self.testfile, '{"branch": {"target": []}}')
  def testStartStop(self):
    with processed_builds.ProcessedBuildsStorage(self.testfile):
      pass

    self.assertFileContents(self.testfile, '{}')