Пример #1
0
 def test_could_be_datetime(self):
     self.assertEqual(True, Record.could_be_datetime("Jan 2014", '%b %Y'))
     self.assertEqual(
         True, Record.could_be_datetime(u"September 1, 2014", '%B %m, %Y'))
     self.assertEqual(False, Record.could_be_datetime(None, None))
     self.assertEqual(False, Record.could_be_datetime("", ""))
     self.assertEqual(False, Record.could_be_datetime("Jan 2004", ""))
 def test_could_be_boolean(self):
     self.assertEqual(True, Record.could_be_boolean("1"))
     self.assertEqual(True, Record.could_be_boolean(1))
     self.assertEqual(True, Record.could_be_boolean(True))
     self.assertEqual(True, Record.could_be_boolean(False))
     self.assertEqual(True, Record.could_be_boolean(0))
     self.assertEqual(True, Record.could_be_boolean("1"))
     self.assertEqual(False, Record.could_be_boolean("ABCD"))
     self.assertEqual(False, Record.could_be_boolean(1234))
     self.assertEqual(False, Record.could_be_boolean(None))
Пример #3
0
 def test_could_be_boolean(self):
     self.assertEqual(True, Record.could_be_boolean("1"))
     self.assertEqual(True, Record.could_be_boolean(1))
     self.assertEqual(True, Record.could_be_boolean(True))
     self.assertEqual(True, Record.could_be_boolean(False))
     self.assertEqual(True, Record.could_be_boolean(0))
     self.assertEqual(True, Record.could_be_boolean("1"))
     self.assertEqual(False, Record.could_be_boolean("ABCD"))
     self.assertEqual(False, Record.could_be_boolean(1234))
     self.assertEqual(False, Record.could_be_boolean(None))
 def test_could_be_datetime(self):
     self.assertEqual(True, Record.could_be_datetime("Jan 2014", '%b %Y'))
     self.assertEqual(True, Record.could_be_datetime(u"September 1, 2014", '%B %m, %Y'))
     self.assertEqual(False, Record.could_be_datetime(None, None))
     self.assertEqual(False, Record.could_be_datetime("", ""))
     self.assertEqual(False, Record.could_be_datetime("Jan 2004", ""))
 def test_could_be_number(self):
     self.assertEqual(True, Record.could_be_number("1"))
     self.assertEqual(True, Record.could_be_number("1.1"))
     self.assertEqual(True, Record.could_be_number("0.1"))
     self.assertEqual(True, Record.could_be_number("000000000000000000000000.1"))
     self.assertEqual(True, Record.could_be_number(0000000000000000000000000.1))
     self.assertEqual(True, Record.could_be_number(10000000000000000000000000.1))
     self.assertEqual(True, Record.could_be_number(str(math.pow(2,63)-1)))
     self.assertEqual(True, Record.could_be_number(10000000000000000000000000))
     self.assertEqual(False, Record.could_be_number("abcd"))
     self.assertEqual(False, Record.could_be_number(None))
     self.assertEqual(False, Record.could_be_number("1111.10000000000.000000000"))
 def test_could_be_int(self):
     self.assertEqual(True, Record.could_be_int("1"))
     self.assertEqual(True, Record.could_be_int(0))
     self.assertEqual(True, Record.could_be_int(2147483647))
     self.assertEqual(True, Record.could_be_int(-2147483647))
     self.assertEqual(True, Record.could_be_int("-2147483647"))
     self.assertEqual(False, Record.could_be_int(math.pow(2,32)))
     self.assertEqual(False, Record.could_be_int(u"1.1"))
     self.assertEqual(False, Record.could_be_int("0.1"))
     self.assertEqual(False, Record.could_be_int("000000000000000000000000.1"))
     self.assertEqual(False, Record.could_be_int(0000000000000000000000000.1))
     self.assertEqual(False, Record.could_be_int(10000000000000000000000000))
     self.assertEqual(False, Record.could_be_int("abcd"))
     self.assertEqual(False, Record.could_be_int(None))
     self.assertEqual(False, Record.could_be_int("1111.10000000000.000000000"))
 def test_parse_boolean(self):
     self.assertEqual(True, Record.parse_boolean("1"))
     self.assertEqual(None, Record.parse_boolean("100"))
     self.assertEqual(True, Record.parse_boolean("TrUe"))
     self.assertEqual(False, Record.parse_boolean("FaLSe"))
     self.assertEqual(True, Record.parse_boolean("true"))
     self.assertEqual(False, Record.parse_boolean("false"))
     self.assertEqual(False, Record.parse_boolean("0"))
     self.assertEqual(None, Record.parse_boolean("ABCD"))
     self.assertEqual(True, Record.parse_boolean(True))
     self.assertEqual(False, Record.parse_boolean(False))
     self.assertEqual(False, Record.parse_boolean(0))
     self.assertEqual(True, Record.parse_boolean(1))
     self.assertEqual(None, Record.parse_boolean(None))
 def test_is_empty_string(self):
     self.assertEqual(True, Record.is_empty_str(""))
     self.assertEqual(True, Record.is_empty_str(u""))
     self.assertEqual(False, Record.is_empty_str(u"adfasdf"))
     self.assertEqual(False, Record.is_empty_str(1234123))
     self.assertEqual(False, Record.is_empty_str(None))
 def setUp(self):
     self.obj = Record()
