<commit_before>import unittest
from mock import Mock
from pyddq.core import Check


class ConstraintTest(unittest.TestCase):
    COLUMN_NAME = "column name"

    def setUp(self):
        self.check = Check(Mock())
        self.jvmCheck = self.check.jvmCheck

    def test_hasUniqueKey(self):
        column_names = ["a", "b"]
        jvm_column_names = Mock()
        self.check._jvm.scala.collection.JavaConversions.\
            iterableAsScalaIterable().toList = Mock(
                return_value=jvm_column_names
        )
        self.check.hasUniqueKey(self.COLUMN_NAME, column_names)
        self.jvmCheck.hasUniqueKey.assert_called_with(
            self.COLUMN_NAME, jvm_column_names
        )

    def test_isNeverNull(self):
        self.check.isNeverNull(self.COLUMN_NAME)
        self.jvmCheck.isNeverNull.assert_called_with(self.COLUMN_NAME)

    def test_isAlwaysNull(self):
        self.check.isAlwaysNull(self.COLUMN_NAME)
        self.jvmCheck.isAlwaysNull.assert_called_with(self.COLUMN_NAME)

    def test_isConvertibleTo(self):
        target_type = Mock()
        target_type.json = Mock(return_value="json value")
        jvm_type = Mock()
        self.check._jvm.org.apache.spark.sql.types.DataType.fromJson = Mock(
            return_value=jvm_type
        )

        self.check.isConvertibleTo(self.COLUMN_NAME, target_type)

        target_type.json.assert_called()
        self.check._jvm.org.apache.spark.sql.types.DataType.fromJson.\
            assert_called_with("json value")
        self.jvmCheck.isConvertibleTo.assert_called_with(
            self.COLUMN_NAME,
            jvm_type
        )

    def test_isFormattedAsDate(self):
        date_format = "yyyy-MM-dd HH:mm:ss"
        jvm_date_format = Mock()
        self.check._jvm.java.text.SimpleDateFormat = Mock(
            return_value=jvm_date_format
        )
        self.check.isFormattedAsDate(self.COLUMN_NAME, date_format)
        self.jvmCheck.isFormattedAsDate.assert_called_with(self.COLUMN_NAME,
                                                           jvm_date_format)

    def test_isAnyOf(self):
        allowed = ("a", "b", "c")
        jvm_allowed = Mock()
        self.check._jvm.scala.collection.JavaConversions.\
            iterableAsScalaIterable().toSet = Mock(
                return_value=jvm_allowed
        )
        self.check.isAnyOf(self.COLUMN_NAME, allowed)
        self.jvmCheck.isAnyOf.assert_called_with(self.COLUMN_NAME, jvm_allowed)

    def test_isMatchingRegex(self):<commit_msg>#117 pyddq: fix unit test for isFormattedAsDate<commit_after>import unittest
from mock import Mock
from pyddq.core import Check


class ConstraintTest(unittest.TestCase):
    COLUMN_NAME = "column name"

    def setUp(self):
        self.check = Check(Mock())
        self.jvmCheck = self.check.jvmCheck

    def test_hasUniqueKey(self):
        column_names = ["a", "b"]
        jvm_column_names = Mock()
        self.check._jvm.scala.collection.JavaConversions.\
            iterableAsScalaIterable().toList = Mock(
                return_value=jvm_column_names
        )
        self.check.hasUniqueKey(self.COLUMN_NAME, column_names)
        self.jvmCheck.hasUniqueKey.assert_called_with(
            self.COLUMN_NAME, jvm_column_names
        )

    def test_isNeverNull(self):
        self.check.isNeverNull(self.COLUMN_NAME)
        self.jvmCheck.isNeverNull.assert_called_with(self.COLUMN_NAME)

    def test_isAlwaysNull(self):
        self.check.isAlwaysNull(self.COLUMN_NAME)
        self.jvmCheck.isAlwaysNull.assert_called_with(self.COLUMN_NAME)

    def test_isConvertibleTo(self):
        target_type = Mock()
        target_type.json = Mock(return_value="json value")
        jvm_type = Mock()
        self.check._jvm.org.apache.spark.sql.types.DataType.fromJson = Mock(
            return_value=jvm_type
        )

        self.check.isConvertibleTo(self.COLUMN_NAME, target_type)

        target_type.json.assert_called()
        self.check._jvm.org.apache.spark.sql.types.DataType.fromJson.\
            assert_called_with("json value")
        self.jvmCheck.isConvertibleTo.assert_called_with(
            self.COLUMN_NAME,
            jvm_type
        )

    def test_isFormattedAsDate(self):
        date_format = "yyyy-MM-dd HH:mm:ss"
        self.check.isFormattedAsDate(self.COLUMN_NAME, date_format)
        self.jvmCheck.isFormattedAsDate.assert_called_with(self.COLUMN_NAME,
                                                           date_format)

    def test_isAnyOf(self):
        allowed = ("a", "b", "c")
        jvm_allowed = Mock()
        self.check._jvm.scala.collection.JavaConversions.\
            iterableAsScalaIterable().toSet = Mock(
                return_value=jvm_allowed
        )
        self.check.isAnyOf(self.COLUMN_NAME, allowed)
        self.jvmCheck.isAnyOf.assert_called_with(self.COLUMN_NAME, jvm_allowed)

    def test_isMatchingRegex(self):
{'fraction_non_alphanumeric': 0.09407452657299939, 'fraction_numerical': 0.0006108735491753207, 'mean_word_length': 2.473833097595474, 'pattern_counts': {'":': 0, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3000121', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1574, 'n_words': 196}