コード例 #1
0
ファイル: recording_pdu.py プロジェクト: dbanerj/AmI-Platform
 def test_closes_not_active(self, close_mock, open_mock, put_mock):
     Experiment(name = 'e1', 
                file = 'file1.txt', 
                since = datetime.now(), 
                filters = {'type': '1'}).save()
                
     e2 = Experiment(name = 'e2', 
                     file = 'file2.txt', 
                     since = datetime.now(), 
                     filters = {'type': '2'}).save()
     
     RecordingPDU.FILES_PURGE_THRESHOLD = 0.1
     pdu = RecordingPDU()
     pdu.process_message({'type': '3', 'id': '0'})
     pdu.process_message({'type': '1', 'id': '1'})
     pdu.process_message({'type': '2', 'id': '2'})
     
     e2.active = False
     e2.save()
     time.sleep(0.3)
     
     pdu.process_message({'type': '1', 'id': '3'})
     pdu.process_message({'type': '2', 'id': '4'})
     pdu.process_message({'type': '3', 'id': '5'})
             
     eq_(3, put_mock.call_count, "2 put expected!")
     put_mock.assert_any_call(Matcher("file1.txt", lambda o: o.fname), 
                              Matcher('1', lambda o: o['type']))
     put_mock.assert_any_call(Matcher("file2.txt", lambda o: o.fname), 
                              Matcher('2', lambda o: o['type']))
     
     eq_(1, close_mock.call_count, "1 close expected!")
     close_mock.assert_called_once_with(Matcher("file2.txt", lambda o: o.fname))
コード例 #2
0
ファイル: recording_pdu.py プロジェクト: dbanerj/AmI-Platform
 def test_no_active(self, close_mock, open_mock, put_mock):
     e = Experiment(name = 'e1', file = 'file2.txt', since = datetime.now())
     e.active = False        
     e.save()
     pdu = RecordingPDU()
     pdu.process_message({'id': 1})
     pdu.process_message({'id': 1})
     
     eq_(0, close_mock.call_count, "no calls expected!")
     eq_(0, open_mock.call_count, "no calls expected!")
     eq_(0, put_mock.call_count, "no calls expected!")
コード例 #3
0
ファイル: experiment.py プロジェクト: aismail/AmI-Platform
    def test_get_active_experiments_returns_active_experiment(self):
        """ Test that get_active_experiments works correctly indeed. """
        e = Experiment(name = "e1", file = 'file2.txt', since = datetime.now())
        e.save()

        active = Experiment.get_active_experiments()
        eq_(active.count(), 1, "There should be exactly one active experiment")

        e.active = False
        e.save()
        active = Experiment.get_active_experiments()
        eq_(active.count(), 0, "There should be no active experiments")
コード例 #4
0
ファイル: experiment.py プロジェクト: aismail/AmI-Platform
                       file=args.file,
                       since=datetime.now(),
                       active=True)
        e.save()
    except MultipleObjectsReturned:
        logger.error("There is more than one experiment with name %s! "
                     "Database is corrupted." % args.name)

elif args.operation == 'stop':
    try:
        connect('experiments', host=settings.MONGO_SERVER)
        e = Experiment.objects.get(name=args.name)
        if not e.active:
            logger.error("The experiment %s is not active!" % args.name)
        else:
            e.active = False
            e.save()
    except DoesNotExist:
        logger.error("There is no experiment with name %s!" % args.name)

elif args.operation == 'delete':
    try:
        connect('experiments', host=settings.MONGO_SERVER)
        e = Experiment.objects.get(name=args.name)
        e.delete(safe=True)
    except DoesNotExist:
        logger.error("There is no experiment with name %s!" % args.name)

elif args.operation == 'play':
    try:
        connect('experiments', host=settings.MONGO_SERVER)