Exemple #1
0
    def test_format_integer(self):
        knob_unit_bytes = KnobUnitType()
        knob_unit_bytes.unit = 1
        knob_unit_time = KnobUnitType()
        knob_unit_time.unit = 2
        knob_unit_other = KnobUnitType()
        knob_unit_other.unit = 3

        self.assertEqual(self.test_dbms.format_integer(5, knob_unit_other), 5)
        self.assertEqual(self.test_dbms.format_integer(0, knob_unit_other), 0)
        self.assertEqual(self.test_dbms.format_integer(-1, knob_unit_other),
                         -1)

        self.assertEqual(self.test_dbms.format_integer(5120, knob_unit_bytes),
                         '5kB')
        self.assertEqual(
            self.test_dbms.format_integer(4194304, knob_unit_bytes), '4MB')
        self.assertEqual(
            self.test_dbms.format_integer(4194500, knob_unit_bytes), '4MB')

        self.assertEqual(
            self.test_dbms.format_integer(86400000, knob_unit_time), '1d')
        self.assertEqual(
            self.test_dbms.format_integer(72000000, knob_unit_time), '20h')
        self.assertEqual(self.test_dbms.format_integer(600000, knob_unit_time),
                         '10min')
        self.assertEqual(self.test_dbms.format_integer(1000, knob_unit_time),
                         '1s')
        self.assertEqual(self.test_dbms.format_integer(500, knob_unit_time),
                         '500ms')
Exemple #2
0
    def test_convert_integer(self):
        super().test_convert_integer()

        # Convert Integer
        knob_unit_bytes = KnobUnitType()
        knob_unit_bytes.unit = 1
        knob_unit_time = KnobUnitType()
        knob_unit_time.unit = 2
        knob_unit_other = KnobUnitType()
        knob_unit_other.unit = 3

        self.assertEqual(self.test_dbms.convert_integer('5', knob_unit_other),
                         5)
        self.assertEqual(self.test_dbms.convert_integer('0', knob_unit_other),
                         0)
        self.assertEqual(
            self.test_dbms.convert_integer('0.0', knob_unit_other), 0)
        self.assertEqual(
            self.test_dbms.convert_integer('0.5', knob_unit_other), 0)

        self.assertEqual(
            self.test_dbms.convert_integer('5kB', knob_unit_bytes), 5 * 1024)
        self.assertEqual(
            self.test_dbms.convert_integer('4MB', knob_unit_bytes),
            4 * 1024**2)

        self.assertEqual(self.test_dbms.convert_integer('1d', knob_unit_time),
                         86400000)
        self.assertEqual(self.test_dbms.convert_integer('20h', knob_unit_time),
                         72000000)
        self.assertEqual(
            self.test_dbms.convert_integer('10min', knob_unit_time), 600000)
        self.assertEqual(self.test_dbms.convert_integer('1s', knob_unit_time),
                         1000)
        self.assertEqual(
            self.test_dbms.convert_integer('5000ms', knob_unit_time), 5000)

        test_exceptions = [('A', knob_unit_other), ('', knob_unit_other),
                           ('', knob_unit_bytes), ('', knob_unit_time),
                           ('1S', knob_unit_time), ('1mb', knob_unit_bytes)]

        for failure_case, knob_unit in test_exceptions:
            with self.assertRaises(Exception):
                self.test_dbms.convert_integer(failure_case, knob_unit)
    def test_convert_integer(self):
        super(Postgres96ParserTests, self).test_convert_integer()

        # Convert Integer
        knob_unit_bytes = KnobUnitType()
        knob_unit_bytes.unit = 1
        knob_unit_time = KnobUnitType()
        knob_unit_time.unit = 2
        knob_unit_other = KnobUnitType()
        knob_unit_other.unit = 3

        self.assertEqual(self.test_dbms.convert_integer('5', knob_unit_other), 5)
        self.assertEqual(self.test_dbms.convert_integer('0', knob_unit_other), 0)
        self.assertEqual(self.test_dbms.convert_integer('0.0', knob_unit_other), 0)
        self.assertEqual(self.test_dbms.convert_integer('0.5', knob_unit_other), 0)

        self.assertEqual(self.test_dbms
                         .convert_integer('5kB', knob_unit_bytes), 5 * 1024)
        self.assertEqual(self.test_dbms
                         .convert_integer('4MB', knob_unit_bytes), 4 * 1024 ** 2)

        self.assertEqual(self.test_dbms.convert_integer('1d', knob_unit_time), 86400000)
        self.assertEqual(self.test_dbms
                         .convert_integer('20h', knob_unit_time), 72000000)
        self.assertEqual(self.test_dbms
                         .convert_integer('10min', knob_unit_time), 600000)
        self.assertEqual(self.test_dbms.convert_integer('1s', knob_unit_time), 1000)

        test_exceptions = [('A', knob_unit_other),
                           ('', knob_unit_other),
                           ('', knob_unit_bytes),
                           ('', knob_unit_time),
                           ('1S', knob_unit_time),
                           ('1mb', knob_unit_bytes)]

        for failure_case, knob_unit in test_exceptions:
            with self.assertRaises(Exception):
                self.test_dbms.convert_integer(failure_case, knob_unit)
    def test_format_integer(self):
        test_dbms = PostgresParser(2)

        knob_unit_bytes = KnobUnitType()
        knob_unit_bytes.unit = 1
        knob_unit_time = KnobUnitType()
        knob_unit_time.unit = 2
        knob_unit_other = KnobUnitType()
        knob_unit_other.unit = 3

        self.assertEqual(test_dbms.format_integer(5, knob_unit_other), 5)
        self.assertEqual(test_dbms.format_integer(0, knob_unit_other), 0)
        self.assertEqual(test_dbms.format_integer(-1, knob_unit_other), -1)

        self.assertEqual(test_dbms.format_integer(5120, knob_unit_bytes), '5kB')
        self.assertEqual(test_dbms.format_integer(4194304, knob_unit_bytes), '4MB')
        self.assertEqual(test_dbms.format_integer(4194500, knob_unit_bytes), '4MB')

        self.assertEqual(test_dbms.format_integer(86400000, knob_unit_time), '1d')
        self.assertEqual(test_dbms.format_integer(72000000, knob_unit_time), '20h')
        self.assertEqual(test_dbms.format_integer(600000, knob_unit_time), '10min')
        self.assertEqual(test_dbms.format_integer(1000, knob_unit_time), '1s')
        self.assertEqual(test_dbms.format_integer(500, knob_unit_time), '500ms')