Exemple #1
0
    def test_path_pointing_to_filename_record_twice(self):
        with temporary_path('custom.perf.yml'):

            with record(path='custom.perf.yml'):
                caches['default'].get('foo')

            with record(path='custom.perf.yml'):
                caches['default'].get('foo')
Exemple #2
0
    def test_path_pointing_to_filename_record_twice(self):
        with temporary_path("custom.perf.yml"):

            with record(path="custom.perf.yml"):
                caches["default"].get("foo")

            with record(path="custom.perf.yml"):
                caches["default"].get("foo")
    def test_custom_name_multiple_calls(self):
        with record(record_name='custom'):
            caches['default'].get('foo')

        with pytest.raises(AssertionError) as excinfo:
            with record(record_name='custom'):
                caches['default'].get('bar')

        assert 'Performance record did not match' in six.text_type(excinfo.value)
Exemple #4
0
    def test_custom_name_multiple_calls(self):
        with record(record_name="custom"):
            caches["default"].get("foo")

        with pytest.raises(AssertionError) as excinfo:
            with record(record_name="custom"):
                caches["default"].get("bar")

        assert "Performance record did not match" in str(excinfo.value)
Exemple #5
0
    def test_diff(self):
        with pretend_not_under_pytest():
            with record(record_name="test_diff"):
                caches["default"].get("foo")

            with pytest.raises(AssertionError) as excinfo:
                with record(record_name="test_diff"):
                    caches["default"].get("bar")

            msg = str(excinfo.value)
            assert "- cache|get: foo\n" in msg
            assert "+ cache|get: bar\n" in msg
Exemple #6
0
    def test_diff(self):
        with pretend_not_under_pytest():
            with record(record_name='test_diff'):
                caches['default'].get('foo')

            with pytest.raises(AssertionError) as excinfo:
                with record(record_name='test_diff'):
                    caches['default'].get('bar')

            msg = six.text_type(excinfo.value)
            assert '- cache|get: foo\n' in msg
            assert '+ cache|get: bar\n' in msg
Exemple #7
0
    def test_path_pointing_to_filename(self):
        with temporary_path("custom.perf.yml"):

            with record(path="custom.perf.yml"):
                caches["default"].get("foo")

            assert os.path.exists("custom.perf.yml")
Exemple #8
0
    def test_path_pointing_to_filename(self):
        with temporary_path('custom.perf.yml'):

            with record(path='custom.perf.yml'):
                caches['default'].get('foo')

            assert os.path.exists('custom.perf.yml')
def record_build_name(request):
    record_name = get_record_name(
        class_name=request.cls.__name__ if request.cls is not None else None,
        test_name=request.function.__name__,
    )
    path = get_perf_path(file_path=request.fspath.strpath)
    with record(record_name=record_name, path=path):
        yield
    def test_queryset_on_get(self):
        record_name = 'UpdateFormTestCase.test_queryset_on_get'
        if 'postgresql' in settings.DATABASES['default']['ENGINE']:
            record_name = '{}-pg'.format(record_name)

        with django_perf_rec.record(record_name=record_name, path='perfs/'):
            self.client.get(
                reverse('formidable:form_detail', args=[self.form.pk]))
Exemple #11
0
    def test_mode_once(self):
        temp_dir = os.path.join(FILE_DIR, "perf_files/")
        with temporary_path(temp_dir):

            with record(path="perf_files/api/"):
                caches["default"].get("foo")

            full_path = os.path.join(FILE_DIR, "perf_files", "api", "test_api.perf.yml")
            assert os.path.exists(full_path)
    def test_queryset_on_context_form_detail(self):
        record_name = 'UpdateFormTestCase.test_queryset_on_context_form_detail'
        if 'postgresql' in settings.DATABASES['default']['ENGINE']:
            record_name = '{}-pg'.format(record_name)

        session = self.client.session
        session['role'] = 'padawan'
        session.save()

        with django_perf_rec.record(record_name=record_name, path='perfs/'):
            self.client.get(
                reverse('formidable:context_form_detail', args=[self.form.pk]))
Exemple #13
0
    def test_queryset_without_role(self):
        class MyForm(FormidableForm):
            first_name = fields.CharField(default='foo')
            last_name = fields.CharField(default='bar')
            origin = fields.ChoiceField(choices=(('fr', 'France'),
                                                 ('en', 'England')))
            weapons = fields.ChoiceField(choices=(('gun', 'Gun'), ('sword',
                                                                   'Sword')))

        form = MyForm.to_formidable(label='test')

        with django_perf_rec.record(path='perfs/'):
            form.get_django_form_class(role='jedi')
