# Path: bertopic/_utils.py
# def check_documents_type(documents):
#     """ Check whether the input documents are indeed a list of strings """
#     if isinstance(documents, Iterable) and not isinstance(documents, str):
#         if not any([isinstance(doc, str) for doc in documents]):
#             raise TypeError("Make sure that the iterable only contains strings.")
# 
#     else:
#         raise TypeError("Make sure that the documents variable is an iterable containing strings only.")
# 
# def check_embeddings_shape(embeddings, docs):
#     """ Check if the embeddings have the correct shape """
#     if embeddings is not None:
#         if not any([isinstance(embeddings, np.ndarray), isinstance(embeddings, csr_matrix)]):
#             raise ValueError("Make sure to input embeddings as a numpy array or scipy.sparse.csr.csr_matrix. ")
#         else:
#             if embeddings.shape[0] != len(docs):
#                 raise ValueError("Make sure that the embeddings are a numpy array with shape: "
#                                  "(len(docs), vector_dim) where vector_dim is the dimensionality "
#                                  "of the vector embeddings. ")
# 
# class MyLogger:
#     def __init__(self, level):
#         self.logger = logging.getLogger('BERTopic')
#         self.set_level(level)
#         self._add_handler()
#         self.logger.propagate = False
# 
#     def info(self, message):
#         self.logger.info("{}".format(message))
# 
#     def set_level(self, level):
#         levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
#         if level in levels:
#             self.logger.setLevel(level)
# 
#     def _add_handler(self):
#         sh = logging.StreamHandler()
#         sh.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(message)s'))
#         self.logger.addHandler(sh)
# 
#         # Remove duplicate handlers
#         if len(self.logger.handlers) > 1:
#             self.logger.handlers = [self.logger.handlers[0]]


import pytest
import logging
import numpy as np
from bertopic._utils import check_documents_type, check_embeddings_shape, MyLogger
"""
Unit tests for utility functions
"""



def test_logger():
    """ Test whether the logger could correctly be instantiated """
    logger = MyLogger("DEBUG")
    assert isinstance(logger.logger, logging.Logger)
    assert logger.logger.level == 10


# Path: bertopic/_utils.py
# def check_documents_type(documents):
#     """ Check whether the input documents are indeed a list of strings """
#     if isinstance(documents, Iterable) and not isinstance(documents, str):
#         if not any([isinstance(doc, str) for doc in documents]):
#             raise TypeError("Make sure that the iterable only contains strings.")
# 
#     else:
#         raise TypeError("Make sure that the documents variable is an iterable containing strings only.")
# 
# def check_embeddings_shape(embeddings, docs):
#     """ Check if the embeddings have the correct shape """
#     if embeddings is not None:
#         if not any([isinstance(embeddings, np.ndarray), isinstance(embeddings, csr_matrix)]):
#             raise ValueError("Make sure to input embeddings as a numpy array or scipy.sparse.csr.csr_matrix. ")
#         else:
#             if embeddings.shape[0] != len(docs):
#                 raise ValueError("Make sure that the embeddings are a numpy array with shape: "
#                                  "(len(docs), vector_dim) where vector_dim is the dimensionality "
#                                  "of the vector embeddings. ")
# 
# class MyLogger:
#     def __init__(self, level):
#         self.logger = logging.getLogger('BERTopic')
#         self.set_level(level)
#         self._add_handler()
#         self.logger.propagate = False
# 
#     def info(self, message):
#         self.logger.info("{}".format(message))
# 
#     def set_level(self, level):
#         levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
#         if level in levels:
#             self.logger.setLevel(level)
# 
#     def _add_handler(self):
#         sh = logging.StreamHandler()
#         sh.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(message)s'))
#         self.logger.addHandler(sh)
# 
#         # Remove duplicate handlers
#         if len(self.logger.handlers) > 1:
#             self.logger.handlers = [self.logger.handlers[0]]


# Path: tests/test_utils.py
import pytest
import logging
import numpy as np
from bertopic._utils import check_documents_type, check_embeddings_shape, MyLogger

"""
Unit tests for utility functions
"""



def test_logger():
    """ Test whether the logger could correctly be instantiated """
    logger = MyLogger("DEBUG")
    assert isinstance(logger.logger, logging.Logger)
    assert logger.logger.level == 10


    logger = MyLogger("WARNING")