Пример #1
0
    def testInputLabelListProperlyInitialized(self):
        settings = {}
        settings["apiKey"] = "xxx"
        settings["algoSingle"] = "userName/algoName"
        settings["inputLabelList"] = "an input"

        with pytest.raises(AlgoBenchError):
            b = Benchmark(settings)

        settings["inputLabelList"] = ["an input", "another input"]

        with pytest.raises(AlgoBenchError):
            b2 = Benchmark(settings)

        settings["inputLabelList"] = [{
            "data": "an input",
            "label": "true"
        }, {
            "data": "another input",
            "label": "false"
        }]

        b3 = Benchmark(settings)

        assert "inputLabelList" in b3.settings
        assert "inputList" not in b3.settings
        assert "inputSingle" not in b3.settings
Пример #2
0
    def testCalcBasics(self):
        settings = {}
        settings["apiKey"] = "xxx"
        settings["algoSingle"] = "userName/algoName"
        settings["inputSingle"] = "an input"

        b = Benchmark(settings)

        b.results = [{"result": 5, "label": 5}, {"result": 7, "label": 7},\
                     {"result": 5, "label": 5}, {"result": 1, "label": 7},\
                     {"result": 3, "label": 5}, {"result": 7, "label": 7},\
                     {"result": 5, "label": 5}, {"result": 4, "label": 7},\
                     {"result": 4, "label": 5}, {"result": 7, "label": 7}]

        def mapFunc(res):
            return res

        b.calcStats(mapFunc)

        assert b.stats["FN"]["labels"][5] == 2
        assert b.stats["FN"]["labels"][7] == 2
        assert b.stats["FP"]["labels"][5] == 0
        assert b.stats["FP"]["labels"][7] == 0
        assert b.stats["TN"]["labels"][5] == 5
        assert b.stats["TN"]["labels"][7] == 5
        assert b.stats["TP"]["labels"][5] == 3
        assert b.stats["TP"]["labels"][7] == 3
Пример #3
0
    def testHasLabels(self):
        settings = {}
        settings["apiKey"] = "xxx"
        settings["algoSingle"] = "userName/algoName"
        settings["inputSingle"] = "an input"

        b = Benchmark(settings)

        b.results = [{"result": 5, "label": 5}, {"result": 7, "label": 7}]

        assert b._Benchmark__hasLabels() == True
Пример #4
0
    def testInputListProperlyInitialized(self):
        settings = {}
        settings["apiKey"] = "xxx"
        settings["algoSingle"] = "userName/algoName"
        settings["inputList"] = "an input"
        with pytest.raises(AlgoBenchError):
            b = Benchmark(settings)

        settings["inputList"] = ["an input", "another input"]

        b2 = Benchmark(settings)

        assert "inputLabelList" in b2.settings
        assert "inputList" not in b2.settings
Пример #5
0
    def testCalcAverage(self):
        settings = {}
        settings["apiKey"] = "xxx"
        settings["inputSingle"] = "an input"
        settings["algoSingle"] = "userName/algoName"
        b = Benchmark(settings)

        b.results = [{"response":{"metadata":{"duration":0.24214214}}, "algo":"userName/algoName"},\
                     {"response":{"metadata":{"duration":0.43523423}}, "algo":"userName/algoName"},\
                     {"response":{"metadata":{"duration":0.12435256}}, "algo":"userName/algoName"},\
                     {"response":{"metadata":{"duration":0.35314251}}, "algo":"userName/algoName"},\
                     {"response":{"metadata":{"duration":0.12451533}}, "algo":"userName/algoName"}]
        b._Benchmark__calcAverage()

        assert b.average["userName/algoName"] == 0.255877354
Пример #6
0
    def testAlgoListProperlyInitialized(self):
        settings = {}
        settings["apiKey"] = "xxx"
        settings["algoList"] = "userName/algoName"
        settings["inputSingle"] = "an input"

        with pytest.raises(AlgoBenchError):
            b = Benchmark(settings)

        settings["algoList"] = [
            "userName/algoName/ver1", "userName/algoName/ver2"
        ]

        b2 = Benchmark(settings)

        assert "algoList" in b2.settings
Пример #7
0
    def testInputSingleProperlyInitialized(self):
        settings = {}
        settings["apiKey"] = "xxx"
        settings["algoSingle"] = "userName/algoName"
        settings["inputSingle"] = "an input"
        b = Benchmark(settings)

        assert "inputLabelList" in b.settings
        assert "inputSingle" not in b.settings
Пример #8
0
    def testNoMaxNumConnections(self):
        settings = {}
        settings["apiKey"] = "xxx"
        settings["inputSingle"] = "an input"
        settings["algoSingle"] = "userName/algoName"
        settings["numBenchRuns"] = 5
        b = Benchmark(settings)

        assert b.settings["maxNumConnections"] == 10
Пример #9
0
    def testCalcFScore(self):
        settings = {}
        settings["apiKey"] = "xxx"
        settings["algoSingle"] = "userName/algoName"
        settings["inputSingle"] = "an input"

        b = Benchmark(settings)

        b.results = [{"result": 5, "label": 5}, {"result": 7, "label": 7},\
                     {"result": 5, "label": 5}, {"result": 1, "label": 7},\
                     {"result": 3, "label": 5}, {"result": 7, "label": 7},\
                     {"result": 5, "label": 5}, {"result": 4, "label": 7},\
                     {"result": 4, "label": 5}, {"result": 7, "label": 7}]

        def mapFunc(res):
            return res

        b.calcStats(mapFunc)

        assert b.stats['fScore']['labels'][5] == 0.7499999999999999
        assert b.stats['fScore']['labels'][7] == 0.7499999999999999
Пример #10
0
 def testSettingsIsNotDict(self):
     settings = "not dict"
     with pytest.raises(AlgoBenchError):
         b = Benchmark(settings)
Пример #11
0
 def testNoAlgo(self):
     settings = {}
     settings["apiKey"] = "xxx"
     settings["inputSingle"] = "an input"
     with pytest.raises(AlgoBenchError):
         b = Benchmark(settings)
Пример #12
0
 def testNoInput(self):
     settings = {}
     settings["apiKey"] = "xxx"
     settings["algoSingle"] = "userName/algoName"
     with pytest.raises(AlgoBenchError):
         b = Benchmark(settings)
Пример #13
0
 def testNoAPIKey(self):
     settings = {}
     settings["inputSingle"] = "an input"
     settings["algoSingle"] = "userName/algoName"
     with pytest.raises(AlgoBenchError):
         b = Benchmark(settings)