Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codespeed/fixtures/jruby.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions codespeed/fixtures/testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
"fields": {
"name": "float",
"parent": null,
"source": "legacy",
"source": "classic",
"data_type": "U",
"description": "",
"units_title": "Time",
Expand All @@ -234,7 +234,7 @@
"fields": {
"name": "int",
"parent": null,
"source": "legacy",
"source": "classic",
"data_type": "U",
"description": "",
"units_title": "Time",
Expand Down
4 changes: 2 additions & 2 deletions codespeed/fixtures/timeline_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
"fields": {
"parent": null,
"name": "float",
"source": "legacy",
"source": "classic",
"default_on_comparison": true,
"units_title": "Time",
"units": "seconds",
Expand All @@ -224,7 +224,7 @@
"fields": {
"parent": null,
"name": "int",
"source": "legacy",
"source": "classic",
"default_on_comparison": true,
"units_title": "Time",
"units": "seconds",
Expand Down
29 changes: 29 additions & 0 deletions codespeed/migrations/0009_rename_legacy_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.db import migrations, models


def legacy_to_classic(apps, schema_editor):
apps.get_model('codespeed', 'Benchmark').objects.filter(
source='legacy').update(source='classic')


def _classic_to_legacy(apps, schema_editor):
apps.get_model('codespeed', 'Benchmark').objects.filter(
source='classic').update(source='legacy')


class Migration(migrations.Migration):

dependencies = [
('codespeed', '0008_alter_revision_tag'),
]

operations = [
migrations.AlterField(
model_name='benchmark',
name='source',
field=models.CharField(
choices=[('classic', 'classic'), ('pyperformance', 'PyPerformance')],
default='classic', max_length=14),
),
migrations.RunPython(legacy_to_classic, _classic_to_legacy),
]
10 changes: 8 additions & 2 deletions codespeed/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ def __str__(self):

class Benchmark(models.Model):
S_TYPES = (
('legacy', 'Legacy'),
('classic', 'classic'),
('pyperformance', 'PyPerformance'),
)
# Former source names, still accepted from uploaders and old permalinks
SOURCE_ALIASES = {'legacy': 'classic'}
D_TYPES = (
('U', 'Mean'),
('M', 'Median'),
Expand All @@ -189,7 +191,7 @@ class Benchmark(models.Model):
'self', on_delete=models.CASCADE, verbose_name="parent",
help_text="allows to group benchmarks in hierarchies",
null=True, blank=True, default=None)
source = models.CharField(max_length=14, choices=S_TYPES, default='legacy')
source = models.CharField(max_length=14, choices=S_TYPES, default='classic')
data_type = models.CharField(max_length=1, choices=D_TYPES, default='U')
description = models.CharField(max_length=300, blank=True)
units_title = models.CharField(max_length=30, default='Time')
Expand All @@ -198,6 +200,10 @@ class Benchmark(models.Model):
default_on_comparison = models.BooleanField(
"Default on comparison page", default=True)

@classmethod
def normalize_source(cls, source):
return cls.SOURCE_ALIASES.get(source, source)

class Meta:
unique_together = (('name', 'source'),)

Expand Down
8 changes: 5 additions & 3 deletions codespeed/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def validate_result(item):
return 'Value for key "' + key + '" empty in request', error

# 'source' is optional: uploaders that predate it (pyperformance on
# speed.python.org) get the 'legacy' default.
if 'source' in item and item['source'] not in dict(Benchmark.S_TYPES):
# speed.python.org) get the 'classic' default.
if ('source' in item and
Benchmark.normalize_source(item['source']) not in dict(Benchmark.S_TYPES)):
return 'Invalid source "%s"' % item['source'], error

try:
Expand Down Expand Up @@ -73,7 +74,8 @@ def save_result(data, update_repo=True):
branch, created = Branch.objects.get_or_create(name=data["branch"],
project=p)
b, created = Benchmark.objects.get_or_create(
name=data["benchmark"], source=data.get("source", "legacy"))
name=data["benchmark"],
source=Benchmark.normalize_source(data.get("source", "classic")))

if created:
if "description" in data:
Expand Down
4 changes: 2 additions & 2 deletions codespeed/static/js/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,8 @@ function setValuesOfInputFields(params) {
var benchmark = valueOrDefault(params.ben, defaults.benchmark);
var benchRadio = $("input:radio[name='benchmark']").filter("[value='" + benchmark + "']");
if (benchRadio.length === 0 && benchmark !== "grid" && benchmark !== "show_none") {
// backwards compat: a bare '<name>' permalink defaults to the legacy suite
benchmark = benchmark + ".legacy";
// backwards compat: a bare '<name>' permalink defaults to the classic
benchmark = benchmark + ".classic";
benchRadio = $("input:radio[name='benchmark']").filter("[value='" + benchmark + "']");
}
benchRadio.prop('checked', true);
Expand Down
4 changes: 2 additions & 2 deletions codespeed/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def test_changes_table_row_has_bench_source(self):
s1 = self.make_result(15)
rep = self.make_report(s1)
tablelist = rep.get_changes_table(force_save=True)
self.assertEqual(tablelist[0]['rows'][0]['bench_source'], 'legacy')
self.assertEqual(tablelist[0]['rows'][0]['bench_source'], 'classic')

def test_multiple_quantities(self):
b1 = self.make_bench('b1', quantity='Space', units='bytes')
Expand All @@ -217,7 +217,7 @@ def test_stale_tablecache_is_rebuilt(self):
Report.objects.filter(pk=report.pk).update(_tablecache=json.dumps(cached))

table = Report.objects.get(pk=report.pk).get_changes_table()
self.assertEqual(table[0]['rows'][0]['bench_source'], 'legacy')
self.assertEqual(table[0]['rows'][0]['bench_source'], 'classic')
self.assertIn('"bench_source"',
Report.objects.get(pk=report.pk)._tablecache)

Expand Down
60 changes: 38 additions & 22 deletions codespeed/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUp(self):
'benchmark': 'float',
'environment': 'Dual Core',
'result_value': 456,
'source': 'legacy',
'source': 'classic',
}

def test_add_correct_result(self):
Expand All @@ -44,7 +44,7 @@ def test_add_correct_result(self):
# Check that the data was correctly saved
e = Environment.objects.get(name='Dual Core')
b = Benchmark.objects.get(name='float')
self.assertEqual(b.source, "legacy")
self.assertEqual(b.source, "classic")
self.assertEqual(b.units, "seconds")
self.assertEqual(b.lessisbetter, True)
p = Project.objects.get(name='MyProject')
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_bad_environment(self):
def test_empty_argument(self):
"""Should respond 400 when a POST request has an empty argument"""
for key in self.data:
if key == 'source': # optional, defaults to 'legacy'
if key == 'source': # optional, defaults to 'classic'
continue
backup = self.data[key]
self.data[key] = ""
Expand All @@ -120,7 +120,7 @@ def test_empty_argument(self):
def test_missing_argument(self):
"""Should respond 400 when a POST request is missing an argument"""
for key in list(self.data):
if key == 'source': # optional, defaults to 'legacy'
if key == 'source': # optional, defaults to 'classic'
continue
backup = self.data[key]
del self.data[key]
Expand Down Expand Up @@ -196,14 +196,23 @@ def test_source_set_on_new_benchmark(self):
b = Benchmark.objects.get(name='newbench')
self.assertEqual(b.source, 'pyperformance')

def test_source_defaults_to_legacy(self):
"""A payload without a source creates a 'legacy' Benchmark"""
def test_source_defaults_to_classic(self):
"""A payload without a source creates a 'classic' Benchmark"""
modified_data = copy.deepcopy(self.data)
del modified_data['source']
response = self.client.post(self.path, modified_data)
self.assertEqual(response.status_code, 202)
b = Benchmark.objects.get(name='float')
self.assertEqual(b.source, 'legacy')
self.assertEqual(b.source, 'classic')

def test_former_source_name_is_accepted(self):
"""Uploaders still sending the pre-rename source name are mapped"""
modified_data = copy.deepcopy(self.data)
modified_data['source'] = 'legacy'
response = self.client.post(self.path, modified_data)
self.assertEqual(response.status_code, 202)
b = Benchmark.objects.get(name='float')
self.assertEqual(b.source, 'classic')

def test_same_name_different_source_are_distinct(self):
"""The same name in a different suite is a separate Benchmark"""
Expand All @@ -212,10 +221,10 @@ def test_same_name_different_source_are_distinct(self):
modified_data['source'] = 'pyperformance'
self.client.post(self.path, modified_data)

legacy = Benchmark.objects.get(name='float', source='legacy')
suite2010 = Benchmark.objects.get(name='float', source='classic')
pyperf = Benchmark.objects.get(name='float', source='pyperformance')
self.assertNotEqual(legacy.pk, pyperf.pk)
self.assertEqual(legacy.results.count(), 1)
self.assertNotEqual(suite2010.pk, pyperf.pk)
self.assertEqual(suite2010.results.count(), 1)
self.assertEqual(pyperf.results.count(), 1)

def test_invalid_source_rejected(self):
Expand Down Expand Up @@ -255,31 +264,31 @@ def setUp(self):
'benchmark': 'Richards',
'environment': 'bigdog',
'result_value': 456,
'source': 'legacy'},
'source': 'classic'},
{'commitid': '456',
'project': 'pypy',
'branch': 'default',
'executable': 'pypy-c',
'benchmark': 'Richards',
'environment': 'bigdog',
'result_value': 457,
'source': 'legacy'},
'source': 'classic'},
{'commitid': '456',
'project': 'pypy',
'branch': 'default',
'executable': 'pypy-c',
'benchmark': 'Richards2',
'environment': 'bigdog',
'result_value': 34,
'source': 'legacy'},
'source': 'classic'},
{'commitid': '789',
'project': 'pypy',
'branch': 'default',
'executable': 'pypy-c',
'benchmark': 'Richards',
'environment': 'bigdog',
'result_value': 458,
'source': 'legacy'},
'source': 'classic'},
]

