# Path: zdict/dictionaries/urban.py
# class UrbanDict(DictBase):
# 
#     HOMEPAGE_URL = "https://www.urbandictionary.com/"
#     API = 'http://api.urbandictionary.com/v0/define?term={word}'
# 
#     @property
#     def provider(self):
#         return 'urban'
# 
#     @property
#     def title(self):
#         return 'Urban Dictionary'
# 
#     def _get_url(self, word) -> str:
#         return self.API.format(word=word)
# 
#     def show(self, record: Record):
#         content = json.loads(record.content)
# 
#         data = content['list'][0]
# 
#         # print word
#         self.color.print(data.get('word', ''), 'yellow')
# 
#         for line in data.get('definition', '').splitlines():
#             self.color.print(line, 'org', indent=2)
# 
#         for example in data.get('example', '').split('\n'):
#             self.color.print(
#                 example,
#                 'indigo',
#                 indent=2,
#             )
# 
#         print()
# 
#     def query(self, word: str):
#         content_str = self._get_raw(word)
#         content_dict = json.loads(content_str)
# 
#         if content_dict['list'] == []:
#             raise NotFoundError(word)
# 
#         record = Record(
#             word=word,
#             content=content_str,
#             source=self.provider,
#         )
# 
#         return record
# 
# Path: zdict/exceptions.py
# class NotFoundError(Exception):
#     def __init__(self, word):
#         self.word = word
# 
#     def __str__(self):
#         return '"{}" not found!'.format(self.word)
# 
# Path: zdict/zdict.py
# def get_args():
#     # parse args
#     parser = ArgumentParser(prog='zdict')
# 
#     parser.add_argument(
#         'words',
#         metavar='word',
#         type=str,
#         nargs='*',
#         help='Words for searching its translation'
#     )
# 
#     parser.add_argument(
#         "-v", "--version",
#         action="version",
#         version='%(prog)s-' + constants.VERSION
#     )
# 
#     parser.add_argument(
#         "-d", "--disable-db-cache",
#         default=False,
#         action="store_true",
#         help="Temporarily not using the result from db cache.\
#               (still save the result into db)"
#     )
# 
#     parser.add_argument(
#         "-t", "--query-timeout",
#         type=float,
#         default=5.0,
#         action="store",
#         help="Set timeout for every query. default is 5 seconds."
#     )
# 
#     def positive_int_only(value):
#         ivalue = int(value)
#         if ivalue <= 0:
#             raise ArgumentTypeError(
#                 "%s is an invalid positive int value" % value
#             )
#         return ivalue
# 
#     parser.add_argument(
#         "-j", "--jobs",
#         type=positive_int_only,
#         nargs="?",
#         default=0,     # 0: not using, None: auto, N (1, 2, ...): N jobs
#         action="store",
#         help="""
#             Allow N jobs at once.
#             Do not pass any argument to use the number of CPUs in the system.
#         """
#     )
# 
#     parser.add_argument(
#         "-sp", "--show-provider",
#         default=False,
#         action="store_true",
#         help="Show the dictionary provider of the queried word"
#     )
# 
#     parser.add_argument(
#         "-su", "--show-url",
#         default=False,
#         action="store_true",
#         help="Show the url of the queried word"
#     )
# 
#     available_dictionaries = list(dictionary_map.keys())
#     available_dictionaries.append('all')
#     parser.add_argument(
#         "-dt", "--dict",
#         default="yahoo",
#         action="store",
#         choices=available_dictionaries,
#         metavar=','.join(available_dictionaries),
#         help="""
#             Must be seperated by comma and no spaces after each comma.
#             Choose the dictionary you want. (default: yahoo)
#             Use 'all' for qureying all dictionaries.
#             If 'all' or more than 1 dictionaries been chosen,
#             --show-provider will be set to True in order to
#             provide more understandable output.
#         """
#     )
# 
#     parser.add_argument(
#         "-ld", "--list-dicts",
#         default=False,
#         action="store_true",
#         help="Show currently supported dictionaries."
#     )
# 
#     parser.add_argument(
#         "-V", "--verbose",
#         default=False,
#         action="store_true",
#         help="Show more information for the queried word.\
#         (If the chosen dictionary have implemented verbose related functions)"
#     )
# 
#     parser.add_argument(
#         "-c", "--force-color",
#         default=False,
#         action="store_true",
#         help="Force color printing (zdict automatically disable color printing \
#         when output is not a tty, use this option to force color printing)"
#     )
# 
#     parser.add_argument(
#         '--dump', dest='pattern',
#         nargs='?',
#         default=None, const=r'^.*$',
#         help='Dump the querying history, can be filtered with regex'
#     )
# 
#     parser.add_argument(
#         "-D", "--debug",
#         default=False,
#         action="store_true",
#         help="Print raw html prettified by BeautifulSoup for debugging."
#     )
# 
#     return parser.parse_args()


from pytest import raises
from unittest.mock import patch
from zdict.dictionaries.urban import UrbanDict
from zdict.exceptions import NotFoundError
from zdict.zdict import get_args



class TestUrbanDict:
    @classmethod
    def setup_class(cls):
        cls.dict = UrbanDict(get_args())
        cls.not_found_word = 'some_not_existing_word'
        cls.word = 'urban'
        cls.record = cls.dict.query(cls.word)

    @classmethod
    def teardown_class(cls):
        del cls.dict
        del cls.not_found_word
        del cls.word
        del cls.record

    def test_provider(self):
        assert self.dict.provider == 'urban'

    def test__get_url(self):

