# Path: beancount_import/source/description_based_source.py
# class DescriptionBasedSource(Source):
#     def get_example_key_value_pairs(self, transaction: Transaction,
#                                     posting: Posting):
#         result = {}
#         if posting.meta is not None:
#             meta = posting.meta
#             key = SOURCE_DESC_KEYS[0]
#             value = meta.get(key)
#             if value is not None:
#                 result['desc'] = value
#         return result
# 
#     def is_posting_cleared(self, posting: Posting):
#         if posting.meta is None:
#             return False
#         if posting.meta.get("merge"):
#             return True
#         return not MATCHED_METADATA_KEYS.isdisjoint(posting.meta)


import unittest
from beancount.core.amount import Amount
from beancount.core.data import Posting
from beancount.core.number import D
from .description_based_source import DescriptionBasedSource




class DescriptionBasedSourceTest(unittest.TestCase):
    def test_merged_posting_is_cleared(self):
        postings = [
            Posting(account="a", units=Amount(D(10), "USD"), cost=None,
                    price=None, flag=None, meta=None),
            Posting(account="a", units=Amount(D(10), "USD"), cost=None,
                    price=None, flag=None, meta={"merge": True}),
        ]

# Path: beancount_import/source/description_based_source.py
# class DescriptionBasedSource(Source):
#     def get_example_key_value_pairs(self, transaction: Transaction,
#                                     posting: Posting):
#         result = {}
#         if posting.meta is not None:
#             meta = posting.meta
#             key = SOURCE_DESC_KEYS[0]
#             value = meta.get(key)
#             if value is not None:
#                 result['desc'] = value
#         return result
# 
#     def is_posting_cleared(self, posting: Posting):
#         if posting.meta is None:
#             return False
#         if posting.meta.get("merge"):
#             return True
#         return not MATCHED_METADATA_KEYS.isdisjoint(posting.meta)


# Path: beancount_import/source/description_based_source_test.py
import unittest
from beancount.core.amount import Amount
from beancount.core.data import Posting
from beancount.core.number import D
from .description_based_source import DescriptionBasedSource





class DescriptionBasedSourceTest(unittest.TestCase):
    def test_merged_posting_is_cleared(self):
        postings = [
            Posting(account="a", units=Amount(D(10), "USD"), cost=None,
                    price=None, flag=None, meta=None),
            Posting(account="a", units=Amount(D(10), "USD"), cost=None,
                    price=None, flag=None, meta={"merge": True}),
        ]

        source = DescriptionBasedSource(lambda s: None)