def test_get_returns_405(self):
Expand All @@ -301,7 +310,7 @@ def test_add_correct_results(self):
# Check that the data was correctly saved
e = Environment.objects.get(name='bigdog')
b = Benchmark.objects.get(name='Richards')
self.assertEqual(b.source, "legacy")
self.assertEqual(b.source, "classic")
self.assertEqual(b.units, "seconds")
self.assertEqual(b.lessisbetter, True)
p = Project.objects.get(name='pypy')
Expand Down Expand Up @@ -356,7 +365,7 @@ def test_empty_argument(self):
'''Should return 400 when making a request with an empty argument'''
data = self.data[1]
for key in data:
if key == 'source': # optional, defaults to 'legacy'
if key == 'source': # optional, defaults to 'classic'
continue
backup = data[key]
data[key] = ""
Expand All @@ -372,7 +381,7 @@ def test_missing_argument(self):
'''Should return 400 when making a request with a missing argument'''
data = self.data[2]
for key in list(data):
if key == 'source': # optional, defaults to 'legacy'
if key == 'source': # optional, defaults to 'classic'
continue
backup = data[key]
del data[key]
Expand Down Expand Up @@ -523,19 +532,19 @@ def test_no_source_fold_with_one_source(self):
response = self.client.get(reverse('timeline'))
self.assertEqual(response.status_code, 200)
self.assertIsNone(response.context['grid_revisions'])
self.assertNotContains(response, 'class="togglefold">Legacy</a>')
self.assertNotContains(response, 'class="togglefold">classic</a>')
self.assertContains(response, 'grid_revisions: null')

