import os
import unittest

from magpie import api
from magpie.config import HEP_TEST_PATH, MODEL_PATH


def train_model_if_necessary(model_path):
    """ If the model under a given path does not exist, create one. """
    if not os.path.exists(model_path):
        api.train(model_path=model_path)


class TestAPI(unittest.TestCase):
    """ Basic tests for making sure that the API works """
    def test_train(self):
        api.train()

    def test_test(self):
        train_model_if_necessary(MODEL_PATH)
        precision, recall, f1_score, accuracy = api.test()
        self.assertGreater(precision, 0)
        self.assertGreater(recall, 0)
        self.assertGreater(f1_score, 0)
        self.assertGreater(accuracy, 0)

    def test_extract(self):
        train_model_if_necessary(MODEL_PATH)
        candidates = api.extract(HEP_TEST_PATH + '/524510.txt')
        self.assertGreaterEqual(len(candidates), 0)

    def test_candidate_recall(self):
        recall = api.calculate_recall_for_kw_candidates()
        self.assertGreater(recall, 0)

@@ -289,18 +289,33 @@
 del_path
+, verbose=False
 )%0A
-
 %0A%0Aclass 
@@ -445,16 +445,29 @@
 i.train(
+verbose=False
 )%0A%0A    d
@@ -588,16 +588,29 @@
 pi.test(
+verbose=False
 )%0A      
@@ -898,16 +898,31 @@
 510.txt'
+, verbose=False
 )%0A      
@@ -997,32 +997,32 @@
 e_recall(self):%0A
-
         recall =
@@ -1061,16 +1061,29 @@
 didates(
+verbose=False
 )%0A      

add verbose=False