예제 #1
0
    def testLogExceptionsWithSystemExitExceptionAndDefaultLogger(self):
        loggerMock = Mock(spec_set=decorators.logging.getLogger())
        with patch.object(decorators.logging,
                          "getLogger",
                          autospec=True,
                          return_value=loggerMock):

            # SystemExit is based on BaseException, so we want to make sure that
            # those are handled properly, too
            inputArgs = (1, 2, 3)
            inputKwargs = dict(a="A", b="B", c="C")

            @decorators.logExceptions()
            def doSomething(*args, **kwargs):
                self.assertEqual(args, inputArgs)
                self.assertEqual(kwargs, inputKwargs)

                raise SystemExit()

            with self.assertRaises(SystemExit):
                doSomething(*inputArgs, **inputKwargs)

            self.assertEqual(loggerMock.exception.call_count, 1)
            self.assertIn("Unhandled exception %r from %r. Caller stack:\n%s",
                          loggerMock.exception.call_args[0][0])


if __name__ == '__main__':
    unittest.main()
    }

    state.__setstate__(record)

    self.assertEqual(state.ROWID, record['ROWID'])
    self.assertEqual(state.anomalyScore, record['anomalyScore'])
    self.assertEqual(state.anomalyVector, record['anomalyVector'])
    self.assertEqual(state.anomalyLabel, record['anomalyLabel'])
    self.assertEqual(state.setByUser, record['setByUser'])




  def mockRemoveIds(self, ids):
    self.helper.clamodel._getAnomalyClassifier().getSelf()._knn._numPatterns -= len(ids)
    for idx in ids:
      if idx in self.helper.clamodel._getAnomalyClassifier().getSelf().getParameter('categoryRecencyList'):
        self.helper.clamodel._getAnomalyClassifier().getSelf().getParameter('categoryRecencyList').remove(idx)




if __name__ == '__main__':
  parser = TestOptionParser()
  options, args = parser.parse_args()

  # Form the command line for the unit test framework
  args = [sys.argv[0]] + args
  unittest.main(argv=args)

예제 #3
0
  @unittest.skip("Currently Fails: NUP-1864")
  def test_TemporalAnomaly(self):
    """ Test that we get the same predictions out of a model that was
    saved and reloaded from a checkpoint as we do from one that runs
    continuously.
    """

    self._testSamePredictions(experiment="temporal_anomaly", predSteps=1,
      checkpointAt=250,
      predictionsFilename='DefaultTask.TemporalAnomaly.predictionLog.csv',
      additionalFields=['anomalyScore'])


  @unittest.skip("We aren't currently supporting serialization backward "
                 "compatibility")
  def test_BackwardsCompatibility(self):
    """ Test that we can load in a checkpoint saved by an earlier version of
    the OPF.
    """

    self._testBackwardsCompatibility(
          os.path.join('backwards_compatibility', 'a'),
          'savedmodels_2012-10-05')



if __name__ == "__main__":
  initLogging(verbose=True)

  unittest.main()
            "anomalyVector": "Vector",
            "anomalyLabel": "Label",
            "setByUser": False
        }

        state.__setstate__(record)

        self.assertEqual(state.ROWID, record['ROWID'])
        self.assertEqual(state.anomalyScore, record['anomalyScore'])
        self.assertEqual(state.anomalyVector, record['anomalyVector'])
        self.assertEqual(state.anomalyLabel, record['anomalyLabel'])
        self.assertEqual(state.setByUser, record['setByUser'])

    def mockRemoveIds(self, ids):
        self.helper.htm_prediction_model._getAnomalyClassifier().getSelf(
        )._knn._numPatterns -= len(ids)
        for idx in ids:
            if idx in self.helper.htm_prediction_model._getAnomalyClassifier(
            ).getSelf().getParameter('categoryRecencyList'):
                self.helper.htm_prediction_model._getAnomalyClassifier(
                ).getSelf().getParameter('categoryRecencyList').remove(idx)


if __name__ == '__main__':
    parser = TestOptionParser()
    options, args = parser.parse_args()

    # Form the command line for the unit test framework
    args = [sys.argv[0]] + args
    unittest.main(argv=args)