def test_source_fold_with_several_sources(self):
Benchmark.objects.create(name='float', source='pyperformance')
# Suites are rendered folded, except the one of the selected benchmark
response = self.client.get(reverse('timeline'))
self.assertContains(response, 'class="togglefold folded">Legacy</a>')
self.assertContains(response, 'class="togglefold folded">classic</a>')
self.assertContains(
response, 'class="togglefold folded">PyPerformance</a>')
response = self.client.get(
reverse('timeline'), {'ben': 'float.pyperformance'})
self.assertContains(response, 'class="togglefold folded">Legacy</a>')
self.assertContains(response, 'class="togglefold folded">classic</a>')
self.assertContains(response, 'class="togglefold">PyPerformance</a>')

@override_settings(TIMELINE_GRID_REVISIONS=25)
Expand Down Expand Up @@ -614,11 +623,18 @@ def test_groups_with_nothing_checked_are_rendered_folded(self):
self.assertContains(
response, 'class="togglefold folded">PyPerformance</a>')

def test_former_source_name_in_ben_param(self):
"""Permalinks from before the rename still say ben=legacy"""
from codespeed.views import _parse_ben_param
Benchmark.objects.create(name='float', source='pyperformance')
self.assertEqual(
{b.source for b in _parse_ben_param('legacy')}, {'classic'})

