Faker.py 954 B

12345678910111213141516171819202122232425262728
  1. import logging
  2. from faker import Faker as FakerBase
  3. from random import randint
  4. logger = logging.getLogger("pyC")
  5. class Faker:
  6. def __init__(self, locale="en-US"):
  7. self.faker = FakerBase()
  8. # Start with a random number
  9. self.faker.seed_instance(randint(10,1000))
  10. def fakerProxy(self, fakerMethod="email", **kwargs):
  11. """
  12. Dynamically call Faker's method and return the value back to the caller
  13. :param fakerMethod: Default "email"
  14. :param kwargs: Any arguments needed to execute a specific functionality
  15. :return: the value, that was delivered by Faker.
  16. """
  17. lValue = None
  18. try:
  19. lCallFakerMethod = getattr(self.faker, fakerMethod)
  20. lValue = lCallFakerMethod(**kwargs)
  21. except Exception as e:
  22. logging.error(f"Error during Faker-Call. Method was: {fakerMethod}, kwargs were: {kwargs}, Exception: {e}")
  23. return lValue