# Path: zdict/dictionaries/urban.py
# class UrbanDict(DictBase):
# 
#     HOMEPAGE_URL = "https://www.urbandictionary.com/"
#     API = 'http://api.urbandictionary.com/v0/define?term={word}'
# 
#     @property
#     def provider(self):
#         return 'urban'
# 
#     @property
#     def title(self):
#         return 'Urban Dictionary'
# 
#     def _get_url(self, word) -> str:
#         return self.API.format(word=word)
# 
#     def show(self, record: Record):
#         content = json.loads(record.content)
# 
#         data = content['list'][0]
# 
#         # print word
#         self.color.print(data.get('word', ''), 'yellow')
# 
#         for line in data.get('definition', '').splitlines():
#             self.color.print(line, 'org', indent=2)
# 
#         for example in data.get('example', '').split('\n'):
#             self.color.print(
#                 example,
#                 'indigo',
#                 indent=2,
#             )
# 
#         print()
# 
#     def query(self, word: str):
#         content_str = self._get_raw(word)
#         content_dict = json.loads(content_str)
# 
#         if content_dict['list'] == []:
#             raise NotFoundError(word)
# 
#         record = Record(
#             word=word,
#             content=content_str,
#             source=self.provider,
#         )
# 
#         return record
# 
# Path: zdict/exceptions.py
# class NotFoundError(Exception):
#     def __init__(self, word):
#         self.word = word
# 
#     def __str__(self):
#         return '"{}" not found!'.format(self.word)
# 
# Path: zdict/zdict.py
# def get_args():
#     # parse args
#     parser = ArgumentParser(prog='zdict')
# 
#     parser.add_argument(
#         'words',
#         metavar='word',
#         type=str,
#         nargs='*',
#         help='Words for searching its translation'
#     )
# 
#     parser.add_argument(
#         "-v", "--version",
#         action="version",
#         version='%(prog)s-' + constants.VERSION
#     )
# 
#     parser.add_argument(
#         "-d", "--disable-db-cache",
#         default=False,
#         action="store_true",
#         help="Temporarily not using the result from db cache.\
#               (still save the result into db)"
#     )
# 
#     parser.add_argument(
#         "-t", "--query-timeout",
#         type=float,
#         default=5.0,
#         action="store",
#         help="Set timeout for every query. default is 5 seconds."
#     )
# 
#     def positive_int_only(value):
#         ivalue = int(value)
#         if ivalue <= 0:
#             raise ArgumentTypeError(
#                 "%s is an invalid positive int value" % value
#             )
#         return ivalue
# 
#     parser.add_argument(
#         "-j", "--jobs",
#         type=positive_int_only,
#         nargs="?",
#         default=0,     # 0: not using, None: auto, N (1, 2, ...): N jobs
#         action="store",
#         help="""
#             Allow N jobs at once.
#             Do not pass any argument to use the number of CPUs in the system.
#         """
#     )
# 
#     parser.add_argument(
#         "-sp", "--show-provider",
#         default=False,
#         action="store_true",
#         help="Show the dictionary provider of the queried word"
#     )
# 
#     parser.add_argument(
#         "-su", "--show-url",
#         default=False,
#         action="store_true",
#         help="Show the url of the queried word"
#     )
# 
#     available_dictionaries = list(dictionary_map.keys())
#     available_dictionaries.append('all')
#     parser.add_argument(
#         "-dt", "--dict",
#         default="yahoo",
#         action="store",
#         choices=available_dictionaries,
#         metavar=','.join(available_dictionaries),
#         help="""
#             Must be seperated by comma and no spaces after each comma.
#             Choose the dictionary you want. (default: yahoo)
#             Use 'all' for qureying all dictionaries.
#             If 'all' or more than 1 dictionaries been chosen,
#             --show-provider will be set to True in order to
#             provide more understandable output.
#         """
#     )
# 
#     parser.add_argument(
#         "-ld", "--list-dicts",
#         default=False,
#         action="store_true",
#         help="Show currently supported dictionaries."
#     )
# 
#     parser.add_argument(
#         "-V", "--verbose",
#         default=False,
#         action="store_true",
#         help="Show more information for the queried word.\
#         (If the chosen dictionary have implemented verbose related functions)"
#     )
# 
#     parser.add_argument(
#         "-c", "--force-color",
#         default=False,
#         action="store_true",
#         help="Force color printing (zdict automatically disable color printing \
#         when output is not a tty, use this option to force color printing)"
#     )
# 
#     parser.add_argument(
#         '--dump', dest='pattern',
#         nargs='?',
#         default=None, const=r'^.*$',
#         help='Dump the querying history, can be filtered with regex'
#     )
# 
#     parser.add_argument(
#         "-D", "--debug",
#         default=False,
#         action="store_true",
#         help="Print raw html prettified by BeautifulSoup for debugging."
#     )
# 
#     return parser.parse_args()


# Path: zdict/tests/dictionaries/test_urban.py
from pytest import raises
from unittest.mock import patch
from zdict.dictionaries.urban import UrbanDict
from zdict.exceptions import NotFoundError
from zdict.zdict import get_args




class TestUrbanDict:
    @classmethod
    def setup_class(cls):
        cls.dict = UrbanDict(get_args())
        cls.not_found_word = 'some_not_existing_word'
        cls.word = 'urban'
        cls.record = cls.dict.query(cls.word)

    @classmethod
    def teardown_class(cls):
        del cls.dict
        del cls.not_found_word
        del cls.word
        del cls.record

    def test_provider(self):
        assert self.dict.provider == 'urban'

    def test__get_url(self):

        uri = 'http://api.urbandictionary.com/v0/define?term=mock'