Exemple #14
0
    def test_mode_all(self):
        temp_dir = os.path.join(FILE_DIR, "perf_files/")
        with temporary_path(temp_dir):

            with pytest.raises(AssertionError) as excinfo:

                with record(path="perf_files/api/"):
                    caches["default"].get("foo")

            assert "Original performance record did not exist" in str(excinfo.value)

            full_path = os.path.join(FILE_DIR, "perf_files", "api", "test_api.perf.yml")
            assert os.path.exists(full_path)
Exemple #15
0
    def test_path_pointing_to_dir(self):
        temp_dir = os.path.join(FILE_DIR, 'perf_files/')
        with temporary_path(temp_dir):

            with record(path='perf_files/'):
                caches['default'].get('foo')

            full_path = os.path.join(
                FILE_DIR,
                'perf_files',
                'test_api.perf.yml',
            )
            assert os.path.exists(full_path)
Exemple #16
0
    def test_single_cache_op_with_traceback(self):
        with pretend_not_under_pytest():
            with pytest.raises(AssertionError) as excinfo:

                def capture_traceback(operation):
                    return True

                with record(
                        record_name="RecordTests.test_single_cache_op",
                        capture_traceback=capture_traceback,
                ):
                    caches["default"].get("foo")

            msg = str(excinfo.value)
            assert "+ traceback:" in msg
            assert "in test_single_cache_op_with_traceback" in msg
    def test_mode_all(self):
        temp_dir = os.path.join(FILE_DIR, 'perf_files/')
        with temporary_path(temp_dir):

            with pytest.raises(AssertionError) as excinfo:

                with record(path='perf_files/api/'):
                    caches['default'].get('foo')

            assert 'Original performance record did not exist' in six.text_type(excinfo.value)

            full_path = os.path.join(
                FILE_DIR,
                'perf_files',
                'api',
                'test_api.perf.yml',
            )
            assert os.path.exists(full_path)
Exemple #18
0
    def test_single_db_query_with_traceback(self):
        with pretend_not_under_pytest():
            with pytest.raises(AssertionError) as excinfo:

                def capture_traceback(operation):
                    return True

                with record(
                        record_name="RecordTests.test_single_db_query",
                        capture_traceback=capture_traceback,
                ):
                    run_query("default", "SELECT 1337")

            msg = str(excinfo.value)
            assert (
                "Performance record did not match for RecordTests.test_single_db_query"
                in msg)
            assert "+ traceback:" in msg
            assert "in test_single_db_query_with_traceback" in msg
Exemple #19
0
 def test_delete_on_cascade_called_twice(self):
     arthur = Author.objects.create(name="Arthur", age=42)
     with record():
         arthur.delete()
Exemple #20
0
 def test_project_directory_listing(self):
     with django_perf_rec.record():
         self.client.get('/en/projects/', follow=True)
Exemple #21
0
 def test_single_db_query(self):
     with record():
         run_query("default", "SELECT 1337")
def record_auto_name_with_request(request):
    with record():
        yield
Exemple #23
0
    def test_multiple_calls_in_same_function_are_different_records(self):
        with record():
            caches["default"].get("foo")

        with record():
            caches["default"].get("bar")
def record_auto_name():
    with record():
        yield
Exemple #25
0
 def test_single_db_query_model_with_columns(self):
     with record():
         list(Author.objects.all())
Exemple #26
0
 def test_multiple_cache_ops(self):
     with record():
         caches["default"].set("foo", "bar")
         caches["second"].get_many(["foo", "bar"])
         caches["default"].delete("foo")
Exemple #27
0
 def test_single_cache_op(self):
     with record():
         caches["default"].get("foo")
Exemple #28
0
 def test_non_deterministic_Q_query(self):
     with record():
         list(Author.objects.filter(Q(name="foo", age=1)))
Exemple #29
0
 def test_non_deterministic_QuerySet_extra(self):
     with record():
         list(Author.objects.extra(select={"x": "1", "y": "1"}))
Exemple #30
0
 def test_non_deterministic_QuerySet_annotate(self):
     with record():
         list(Author.objects.annotate(x=Upper("name"), y=Upper("name")))
Exemple #31
0
 def test_multiple_db_queries(self):
     with record():
         run_query("default", "SELECT 1337")
         run_query("default", "SELECT 4949")