class TestGritsRecord(unittest.TestCase):
    def setUp(self):
        self.obj = Record()

    def test_to_json_empty(self):
        self.assertEqual("{}", self.obj.to_json())

    def test_is_empty_string(self):
        self.assertEqual(True, Record.is_empty_str(""))
        self.assertEqual(True, Record.is_empty_str(u""))
        self.assertEqual(False, Record.is_empty_str(u"adfasdf"))
        self.assertEqual(False, Record.is_empty_str(1234123))
        self.assertEqual(False, Record.is_empty_str(None))

    def test_could_be_boolean(self):
        self.assertEqual(True, Record.could_be_boolean("1"))
        self.assertEqual(True, Record.could_be_boolean(1))
        self.assertEqual(True, Record.could_be_boolean(True))
        self.assertEqual(True, Record.could_be_boolean(False))
        self.assertEqual(True, Record.could_be_boolean(0))
        self.assertEqual(True, Record.could_be_boolean("1"))
        self.assertEqual(False, Record.could_be_boolean("ABCD"))
        self.assertEqual(False, Record.could_be_boolean(1234))
        self.assertEqual(False, Record.could_be_boolean(None))

    def test_parse_boolean(self):
        self.assertEqual(True, Record.parse_boolean("1"))
        self.assertEqual(None, Record.parse_boolean("100"))
        self.assertEqual(True, Record.parse_boolean("TrUe"))
        self.assertEqual(False, Record.parse_boolean("FaLSe"))
        self.assertEqual(True, Record.parse_boolean("true"))
        self.assertEqual(False, Record.parse_boolean("false"))
        self.assertEqual(False, Record.parse_boolean("0"))
        self.assertEqual(None, Record.parse_boolean("ABCD"))
        self.assertEqual(True, Record.parse_boolean(True))
        self.assertEqual(False, Record.parse_boolean(False))
        self.assertEqual(False, Record.parse_boolean(0))
        self.assertEqual(True, Record.parse_boolean(1))
        self.assertEqual(None, Record.parse_boolean(None))

    def test_could_be_float(self):
        self.assertEqual(True, Record.could_be_float("1"))
        self.assertEqual(True, Record.could_be_float(u"1.1"))
        self.assertEqual(True, Record.could_be_float("0.1"))
        self.assertEqual(True, Record.could_be_float("000000000000000000000000.1"))
        self.assertEqual(True, Record.could_be_float(0000000000000000000000000.1))
        self.assertEqual(True, Record.could_be_float(10000000000000000000000000.1))
        self.assertEqual(True, Record.could_be_float(str(math.pow(2,63)-1)))
        self.assertEqual(False, Record.could_be_float(10000000000000000000000000))
        self.assertEqual(False, Record.could_be_float("abcd"))
        self.assertEqual(False, Record.could_be_float(None))
        self.assertEqual(False, Record.could_be_float("1111.10000000000.000000000"))

    def test_could_be_int(self):
        self.assertEqual(True, Record.could_be_int("1"))
        self.assertEqual(True, Record.could_be_int(0))
        self.assertEqual(True, Record.could_be_int(2147483647))
        self.assertEqual(True, Record.could_be_int(-2147483647))
        self.assertEqual(True, Record.could_be_int("-2147483647"))
        self.assertEqual(False, Record.could_be_int(math.pow(2,32)))
        self.assertEqual(False, Record.could_be_int(u"1.1"))
        self.assertEqual(False, Record.could_be_int("0.1"))
        self.assertEqual(False, Record.could_be_int("000000000000000000000000.1"))
        self.assertEqual(False, Record.could_be_int(0000000000000000000000000.1))
        self.assertEqual(False, Record.could_be_int(10000000000000000000000000))
        self.assertEqual(False, Record.could_be_int("abcd"))
        self.assertEqual(False, Record.could_be_int(None))
        self.assertEqual(False, Record.could_be_int("1111.10000000000.000000000"))

        #self.mongo_connection.db = mongomock.Database()
        #self.mongo_connection.db['airports'] = mongomock.Collection()

    def test_could_be_number(self):
        self.assertEqual(True, Record.could_be_number("1"))
        self.assertEqual(True, Record.could_be_number("1.1"))
        self.assertEqual(True, Record.could_be_number("0.1"))
        self.assertEqual(True, Record.could_be_number("000000000000000000000000.1"))
        self.assertEqual(True, Record.could_be_number(0000000000000000000000000.1))
        self.assertEqual(True, Record.could_be_number(10000000000000000000000000.1))
        self.assertEqual(True, Record.could_be_number(str(math.pow(2,63)-1)))
        self.assertEqual(True, Record.could_be_number(10000000000000000000000000))
        self.assertEqual(False, Record.could_be_number("abcd"))
        self.assertEqual(False, Record.could_be_number(None))
        self.assertEqual(False, Record.could_be_number("1111.10000000000.000000000"))

    def test_could_be_datetime(self):
        self.assertEqual(True, Record.could_be_datetime("Jan 2014", '%b %Y'))
        self.assertEqual(True, Record.could_be_datetime(u"September 1, 2014", '%B %m, %Y'))
        self.assertEqual(False, Record.could_be_datetime(None, None))
        self.assertEqual(False, Record.could_be_datetime("", ""))
        self.assertEqual(False, Record.could_be_datetime("Jan 2004", ""))
