# Path: string_utils/generation.py
# def random_string(size: int) -> str:
#     """
#     Returns a string of the specified size containing random characters (uppercase/lowercase ascii letters and digits).
# 
#     *Example:*
# 
#     >>> random_string(9) # possible output: "cx3QQbzYg"
# 
#     :param size: Desired string size
#     :type size: int
#     :return: Random string
#     """
#     if not isinstance(size, int) or size < 1:
#         raise ValueError('size must be >= 1')
# 
#     chars = string.ascii_letters + string.digits
#     buffer = [random.choice(chars) for _ in range(size)]
#     out = ''.join(buffer)
# 
#     return out


from unittest import TestCase
from string_utils.generation import random_string



class RandomStringTestCase(TestCase):
    def test_throws_error_if_size_is_null(self):
        with self.assertRaises(ValueError) as raised:
            # noinspection PyTypeChecker
            random_string(None)

        self.assertEqual(str(raised.exception), 'size must be >= 1')

    def test_throws_error_if_size_is_less_than_1(self):
        msg = 'size must be >= 1'

        with self.assertRaises(ValueError) as raised:
            random_string(-12)

        self.assertEqual(str(raised.exception), msg)

        with self.assertRaises(ValueError) as raised:

# Path: string_utils/generation.py
# def random_string(size: int) -> str:
#     """
#     Returns a string of the specified size containing random characters (uppercase/lowercase ascii letters and digits).
# 
#     *Example:*
# 
#     >>> random_string(9) # possible output: "cx3QQbzYg"
# 
#     :param size: Desired string size
#     :type size: int
#     :return: Random string
#     """
#     if not isinstance(size, int) or size < 1:
#         raise ValueError('size must be >= 1')
# 
#     chars = string.ascii_letters + string.digits
#     buffer = [random.choice(chars) for _ in range(size)]
#     out = ''.join(buffer)
# 
#     return out


# Path: tests/test_random_string.py
from unittest import TestCase
from string_utils.generation import random_string




class RandomStringTestCase(TestCase):
    def test_throws_error_if_size_is_null(self):
        with self.assertRaises(ValueError) as raised:
            # noinspection PyTypeChecker
            random_string(None)

        self.assertEqual(str(raised.exception), 'size must be >= 1')

    def test_throws_error_if_size_is_less_than_1(self):
        msg = 'size must be >= 1'

        with self.assertRaises(ValueError) as raised:
            random_string(-12)

        self.assertEqual(str(raised.exception), msg)

        with self.assertRaises(ValueError) as raised:

            random_string(0)