# Path: sanskrit_parser/util/DhatuWrapper.py
# class DhatuWrapper(object):
#     """
#     Class to interface with the kRShNamAchArya dhAtupATha
#     https://github.com/sanskrit-coders/stardict-sanskrit/tree/master/sa-vyAkaraNa/dhAtu-pATha-kRShNAchArya
#     """
#     db_file = "dhAtu-pATha-kRShNAchArya.json"
#     q = Query()
# 
#     def __init__(self, logger=None):
#         self.logger = logger or logging.getLogger(__name__)
#         db_path = data_file_path(self.db_file)
#         self.db = TinyDB(db_path, access_mode='r')
#         assert len(self.db.all()) != 0
# 
#     def _get_dhatus(self, d):
#         """ Get all tags for a dhatu d """
#         if d is None:
#             return None
#         else:
#             return self.db.search(self.q.DAtuH == d)
# 
#     def is_sakarmaka(self, d):
#         """ Is d sakarmaka? """
#         # Tags
#         tl = self._get_dhatus(d)
#         if len(tl) != 0:
#             supported_karmakas = {'sakarmakaH', 'dvikarmakaH'}
#             return any([t['karmakatvaM'] in supported_karmakas for t in tl])
#         else:
#             self.logger.debug("Couldn't find dhatu {} in database".format(d))
#             return False
# 
#     def is_dvikarmaka(self, d):
#         """ Is d dvikarmaka? """
#         # Tags
#         tl = self._get_dhatus(d)
#         if len(tl) != 0:
#             supported_karmakas = {'dvikarmakaH'}
#             return any([t['karmakatvaM'] in supported_karmakas for t in tl])
#         else:
#             self.logger.debug("Couldn't find dhatu {} in database".format(d))
#             return False
# 
# Path: sanskrit_parser/base/sanskrit_base.py
# class SanskritImmutableString(SanskritString):
#     """ Immutable version of SanskritString
#     """
#     def __init__(self, thing=None, encoding=None, unicode_encoding='utf-8'):
#         super().__init__(thing, encoding, unicode_encoding)
# 
#     def __hash__(self):
#         return hash(str(self))
# 
#     def __eq__(self, other):
#         return str(self) == str(other)
# 
#     def __ne__(self, other):
#         return str(self) != str(other)
# 
# SLP1 = sanscript.SLP1


from sanskrit_parser.util import DhatuWrapper
from sanskrit_parser.base.sanskrit_base import SanskritImmutableString, SLP1
import logging
"""
Tests for DhatuWrapper
"""

logger = logging.getLogger(__name__)


def test_is_sakarmaka():
    s = SanskritImmutableString("kf")
    it = s.transcoded(SLP1)
    w = DhatuWrapper.DhatuWrapper()

    is_sakarmaka = w.is_sakarmaka(it)

    assert is_sakarmaka is True


def test_is_sakarmaka_for_dvikarmaka():
    s = SanskritImmutableString("nI")
    it = s.transcoded(SLP1)

# Path: sanskrit_parser/util/DhatuWrapper.py
# class DhatuWrapper(object):
#     """
#     Class to interface with the kRShNamAchArya dhAtupATha
#     https://github.com/sanskrit-coders/stardict-sanskrit/tree/master/sa-vyAkaraNa/dhAtu-pATha-kRShNAchArya
#     """
#     db_file = "dhAtu-pATha-kRShNAchArya.json"
#     q = Query()
# 
#     def __init__(self, logger=None):
#         self.logger = logger or logging.getLogger(__name__)
#         db_path = data_file_path(self.db_file)
#         self.db = TinyDB(db_path, access_mode='r')
#         assert len(self.db.all()) != 0
# 
#     def _get_dhatus(self, d):
#         """ Get all tags for a dhatu d """
#         if d is None:
#             return None
#         else:
#             return self.db.search(self.q.DAtuH == d)
# 
#     def is_sakarmaka(self, d):
#         """ Is d sakarmaka? """
#         # Tags
#         tl = self._get_dhatus(d)
#         if len(tl) != 0:
#             supported_karmakas = {'sakarmakaH', 'dvikarmakaH'}
#             return any([t['karmakatvaM'] in supported_karmakas for t in tl])
#         else:
#             self.logger.debug("Couldn't find dhatu {} in database".format(d))
#             return False
# 
#     def is_dvikarmaka(self, d):
#         """ Is d dvikarmaka? """
#         # Tags
#         tl = self._get_dhatus(d)
#         if len(tl) != 0:
#             supported_karmakas = {'dvikarmakaH'}
#             return any([t['karmakatvaM'] in supported_karmakas for t in tl])
#         else:
#             self.logger.debug("Couldn't find dhatu {} in database".format(d))
#             return False
# 
# Path: sanskrit_parser/base/sanskrit_base.py
# class SanskritImmutableString(SanskritString):
#     """ Immutable version of SanskritString
#     """
#     def __init__(self, thing=None, encoding=None, unicode_encoding='utf-8'):
#         super().__init__(thing, encoding, unicode_encoding)
# 
#     def __hash__(self):
#         return hash(str(self))
# 
#     def __eq__(self, other):
#         return str(self) == str(other)
# 
#     def __ne__(self, other):
#         return str(self) != str(other)
# 
# SLP1 = sanscript.SLP1


# Path: tests/test_DhatuWrapper.py
from sanskrit_parser.util import DhatuWrapper
from sanskrit_parser.base.sanskrit_base import SanskritImmutableString, SLP1
import logging

"""
Tests for DhatuWrapper
"""

logger = logging.getLogger(__name__)


def test_is_sakarmaka():
    s = SanskritImmutableString("kf")
    it = s.transcoded(SLP1)
    w = DhatuWrapper.DhatuWrapper()

    is_sakarmaka = w.is_sakarmaka(it)

    assert is_sakarmaka is True


def test_is_sakarmaka_for_dvikarmaka():
    s = SanskritImmutableString("nI")
    it = s.transcoded(SLP1)

    w = DhatuWrapper.DhatuWrapper()