Пример #11
0
 def test_could_be_number(self):
     self.assertEqual(True, Record.could_be_number("1"))
     self.assertEqual(True, Record.could_be_number("1.1"))
     self.assertEqual(True, Record.could_be_number("0.1"))
     self.assertEqual(True,
                      Record.could_be_number("000000000000000000000000.1"))
     self.assertEqual(True,
                      Record.could_be_number(0000000000000000000000000.1))
     self.assertEqual(True,
                      Record.could_be_number(10000000000000000000000000.1))
     self.assertEqual(True,
                      Record.could_be_number(str(math.pow(2, 63) - 1)))
     self.assertEqual(True,
                      Record.could_be_number(10000000000000000000000000))
     self.assertEqual(False, Record.could_be_number("abcd"))
     self.assertEqual(False, Record.could_be_number(None))
     self.assertEqual(False,
                      Record.could_be_number("1111.10000000000.000000000"))
Пример #12
0
 def test_could_be_int(self):
     self.assertEqual(True, Record.could_be_int("1"))
     self.assertEqual(True, Record.could_be_int(0))
     self.assertEqual(True, Record.could_be_int(2147483647))
     self.assertEqual(True, Record.could_be_int(-2147483647))
     self.assertEqual(True, Record.could_be_int("-2147483647"))
     self.assertEqual(False, Record.could_be_int(math.pow(2, 32)))
     self.assertEqual(False, Record.could_be_int(u"1.1"))
     self.assertEqual(False, Record.could_be_int("0.1"))
     self.assertEqual(False,
                      Record.could_be_int("000000000000000000000000.1"))
     self.assertEqual(False,
                      Record.could_be_int(0000000000000000000000000.1))
     self.assertEqual(False,
                      Record.could_be_int(10000000000000000000000000))
     self.assertEqual(False, Record.could_be_int("abcd"))
     self.assertEqual(False, Record.could_be_int(None))
     self.assertEqual(False,
                      Record.could_be_int("1111.10000000000.000000000"))
