<commit_before>import unittest
from unittest import mock
from wqflask.show_trait.export_trait_data import dict_to_sorted_list
from wqflask.show_trait.export_trait_data import cmp_samples
from wqflask.show_trait.export_trait_data import export_sample_table
from wqflask.show_trait.export_trait_data import get_export_metadata


class AttributesSetter:
    def __init__(self, obj):
        for key, value in obj.items():
            setattr(self, key, value)


class HelperClass:
    pass


class TestExportTraits(unittest.TestCase):
    """Test methods related to converting dict to sortedlist"""
    @mock.patch("wqflask.show_trait.export_trait_data.create_trait")
    @mock.patch("wqflask.show_trait.export_trait_data.data_set")
    def test_get_export_metadata_no_publish(self, mock_dataset, mock_trait):
        """test for exporting metadata with no publish"""
        mock_dataset_attributes = AttributesSetter(
            {"type": "no_publish", "dataset_name": "Temp", "name": "Temp"})

        mock_nested_attributes = HelperClass()
        mock_nested_attributes.name = "name"
        mock_dataset_attributes.group = mock_nested_attributes
        mock_dataset.create_dataset.return_value = mock_dataset_attributes
        mock_trait.return_value = AttributesSetter({"symbol": "", "description_display": "Description",
                                                         "title": "research1", "journal": "", "authors": ""})

        results = get_export_metadata("random_id", "Temp")
        expected = [["Record ID: random_id"],
                    ["Trait URL: http://genenetwork.org/show_trait?trait_id=random_id&dataset=Temp"],
                    ["Dataset: Temp"],
                    ["Group: name"], []]

        mock_dataset.create_dataset.assert_called_with("Temp")
        mock_trait.assert_called_with(
            dataset=mock_dataset_attributes, name="random_id", cellid=None, get_qtl_info=False)
        self.assertEqual(results, expected)

    @mock.patch("wqflask.show_trait.export_trait_data.create_trait")
    @mock.patch("wqflask.show_trait.export_trait_data.data_set")
    def test_get_export_metadata_with_publish(self, data_mock, trait_mock):
        """test for exporting metadata with dataset.type=Publish"""
        mock_dataset_attributes = AttributesSetter({"type": "Publish", "dataset_name": "Temp",
                                                         "name": "Temp", "description_display": "Description goes here"})

        mock_nested_attributes = HelperClass()
        mock_nested_attributes.name = "name"
        mock_dataset_attributes.group = mock_nested_attributes
        data_mock.create_dataset.return_value = mock_dataset_attributes
        trait_instance = AttributesSetter({"symbol": "", "description_display": "Description",
                                                "title": "research1", "journal": "", "authors": ""})
        trait_mock.return_value = trait_instance

        results = get_export_metadata(
            "29ae0615-0d77-4814-97c7-c9e91f6bfd7b", "Temp")

        expected = [['Phenotype ID: 29ae0615-0d77-4814-97c7-c9e91f6bfd7b'],<commit_msg>remove redundant classes<commit_after>import unittest
from unittest import mock
from wqflask.show_trait.export_trait_data import dict_to_sorted_list
from wqflask.show_trait.export_trait_data import cmp_samples
from wqflask.show_trait.export_trait_data import export_sample_table
from wqflask.show_trait.export_trait_data import get_export_metadata


class AttributesSetter:
    def __init__(self, obj):
        for key, value in obj.items():
            setattr(self, key, value)


class TestExportTraits(unittest.TestCase):
    """Test methods related to converting dict to sortedlist"""
    @mock.patch("wqflask.show_trait.export_trait_data.create_trait")
    @mock.patch("wqflask.show_trait.export_trait_data.data_set")
    def test_get_export_metadata_no_publish(self, mock_dataset, mock_trait):
        """test for exporting metadata with no publish"""
        mock_dataset_attributes = AttributesSetter(
            {"type": "no_publish", "dataset_name": "Temp", "name": "Temp"})

        mock_nested_attributes = AttributesSetter({"name": "name"})
        mock_dataset_attributes.group = mock_nested_attributes
        mock_dataset.create_dataset.return_value = mock_dataset_attributes
        mock_trait.return_value = AttributesSetter({"symbol": "", "description_display": "Description",
                                                    "title": "research1", "journal": "", "authors": ""})

        results = get_export_metadata("random_id", "Temp")
        expected = [["Record ID: random_id"],
                    ["Trait URL: http://genenetwork.org/show_trait?trait_id=random_id&dataset=Temp"],
                    ["Dataset: Temp"],
                    ["Group: name"], []]

        mock_dataset.create_dataset.assert_called_with("Temp")
        mock_trait.assert_called_with(
            dataset=mock_dataset_attributes, name="random_id", cellid=None, get_qtl_info=False)
        self.assertEqual(results, expected)

    @mock.patch("wqflask.show_trait.export_trait_data.create_trait")
    @mock.patch("wqflask.show_trait.export_trait_data.data_set")
    def test_get_export_metadata_with_publish(self, data_mock, trait_mock):
        """test for exporting metadata with dataset.type=Publish"""
        mock_dataset_attributes = AttributesSetter({"type": "Publish", "dataset_name": "Temp",
                                                    "name": "Temp", "description_display": "Description goes here"})

        mock_nested_attributes = AttributesSetter({"name": "name"})
        mock_dataset_attributes.group = mock_nested_attributes
        data_mock.create_dataset.return_value = mock_dataset_attributes
        trait_instance = AttributesSetter({"symbol": "", "description_display": "Description",
                                           "title": "research1", "journal": "", "authors": ""})
        trait_mock.return_value = trait_instance

        results = get_export_metadata(
            "29ae0615-0d77-4814-97c7-c9e91f6bfd7b", "Temp")

        expected = [['Phenotype ID: 29ae0615-0d77-4814-97c7-c9e91f6bfd7b'],
{'fraction_non_alphanumeric': 0.10875202593192869, 'fraction_numerical': 0.01426256077795786, 'mean_word_length': 3.324456902592852, 'pattern_counts': {'":': 36, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2979164', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1802, 'n_words': 308}