Python testtools.matchers.GreaterThan() Examples

The following are 13 code examples of testtools.matchers.GreaterThan(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module testtools.matchers , or try the search function .
Example #1
Source File: test_service.py    From designate with Apache License 2.0 6 votes vote down vote up
def test_delete_recordset(self):
        zone = self.create_zone()
        original_serial = zone.serial

        # Create a recordset
        recordset = self.create_recordset(zone)

        # Delete the recordset
        self.central_service.delete_recordset(
            self.admin_context, zone['id'], recordset['id'])

        # Fetch the recordset again, ensuring an exception is raised
        exc = self.assertRaises(rpc_dispatcher.ExpectedException,
                                self.central_service.get_recordset,
                                self.admin_context, zone['id'],
                                recordset['id'])

        self.assertEqual(exceptions.RecordSetNotFound, exc.exc_info[0])

        # Fetch the zone again to verify serial number increased
        updated_zone = self.central_service.get_zone(self.admin_context,
                                                     zone.id)
        new_serial = updated_zone.serial
        self.assertThat(new_serial, GreaterThan(original_serial)) 
Example #2
Source File: test_callback.py    From stevedore with Apache License 2.0 6 votes vote down vote up
def test_extension_failure_custom_callback(self):
        errors = []

        def failure_callback(manager, entrypoint, error):
            errors.append((manager, entrypoint, error))

        em = extension.ExtensionManager('stevedore.test.extension',
                                        invoke_on_load=True,
                                        on_load_failure_callback=
                                        failure_callback)
        extensions = list(em.extensions)
        self.assertTrue(len(extensions), GreaterThan(0))
        self.assertEqual(len(errors), 2)
        for manager, entrypoint, error in errors:
            self.assertIs(manager, em)
            self.assertIsInstance(error, (IOError, ImportError)) 
Example #3
Source File: test_callback.py    From bazarr with GNU General Public License v3.0 6 votes vote down vote up
def test_extension_failure_custom_callback(self):
        errors = []

        def failure_callback(manager, entrypoint, error):
            errors.append((manager, entrypoint, error))

        em = extension.ExtensionManager('stevedore.test.extension',
                                        invoke_on_load=True,
                                        on_load_failure_callback=
                                        failure_callback)
        extensions = list(em.extensions)
        self.assertThat(len(extensions), GreaterThan(0))
        self.assertEqual(len(errors), 2)
        for manager, entrypoint, error in errors:
            self.assertIs(manager, em)
            self.assertIsInstance(error, (IOError, ImportError)) 
Example #4
Source File: test_version.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def test_ordering(self):
        ordered_versions = [
            "1.2.3.dev6",
            "1.2.3.dev7",
            "1.2.3.a4.dev12",
            "1.2.3.a4.dev13",
            "1.2.3.a4",
            "1.2.3.a5.dev1",
            "1.2.3.a5",
            "1.2.3.b3.dev1",
            "1.2.3.b3",
            "1.2.3.rc2.dev1",
            "1.2.3.rc2",
            "1.2.3.rc3.dev1",
            "1.2.3",
            "1.2.4",
            "1.3.3",
            "2.2.3",
        ]
        for v in ordered_versions:
            sv = version.SemanticVersion.from_pip_string(v)
            self.expectThat(sv, matchers.Equals(sv))
        for left, right in itertools.combinations(ordered_versions, 2):
            l_pos = ordered_versions.index(left)
            r_pos = ordered_versions.index(right)
            if l_pos < r_pos:
                m1 = matchers.LessThan
                m2 = matchers.GreaterThan
            else:
                m1 = matchers.GreaterThan
                m2 = matchers.LessThan
            left_sv = version.SemanticVersion.from_pip_string(left)
            right_sv = version.SemanticVersion.from_pip_string(right)
            self.expectThat(left_sv, m1(right_sv))
            self.expectThat(right_sv, m2(left_sv)) 
Example #5
Source File: test_service.py    From designate with Apache License 2.0 5 votes vote down vote up
def test_create_recordset_with_records(self):
        zone = self.create_zone()
        original_serial = zone.serial

        # Create the Object
        recordset = objects.RecordSet(
            name='www.%s' % zone.name,
            type='A',
            records=objects.RecordList(objects=[
                objects.Record(data='192.3.3.15'),
                objects.Record(data='192.3.3.16'),
            ])
        )

        # Persist the Object
        recordset = self.central_service.create_recordset(
            self.admin_context, zone.id, recordset=recordset)

        # Get updated serial number
        updated_zone = self.central_service.get_zone(self.admin_context,
                                                     zone.id)
        new_serial = updated_zone.serial

        # Ensure all values have been set correctly
        self.assertIsNotNone(recordset.records)
        self.assertEqual(2, len(recordset.records))
        self.assertIsNotNone(recordset.records[0].id)
        self.assertIsNotNone(recordset.records[1].id)
        self.assertThat(new_serial, GreaterThan(original_serial)) 
Example #6
Source File: test_service.py    From designate with Apache License 2.0 5 votes vote down vote up
def test_update_recordset(self):
        # Create a zone
        zone = self.create_zone()
        original_serial = zone.serial

        # Create a recordset
        recordset = self.create_recordset(zone)

        # Update the recordset
        recordset.ttl = 1800

        # Perform the update
        self.central_service.update_recordset(self.admin_context, recordset)

        # Get zone again to verify that serial number was updated
        updated_zone = self.central_service.get_zone(self.admin_context,
                                                     zone.id)
        new_serial = updated_zone.serial

        # Fetch the resource again
        recordset = self.central_service.get_recordset(
            self.admin_context, recordset.zone_id, recordset.id)

        # Ensure the new value took
        self.assertEqual(1800, recordset.ttl)
        self.assertThat(new_serial, GreaterThan(original_serial)) 
Example #7
Source File: test_service.py    From designate with Apache License 2.0 5 votes vote down vote up
def test_update_recordset_with_record_delete(self):
        # Create a zone
        zone = self.create_zone()
        original_serial = zone.serial

        # Create a recordset and two records
        recordset = self.create_recordset(zone)
        self.create_record(zone, recordset)
        self.create_record(zone, recordset, fixture=1)

        # Append two new Records
        recordset.records.append(objects.Record(data='192.0.2.1'))
        recordset.records.append(objects.Record(data='192.0.2.2'))

        # Remove one of the Records
        recordset.records.pop(0)

        # Perform the update
        self.central_service.update_recordset(self.admin_context, recordset)

        # Fetch the RecordSet again
        recordset = self.central_service.get_recordset(
            self.admin_context, zone.id, recordset.id)

        # Fetch the Zone again
        updated_zone = self.central_service.get_zone(self.admin_context,
                                                     zone.id)
        new_serial = updated_zone.serial

        # Ensure two Records are attached to the RecordSet correctly
        self.assertEqual(1, len(recordset.records))
        self.assertIsNotNone(recordset.records[0].id)
        self.assertThat(new_serial, GreaterThan(original_serial)) 
Example #8
Source File: test_builtin_workflows.py    From cloudify-plugins-common with Apache License 2.0 5 votes vote down vote up
def _dep_order_tests_helper(self, cfy_local, node_ids_param,
                                ordered_node_ids_of_instances,
                                indices_pairs_for_time_diff_assertions):
        params = self._get_params(
            op='cloudify.interfaces.lifecycle.start',
            node_ids=node_ids_param,
            run_by_dep=True)
        cfy_local.execute('execute_operation', params, task_thread_pool_size=4)

        instances_and_visit_times = sorted(
            ((inst, inst.runtime_properties['visit_time']) for inst in
             cfy_local.storage.get_node_instances() if 'visit_time' in
             inst.runtime_properties),
            key=lambda inst_and_time: inst_and_time[1])

        self.assertEqual(ordered_node_ids_of_instances,
                         [inst_and_time[0].node_id for inst_and_time in
                          instances_and_visit_times])

        # asserting time difference between the operation execution for the
        # different nodes. this way if something breaks and the tasks aren't
        # dependent on one another, there's a better chance we'll catch
        # it, since even if the order of the visits happens to be correct,
        # it's less likely there'll be a significant time difference between
        # the visits
        def assert_time_difference(earlier_inst_index, later_inst_index):
            td = instances_and_visit_times[later_inst_index][1] - \
                instances_and_visit_times[earlier_inst_index][1]
            self.assertThat(td, MatchesAny(Equals(1), GreaterThan(1)))

        for index1, index2 in indices_pairs_for_time_diff_assertions:
            assert_time_difference(index1, index2) 
Example #9
Source File: test.py    From taskflow with Apache License 2.0 5 votes vote down vote up
def assertGreater(self, first, second):
        matcher = matchers.GreaterThan(first)
        self.assertThat(second, matcher) 
Example #10
Source File: test_rdns.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_set_current_entry_updates_updated_time(self):
        region = factory.make_RegionController()
        hostname = factory.make_hostname()
        ip = factory.make_ip_address()
        yesterday = datetime.now() - timedelta(days=1)
        factory.make_RDNS(ip, hostname, region, updated=yesterday)
        # Nothing changed, so expect that only the last updated time changed.
        RDNS.objects.set_current_entry(ip, [hostname], region)
        result = RDNS.objects.first()
        self.assertThat(result.updated, GreaterThan(yesterday)) 
Example #11
Source File: test_timeutils.py    From oslo.utils with Apache License 2.0 5 votes vote down vote up
def test_elapsed(self, mock_now):
        mock_now.side_effect = monotonic_iter(incr=0.2)
        watch = timeutils.StopWatch()
        watch.start()
        matcher = matchers.GreaterThan(0.19)
        self.assertThat(watch.elapsed(), matcher) 
Example #12
Source File: test_timeutils.py    From oslo.utils with Apache License 2.0 5 votes vote down vote up
def test_context_manager(self, mock_now):
        mock_now.side_effect = monotonic_iter()
        with timeutils.StopWatch() as watch:
            pass
        matcher = matchers.GreaterThan(0.04)
        self.assertThat(watch.elapsed(), matcher) 
Example #13
Source File: test_version.py    From keras-lambda with MIT License 5 votes vote down vote up
def test_ordering(self):
        ordered_versions = [
            "1.2.3.dev6",
            "1.2.3.dev7",
            "1.2.3.a4.dev12",
            "1.2.3.a4.dev13",
            "1.2.3.a4",
            "1.2.3.a5.dev1",
            "1.2.3.a5",
            "1.2.3.b3.dev1",
            "1.2.3.b3",
            "1.2.3.rc2.dev1",
            "1.2.3.rc2",
            "1.2.3.rc3.dev1",
            "1.2.3",
            "1.2.4",
            "1.3.3",
            "2.2.3",
        ]
        for v in ordered_versions:
            sv = version.SemanticVersion.from_pip_string(v)
            self.expectThat(sv, matchers.Equals(sv))
        for left, right in itertools.combinations(ordered_versions, 2):
            l_pos = ordered_versions.index(left)
            r_pos = ordered_versions.index(right)
            if l_pos < r_pos:
                m1 = matchers.LessThan
                m2 = matchers.GreaterThan
            else:
                m1 = matchers.GreaterThan
                m2 = matchers.LessThan
            left_sv = version.SemanticVersion.from_pip_string(left)
            right_sv = version.SemanticVersion.from_pip_string(right)
            self.expectThat(left_sv, m1(right_sv))
            self.expectThat(right_sv, m2(left_sv))