Пример #13
0
 def test_parse_boolean(self):
     self.assertEqual(True, Record.parse_boolean("1"))
     self.assertEqual(None, Record.parse_boolean("100"))
     self.assertEqual(True, Record.parse_boolean("TrUe"))
     self.assertEqual(False, Record.parse_boolean("FaLSe"))
     self.assertEqual(True, Record.parse_boolean("true"))
     self.assertEqual(False, Record.parse_boolean("false"))
     self.assertEqual(False, Record.parse_boolean("0"))
     self.assertEqual(None, Record.parse_boolean("ABCD"))
     self.assertEqual(True, Record.parse_boolean(True))
     self.assertEqual(False, Record.parse_boolean(False))
     self.assertEqual(False, Record.parse_boolean(0))
     self.assertEqual(True, Record.parse_boolean(1))
     self.assertEqual(None, Record.parse_boolean(None))
Пример #14
0
 def test_is_empty_string(self):
     self.assertEqual(True, Record.is_empty_str(""))
     self.assertEqual(True, Record.is_empty_str(u""))
     self.assertEqual(False, Record.is_empty_str(u"adfasdf"))
     self.assertEqual(False, Record.is_empty_str(1234123))
     self.assertEqual(False, Record.is_empty_str(None))
Пример #15
0
 def setUp(self):
     self.obj = Record()
