def testGetExpiredHistograms(self):
        histograms = {
            "FirstHistogram": {
                "expiry_date": "2000/10/01"
            },
            "SecondHistogram": {
                "expiry_date": "2002/10/01"
            },
            "ThirdHistogram": {
                "expiry_date": "2001/10/01"
            },
            "FourthHistogram": {},
            "FifthHistogram": {
                "obsolete": "Has expired.",
                "expiry_date": "2000/10/01"
            }
        }

        base_date = datetime.date(2001, 10, 1)

        expired_histograms_names = (
            generate_expired_histograms_array._GetExpiredHistograms(
                histograms, base_date))

        self.assertEqual(expired_histograms_names, ["FirstHistogram"])
  def testBadExpiryDate(self):
    histograms = {
        "FirstHistogram": {
            "expires_after": "2000-10-01"
        },
        "SecondHistogram": {
            "expires_after": "2000/10/01"
        }
    }
    base_date = datetime.date(2000, 10, 1)
    current_milestone = 60

    with self.assertRaises(generate_expired_histograms_array.Error) as error:
      generate_expired_histograms_array._GetExpiredHistograms(
          histograms, base_date, current_milestone)

    self.assertEqual(
        generate_expired_histograms_array._DATE_FORMAT_ERROR.format(
            date="2000/10/01", name="SecondHistogram"), str(error.exception))
    def testBadExpiryDate(self):
        histograms = {
            "FirstHistogram": {
                "expiry_date": "2000/10/01"
            },
            "SecondHistogram": {
                "expiry_date": "2000-10-01"
            },
        }
        base_date = datetime.date(2000, 10, 01)

        with self.assertRaises(
                generate_expired_histograms_array.Error) as error:
            generate_expired_histograms_array._GetExpiredHistograms(
                histograms, base_date)

        self.assertEqual(
            "Unable to parse expiry date 2000-10-01 in histogram SecondHistogram.",
            str(error.exception))
  def testGetExpiredHistograms(self):
    histograms = {
        "FirstHistogram": {
            "expires_after": "2000-10-01"
        },
        "SecondHistogram": {
            "expires_after": "2002-10-01"
        },
        "ThirdHistogram": {
            "expires_after": "2001-10-01"
        },
        "FourthHistogram": {},
        "FifthHistogram": {
            "obsolete": "Has expired.",
            "expires_after": "2000-10-01"
        },
        "SixthHistogram": {
            "expires_after": "M22"
        },
        "SeventhHistogram": {
            "expires_after": "M60"
        },
        "EigthHistogram": {
            "expires_after": "M65"
        },
    }

    base_date = datetime.date(2001, 10, 1)
    current_milestone = 60

    expired_histograms_names = (
        generate_expired_histograms_array._GetExpiredHistograms(
            histograms, base_date, current_milestone))

    self.assertEqual(2, len(expired_histograms_names))
    self.assertIn("FirstHistogram", expired_histograms_names)
    self.assertIn("SixthHistogram", expired_histograms_names)