# Path: bento/core/pkg_objects.py
# class DataFiles(object):
#     @classmethod
#     def from_parse_dict(cls, d):
#         return cls(**d)
# 
#     def __init__(self, name, files=None, target_dir=None, source_dir=None):
#         self.name = name
# 
#         if files is not None:
#             self.files = files
#         else:
#             self.files = []
# 
#         if target_dir is not None:
#             self.target_dir = target_dir
#         else:
#             self.target_dir = "$sitedir"
# 
#         if source_dir is not None:
#             self.source_dir = source_dir
#         else:
#             self.source_dir = "."
# 
#     def __repr__(self):
#         return "DataSection(files=%r, target_dir=%r, source_dir=%r)" % \
#                (self.files, self.target_dir, self.source_dir)
# 
#     def __eq__(self, other):
#         return self.__dict__ == other.__dict__
# 
# class Executable(object):
#     @classmethod
#     def from_parse_dict(cls, d):
#         return cls(**d)
# 
#     @classmethod
#     def from_representation(cls, s):
#         if not "=" in s:
#             raise ValueError("s should be of the form name=module:function")
#         name, value = [j.strip() for j in s.split("=")]
#         if not ":" in value:
#             raise ValueError(
#                 "string representation should be of the form module:function, not %s"
#                 % value)
#         module, function = value.split(":", 1)
#         return cls(name, module, function)
# 
#     def __init__(self, name, module, function):
#         # FIXME: check that module is a module name ?
#         self.name = name
#         self.module = module
#         self.function = function
# 
#     # FIXME: this function should not really be here...
#     def representation(self):
#         return ":".join([self.module, self.function])
# 
#     # FIXME: this function should not really be here...
#     def full_representation(self):
#         return "%s = %s" % (self.name, self.representation())
# 
#     def __repr__(self):
#         return repr({"name": self.name, "module": self.module, "function": self.function})


import os
import tempfile
import sys
from bento.compat.api.moves \
    import \
        unittest
from bento.core.pkg_objects \
    import \
        DataFiles, Executable


class TestDataFiles(unittest.TestCase):
    def test_simple(self):
        data = DataFiles("data", files=["foo.c"])
        self.assertEqual(data.name, "data")
        self.assertEqual(data.files, ["foo.c"])
        self.assertEqual(data.source_dir, ".")
        self.assertEqual(data.target_dir, "$sitedir")

    def test_from_dict(self):
        parsed_dict = {"name": "data",
                       "files": ["foo.c", "yo.c"], "target_dir": "foo"}

# Path: bento/core/pkg_objects.py
# class DataFiles(object):
#     @classmethod
#     def from_parse_dict(cls, d):
#         return cls(**d)
# 
#     def __init__(self, name, files=None, target_dir=None, source_dir=None):
#         self.name = name
# 
#         if files is not None:
#             self.files = files
#         else:
#             self.files = []
# 
#         if target_dir is not None:
#             self.target_dir = target_dir
#         else:
#             self.target_dir = "$sitedir"
# 
#         if source_dir is not None:
#             self.source_dir = source_dir
#         else:
#             self.source_dir = "."
# 
#     def __repr__(self):
#         return "DataSection(files=%r, target_dir=%r, source_dir=%r)" % \
#                (self.files, self.target_dir, self.source_dir)
# 
#     def __eq__(self, other):
#         return self.__dict__ == other.__dict__
# 
# class Executable(object):
#     @classmethod
#     def from_parse_dict(cls, d):
#         return cls(**d)
# 
#     @classmethod
#     def from_representation(cls, s):
#         if not "=" in s:
#             raise ValueError("s should be of the form name=module:function")
#         name, value = [j.strip() for j in s.split("=")]
#         if not ":" in value:
#             raise ValueError(
#                 "string representation should be of the form module:function, not %s"
#                 % value)
#         module, function = value.split(":", 1)
#         return cls(name, module, function)
# 
#     def __init__(self, name, module, function):
#         # FIXME: check that module is a module name ?
#         self.name = name
#         self.module = module
#         self.function = function
# 
#     # FIXME: this function should not really be here...
#     def representation(self):
#         return ":".join([self.module, self.function])
# 
#     # FIXME: this function should not really be here...
#     def full_representation(self):
#         return "%s = %s" % (self.name, self.representation())
# 
#     def __repr__(self):
#         return repr({"name": self.name, "module": self.module, "function": self.function})


# Path: bento/core/tests/test_pkg_objects.py
import os
import tempfile
import sys
from bento.compat.api.moves \
    import \
        unittest
from bento.core.pkg_objects \
    import \
        DataFiles, Executable



class TestDataFiles(unittest.TestCase):
    def test_simple(self):
        data = DataFiles("data", files=["foo.c"])
        self.assertEqual(data.name, "data")
        self.assertEqual(data.files, ["foo.c"])
        self.assertEqual(data.source_dir, ".")
        self.assertEqual(data.target_dir, "$sitedir")

    def test_from_dict(self):
        parsed_dict = {"name": "data",
                       "files": ["foo.c", "yo.c"], "target_dir": "foo"}

        data = DataFiles.from_parse_dict(parsed_dict)