Пример #16
0
class TestGritsRecord(unittest.TestCase):
    def setUp(self):
        self.obj = Record()

    def test_to_json_empty(self):
        self.assertEqual("{}", self.obj.to_json())

    def test_is_empty_string(self):
        self.assertEqual(True, Record.is_empty_str(""))
        self.assertEqual(True, Record.is_empty_str(u""))
        self.assertEqual(False, Record.is_empty_str(u"adfasdf"))
        self.assertEqual(False, Record.is_empty_str(1234123))
        self.assertEqual(False, Record.is_empty_str(None))

    def test_could_be_boolean(self):
        self.assertEqual(True, Record.could_be_boolean("1"))
        self.assertEqual(True, Record.could_be_boolean(1))
        self.assertEqual(True, Record.could_be_boolean(True))
        self.assertEqual(True, Record.could_be_boolean(False))
        self.assertEqual(True, Record.could_be_boolean(0))
        self.assertEqual(True, Record.could_be_boolean("1"))
        self.assertEqual(False, Record.could_be_boolean("ABCD"))
        self.assertEqual(False, Record.could_be_boolean(1234))
        self.assertEqual(False, Record.could_be_boolean(None))

    def test_parse_boolean(self):
        self.assertEqual(True, Record.parse_boolean("1"))
        self.assertEqual(None, Record.parse_boolean("100"))
        self.assertEqual(True, Record.parse_boolean("TrUe"))
        self.assertEqual(False, Record.parse_boolean("FaLSe"))
        self.assertEqual(True, Record.parse_boolean("true"))
        self.assertEqual(False, Record.parse_boolean("false"))
        self.assertEqual(False, Record.parse_boolean("0"))
        self.assertEqual(None, Record.parse_boolean("ABCD"))
        self.assertEqual(True, Record.parse_boolean(True))
        self.assertEqual(False, Record.parse_boolean(False))
        self.assertEqual(False, Record.parse_boolean(0))
        self.assertEqual(True, Record.parse_boolean(1))
        self.assertEqual(None, Record.parse_boolean(None))

    def test_could_be_float(self):
        self.assertEqual(True, Record.could_be_float("1"))
        self.assertEqual(True, Record.could_be_float(u"1.1"))
        self.assertEqual(True, Record.could_be_float("0.1"))
        self.assertEqual(True,
                         Record.could_be_float("000000000000000000000000.1"))
        self.assertEqual(True,
                         Record.could_be_float(0000000000000000000000000.1))
        self.assertEqual(True,
                         Record.could_be_float(10000000000000000000000000.1))
        self.assertEqual(True, Record.could_be_float(str(math.pow(2, 63) - 1)))
        self.assertEqual(False,
                         Record.could_be_float(10000000000000000000000000))
        self.assertEqual(False, Record.could_be_float("abcd"))
        self.assertEqual(False, Record.could_be_float(None))
        self.assertEqual(False,
                         Record.could_be_float("1111.10000000000.000000000"))

    def test_could_be_int(self):
        self.assertEqual(True, Record.could_be_int("1"))
        self.assertEqual(True, Record.could_be_int(0))
        self.assertEqual(True, Record.could_be_int(2147483647))
        self.assertEqual(True, Record.could_be_int(-2147483647))
        self.assertEqual(True, Record.could_be_int("-2147483647"))
        self.assertEqual(False, Record.could_be_int(math.pow(2, 32)))
        self.assertEqual(False, Record.could_be_int(u"1.1"))
        self.assertEqual(False, Record.could_be_int("0.1"))
        self.assertEqual(False,
                         Record.could_be_int("000000000000000000000000.1"))
        self.assertEqual(False,
                         Record.could_be_int(0000000000000000000000000.1))
        self.assertEqual(False,
                         Record.could_be_int(10000000000000000000000000))
        self.assertEqual(False, Record.could_be_int("abcd"))
        self.assertEqual(False, Record.could_be_int(None))
        self.assertEqual(False,
                         Record.could_be_int("1111.10000000000.000000000"))

        #self.mongo_connection.db = mongomock.Database()
        #self.mongo_connection.db['airports'] = mongomock.Collection()

    def test_could_be_number(self):
        self.assertEqual(True, Record.could_be_number("1"))
        self.assertEqual(True, Record.could_be_number("1.1"))
        self.assertEqual(True, Record.could_be_number("0.1"))
        self.assertEqual(True,
                         Record.could_be_number("000000000000000000000000.1"))
        self.assertEqual(True,
                         Record.could_be_number(0000000000000000000000000.1))
        self.assertEqual(True,
                         Record.could_be_number(10000000000000000000000000.1))
        self.assertEqual(True,
                         Record.could_be_number(str(math.pow(2, 63) - 1)))
        self.assertEqual(True,
                         Record.could_be_number(10000000000000000000000000))
        self.assertEqual(False, Record.could_be_number("abcd"))
        self.assertEqual(False, Record.could_be_number(None))
        self.assertEqual(False,
                         Record.could_be_number("1111.10000000000.000000000"))

    def test_could_be_datetime(self):
        self.assertEqual(True, Record.could_be_datetime("Jan 2014", '%b %Y'))
        self.assertEqual(
            True, Record.could_be_datetime(u"September 1, 2014", '%B %m, %Y'))
        self.assertEqual(False, Record.could_be_datetime(None, None))
        self.assertEqual(False, Record.could_be_datetime("", ""))
        self.assertEqual(False, Record.could_be_datetime("Jan 2004", ""))