def test_benchmarks_grouped_by_source_with_several_sources(self):
Benchmark.objects.create(name='float', source='pyperformance')
response = self.client.get(self.path)
self.assertEqual(list(response.context['benchmarks']),
['Legacy', 'PyPerformance'])
['classic', 'PyPerformance'])


@override_settings(ALLOW_ANONYMOUS_POST=True)
Expand All @@ -634,7 +650,7 @@ def setUp(self):
'benchmark': 'float',
'environment': 'Dual Core',
'result_value': 200,
'source': 'legacy',
'source': 'classic',
}
resp = self.client.post(reverse('add-result'),
self.data)
Expand Down
26 changes: 16 additions & 10 deletions codespeed/tests/test_views_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,18 @@ def test_full_ident_with_valid_source_suffix(self):
parse_benchmark_ident('mybenchmark.pyperformance'),
('mybenchmark', 'pyperformance'))
self.assertEqual(
parse_benchmark_ident('mybenchmark.legacy'),
('mybenchmark', 'legacy'))
parse_benchmark_ident('mybenchmark.classic'),
('mybenchmark', 'classic'))

def test_bare_legacy_name_without_dot(self):
Benchmark.objects.create(name='ai', source='legacy')
self.assertEqual(parse_benchmark_ident('ai'), ('ai', 'legacy'))
def test_former_source_name_is_an_alias(self):
# Permalinks from before the rename still say '.legacy'
self.assertEqual(
parse_benchmark_ident('mybenchmark.' + 'legacy'),
('mybenchmark', 'classic'))

def test_bare_classic_name_without_dot(self):
Benchmark.objects.create(name='ai', source='classic')
self.assertEqual(parse_benchmark_ident('ai'), ('ai', 'classic'))

def test_bare_pyperformance_name_containing_dot(self):
# Regression test: this name contains a dot but isn't a valid
Expand All @@ -310,16 +316,16 @@ def test_bare_pyperformance_name_containing_dot(self):
parse_benchmark_ident('base16_large.pyperf'),
('base16_large.pyperf', 'pyperformance'))

def test_unknown_name_falls_back_to_legacy(self):
def test_unknown_name_falls_back_to_classic(self):
self.assertEqual(
parse_benchmark_ident('nosuchbenchmark'),
('nosuchbenchmark', 'legacy'))
('nosuchbenchmark', 'classic'))

def test_ambiguous_name_across_sources_falls_back_to_legacy(self):
Benchmark.objects.create(name='float', source='legacy')
def test_ambiguous_name_across_sources_falls_back_to_classic(self):
Benchmark.objects.create(name='float', source='classic')
Benchmark.objects.create(name='float', source='pyperformance')
self.assertEqual(
parse_benchmark_ident('float'), ('float', 'legacy'))
parse_benchmark_ident('float'), ('float', 'classic'))


class TestGetDefaultEnvironment(TestCase):
Expand Down
Loading