当前位置: 首页>>代码示例>>Python>>正文


Python models.Environment类代码示例

本文整理汇总了Python中codespeed.models.Environment的典型用法代码示例。如果您正苦于以下问题:Python Environment类的具体用法?Python Environment怎么用?Python Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Environment类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

 def setUp(self):
     self.data1 = {
         'commitid': '2',
         'branch': 'default', # Always use default for trunk/master/tip
         'project': 'MyProject',
         'executable': 'myexe O3 64bits',
         'benchmark': 'float',
         'environment': "Bulldozer",
         'result_value': 4000,
         }
     self.data_optional = {
         'std_dev': 0.2,
         'val_min': 2.23,
         'val_max': 3.42,
         'date': datetime.now().strftime(self.DATETIME_FORMAT),
         }
     project_data = dict(
         name="PyPy",
         repo_type="M",
         repo_path="ssh://[email protected]/pypy/pypy",
         repo_user="fridolin",
         repo_pass="secret",
         )
     self.project = Project(**project_data)
     self.project.save()
     self.env1 = Environment(name='Bulldozer')
     self.env1.save()
开发者ID:iffy,项目名称:codespeed,代码行数:27,代码来源:tests_api.py

示例2: setUp

 def setUp(self):
     self.path = reverse('codespeed.views.addresult')
     self.client = Client()
     self.e = Environment(name='bigdog', cpu='Core 2 Duo 8200')
     self.e.save()
     temp = datetime.today()
     self.cdate = datetime(temp.year, temp.month, temp.day, temp.hour, temp.minute, temp.second)
     self.data = {
             'commitid': '23232',
             'project': 'pypy',
             'executable_name': 'pypy-c',
             'benchmark': 'Richards',
             'environment': 'bigdog',
             'result_value': 456,
     }        
开发者ID:camillobruni,项目名称:codespeed,代码行数:15,代码来源:tests.py

示例3: setUp

 def setUp(self):
     self.path = reverse("codespeed.views.add_result")
     self.client = Client()
     self.e = Environment(name="Dual Core", cpu="Core 2 Duo 8200")
     self.e.save()
     temp = datetime.today()
     self.cdate = datetime(temp.year, temp.month, temp.day, temp.hour, temp.minute, temp.second)
     self.data = {
         "commitid": "23",
         "branch": "default",
         "project": "MyProject",
         "executable": "myexe O3 64bits",
         "benchmark": "float",
         "environment": "Dual Core",
         "result_value": 456,
     }
开发者ID:AlekSi,项目名称:codespeed,代码行数:16,代码来源:tests.py

示例4: setUp

 def setUp(self):
     self.path = reverse('codespeed.views.add_result')
     self.e = Environment(name='Dual Core', cpu='Core 2 Duo 8200')
     self.e.save()
     temp = datetime.today()
     self.cdate = datetime(
         temp.year, temp.month, temp.day, temp.hour, temp.minute, temp.second)
     self.data = {
         'commitid': '23',
         'branch': 'default',
         'project': 'MyProject',
         'executable': 'myexe O3 64bits',
         'benchmark': 'float',
         'environment': 'Dual Core',
         'result_value': 456,
     }
开发者ID:cykl,项目名称:codespeed,代码行数:16,代码来源:tests.py

示例5: setUp

 def setUp(self):
     self.env1_data = dict(
         name="env1",
         cpu="cpu1",
         memory="48kB",
         os="ZX Spectrum OS",
         kernel="2.6.32"
     )
     self.env1 = Environment(**self.env1_data)
     self.env1.save()
     self.env2_data = dict(
         name="env2",
         cpu="z80",
         memory="64kB",
         os="ZX Spectrum OS",
         kernel="2.6.32"
     )
     self.client = Client()
     super(EnvironmentTest, self).setUp()
开发者ID:Kami,项目名称:codespeed,代码行数:19,代码来源:tests_api.py

示例6: setUp

    def setUp(self):
        self.path = reverse('add-json-results')
        self.e = Environment(name='bigdog', cpu='Core 2 Duo 8200')
        self.e.save()
        temp = datetime.today()
        self.cdate = datetime(
            temp.year, temp.month, temp.day, temp.hour, temp.minute,
            temp.second)

        self.data = [
            {'commitid': '123',
             'project': 'pypy',
             'branch': 'default',
             'executable': 'pypy-c',
             'benchmark': 'Richards',
             'environment': 'bigdog',
             'result_value': 456},
            {'commitid': '456',
             'project': 'pypy',
             'branch': 'default',
             'executable': 'pypy-c',
             'benchmark': 'Richards',
             'environment': 'bigdog',
             'result_value': 457},
            {'commitid': '456',
             'project': 'pypy',
             'branch': 'default',
             'executable': 'pypy-c',
             'benchmark': 'Richards2',
             'environment': 'bigdog',
             'result_value': 34},
            {'commitid': '789',
             'project': 'pypy',
             'branch': 'default',
             'executable': 'pypy-c',
             'benchmark': 'Richards',
             'environment': 'bigdog',
             'result_value': 458},
        ]
开发者ID:pombredanne,项目名称:codespeed,代码行数:39,代码来源:test_views.py

示例7: AddResultTest

class AddResultTest(TestCase):
    def setUp(self):
        self.path = reverse('codespeed.views.addresult')
        self.client = Client()
        self.e = Environment(name='bigdog', cpu='Core 2 Duo 8200')
        self.e.save()
        temp = datetime.today()
        self.cdate = datetime(temp.year, temp.month, temp.day, temp.hour, temp.minute, temp.second)
        self.data = {
                'commitid': '23232',
                'project': 'pypy',
                'executable_name': 'pypy-c',
                'benchmark': 'Richards',
                'environment': 'bigdog',
                'result_value': 456,
        }        
    def test_add_default_result(self):
        """
        Add result data using default options
        """
        response = self.client.post(self.path, self.data)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(response.content, "Result data saved succesfully")
        e = Environment.objects.get(name='bigdog')        
        b = Benchmark.objects.get(name='Richards')
        self.assertEquals(b.benchmark_type, "C")
        self.assertEquals(b.units, "seconds")
        self.assertEquals(b.lessisbetter, True)
        p = Project.objects.get(name='pypy')
        r = Revision.objects.get(commitid='23232', project=p)
        i = Executable.objects.get(name='pypy-c', coptions='')
        res = Result.objects.get(
            revision=r,
            executable=i,
            benchmark=b,
            environment=e
        )
        self.assertTrue(res.value, 456)
        resdate = res.date.strftime("%Y%m%dT%H%M%S")
        selfdate = self.cdate.strftime("%Y%m%dT%H%M%S")
        self.assertTrue(resdate, selfdate)
        
    def test_add_non_default_result(self):
        """
        Add result data with non-default options
        """
        modified_data = copy.deepcopy(self.data)
        modified_data['executable_coptions'] = 'gc=Böhm'
        modified_data['benchmark_type'] = "O"
        modified_data['units'] = "fps"
        modified_data['lessisbetter'] = False
        modified_data['result_date'] = self.cdate
        modified_data['std_dev'] = 1.11111
        modified_data['max'] = 2
        modified_data['min'] = 1.0
        response = self.client.post(self.path, modified_data)
        self.assertEquals(response.status_code, 200)
        self.assertEquals(response.content, "Result data saved succesfully")
        e = Environment.objects.get(name='bigdog')    
        p = Project.objects.get(name='pypy')
        r = Revision.objects.get(commitid='23232', project=p)
        self.assertEquals(r.date, self.cdate)
        i = Executable.objects.get(name='pypy-c', coptions='gc=Böhm')
        b = Benchmark.objects.get(name='Richards')
        res = Result.objects.get(
            revision=r,
            executable=i,
            benchmark=b,
            environment=e
        )
        self.assertEquals(res.std_dev, 1.11111)
        self.assertEquals(res.val_max, 2)
        self.assertEquals(res.val_min, 1)

    def test_bad_environment(self):
        """
        Add result associated with non-existing environment
        """
        bad_name = 'bigdog1'
        self.data['environment'] = bad_name
        response = self.client.post(self.path, self.data)
        self.assertEquals(response.status_code, 404)
        self.assertEquals(response.content, "Environment " + bad_name + " not found")
        self.data['environment'] = 'bigdog'
    
    def test_empty_argument(self):
        """
        Make POST request with an empty argument.
        """
        for key in self.data:
            backup = self.data[key]
            self.data[key] = ""
            response = self.client.post(self.path, self.data)
            self.assertEquals(response.status_code, 400)
            self.assertEquals(response.content, 'Key "' + key + '" empty in request')
            self.data[key] = backup
    
    def test_missing_argument(self):
        """
        Make POST request with a missing argument.
#.........这里部分代码省略.........
开发者ID:camillobruni,项目名称:codespeed,代码行数:101,代码来源:tests.py

示例8: TestAddJSONResults

class TestAddJSONResults(TestCase):

    def setUp(self):
        self.path = reverse('codespeed.views.add_json_results')
        self.e = Environment(name='bigdog', cpu='Core 2 Duo 8200')
        self.e.save()
        temp = datetime.today()
        self.cdate = datetime(
            temp.year, temp.month, temp.day, temp.hour, temp.minute, temp.second)

        self.data = [
            {'commitid': '123',
             'project': 'pypy',
             'branch': 'default',
             'executable': 'pypy-c',
             'benchmark': 'Richards',
             'environment': 'bigdog',
             'result_value': 456},
            {'commitid': '456',
             'project': 'pypy',
             'branch': 'default',
             'executable': 'pypy-c',
             'benchmark': 'Richards',
             'environment': 'bigdog',
             'result_value': 457},
            {'commitid': '456',
             'project': 'pypy',
             'branch': 'default',
             'executable': 'pypy-c',
             'benchmark': 'Richards2',
             'environment': 'bigdog',
             'result_value': 34},
            {'commitid': '789',
             'project': 'pypy',
             'branch': 'default',
             'executable': 'pypy-c',
             'benchmark': 'Richards',
             'environment': 'bigdog',
             'result_value': 458},
        ]

    def test_get_returns_405(self):
        response = self.client.get(self.path,
                                   {'json': json.dumps(self.data)})

        self.assertEquals(response.status_code, 405)

    def test_add_correct_results(self):
        """Should add all results when the request data is valid"""
        response = self.client.post(self.path,
                                    {'json': json.dumps(self.data)})

        # Check that we get a success response
        self.assertEquals(response.status_code, 202)
        self.assertEquals(response.content.decode(),
                          "All result data saved successfully")

        # Check that the data was correctly saved
        e = Environment.objects.get(name='bigdog')
        b = Benchmark.objects.get(name='Richards')
        self.assertEquals(b.benchmark_type, "C")
        self.assertEquals(b.units, "seconds")
        self.assertEquals(b.lessisbetter, True)
        p = Project.objects.get(name='pypy')
        branch = Branch.objects.get(name='default', project=p)
        r = Revision.objects.get(commitid='123', branch=branch)
        i = Executable.objects.get(name='pypy-c')
        res = Result.objects.get(
            revision=r,
            executable=i,
            benchmark=b,
            environment=e
        )
        self.assertTrue(res.value, 456)
        resdate = res.date.strftime("%Y%m%dT%H%M%S")
        selfdate = self.cdate.strftime("%Y%m%dT%H%M%S")
        self.assertTrue(resdate, selfdate)

        r = Revision.objects.get(commitid='456', branch=branch)
        res = Result.objects.get(
            revision=r,
            executable=i,
            benchmark=b,
            environment=e
        )
        self.assertTrue(res.value, 457)

        r = Revision.objects.get(commitid='789', branch=branch)
        res = Result.objects.get(
            revision=r,
            executable=i,
            benchmark=b,
            environment=e
        )
        self.assertTrue(res.value, 458)

    def test_bad_environment(self):
        """Add result associated with non-existing environment.
           Only change one item in the list.
        """
#.........这里部分代码省略.........
开发者ID:evilhonduco,项目名称:codespeed,代码行数:101,代码来源:test_views.py

示例9: AddResult

class AddResult(TestCase):

    def setUp(self):
        self.path = reverse('codespeed.views.add_result')
        self.client = Client()
        self.e = Environment(name='Dual Core', cpu='Core 2 Duo 8200')
        self.e.save()
        temp = datetime.today()
        self.cdate = datetime(
            temp.year, temp.month, temp.day, temp.hour, temp.minute, temp.second)
        self.data = {
                'commitid': '23',
                'branch': 'default',
                'project': 'MyProject',
                'executable': 'myexe O3 64bits',
                'benchmark': 'float',
                'environment': 'Dual Core',
                'result_value': 456,
        }

    def test_add_correct_result(self):
        """Add correct result data"""
        response = self.client.post(self.path, self.data)
        
        # Check that we get a success response
        self.assertEquals(response.status_code, 202)
        self.assertEquals(response.content, "Result data saved successfully")
        
        # Check that the data was correctly saved
        e = Environment.objects.get(name='Dual Core')
        b = Benchmark.objects.get(name='float')
        self.assertEquals(b.benchmark_type, "C")
        self.assertEquals(b.units, "seconds")
        self.assertEquals(b.lessisbetter, True)
        p = Project.objects.get(name='MyProject')
        branch = Branch.objects.get(name='default', project=p)
        r = Revision.objects.get(commitid='23', branch=branch)
        i = Executable.objects.get(name='myexe O3 64bits')
        res = Result.objects.get(
            revision=r,
            executable=i,
            benchmark=b,
            environment=e
        )
        self.assertTrue(res.value, 456)

    def test_add_non_default_result(self):
        """Add result data with non-mandatory options"""
        modified_data = copy.deepcopy(self.data)
        revision_date = self.cdate - timedelta(minutes=2)
        modified_data['revision_date'] = revision_date
        result_date = self.cdate + timedelta(minutes=2)
        modified_data['result_date'] = result_date
        modified_data['std_dev']     = 1.11111
        modified_data['max']         = 2
        modified_data['min']         = 1.0
        response = self.client.post(self.path, modified_data)
        self.assertEquals(response.status_code, 202)
        self.assertEquals(response.content, "Result data saved successfully")
        e = Environment.objects.get(name='Dual Core')
        p = Project.objects.get(name='MyProject')
        branch = Branch.objects.get(name='default', project=p)
        r = Revision.objects.get(commitid='23', branch=branch)

        # Tweak the resolution down to avoid failing over very slight differences:
        self.assertEquals(r.date, revision_date)

        i = Executable.objects.get(name='myexe O3 64bits')
        b = Benchmark.objects.get(name='float')
        res = Result.objects.get(
            revision=r,
            executable=i,
            benchmark=b,
            environment=e
        )
        self.assertEquals(res.date, result_date)
        self.assertEquals(res.std_dev, 1.11111)
        self.assertEquals(res.val_max, 2)
        self.assertEquals(res.val_min, 1)

    def test_bad_environment(self):
        """Should return 400 when environment does not exist"""
        bad_name = '10 Core'
        self.data['environment'] = bad_name
        response = self.client.post(self.path, self.data)
        self.assertEquals(response.status_code, 400)
        self.assertEquals(response.content, "Environment " + bad_name + " not found")
        self.data['environment'] = 'Dual Core'

    def test_empty_argument(self):
        """Should respond 400 when a POST request has an empty argument"""
        for key in self.data:
            backup = self.data[key]
            self.data[key] = ""
            response = self.client.post(self.path, self.data)
            self.assertEquals(response.status_code, 400)
            self.assertEquals(
                response.content, 'Value for key "' + key + '" empty in request')
            self.data[key] = backup

#.........这里部分代码省略.........
开发者ID:michaelnt,项目名称:codespeed,代码行数:101,代码来源:tests.py

示例10: AddJSONResults

class AddJSONResults(TestCase):
    def setUp(self):
        self.path = reverse("codespeed.views.add_json_results")
        self.client = Client()
        self.e = Environment(name="bigdog", cpu="Core 2 Duo 8200")
        self.e.save()
        temp = datetime.today()
        self.cdate = datetime(temp.year, temp.month, temp.day, temp.hour, temp.minute, temp.second)

        self.data = [
            {
                "commitid": "123",
                "project": "pypy",
                "branch": "default",
                "executable": "pypy-c",
                "benchmark": "Richards",
                "environment": "bigdog",
                "result_value": 456,
            },
            {
                "commitid": "456",
                "project": "pypy",
                "branch": "default",
                "executable": "pypy-c",
                "benchmark": "Richards",
                "environment": "bigdog",
                "result_value": 457,
            },
            {
                "commitid": "456",
                "project": "pypy",
                "branch": "default",
                "executable": "pypy-c",
                "benchmark": "Richards2",
                "environment": "bigdog",
                "result_value": 34,
            },
            {
                "commitid": "789",
                "project": "pypy",
                "branch": "default",
                "executable": "pypy-c",
                "benchmark": "Richards",
                "environment": "bigdog",
                "result_value": 458,
            },
        ]

    def test_add_correct_results(self):
        """Should add all results when the request data is valid"""
        response = self.client.post(self.path, {"json": json.dumps(self.data)})

        # Check that we get a success response
        self.assertEquals(response.status_code, 202)
        self.assertEquals(response.content, "All result data saved successfully")

        # Check that the data was correctly saved
        e = Environment.objects.get(name="bigdog")
        b = Benchmark.objects.get(name="Richards")
        self.assertEquals(b.benchmark_type, "C")
        self.assertEquals(b.units, "seconds")
        self.assertEquals(b.lessisbetter, True)
        p = Project.objects.get(name="pypy")
        branch = Branch.objects.get(name="default", project=p)
        r = Revision.objects.get(commitid="123", branch=branch)
        i = Executable.objects.get(name="pypy-c")
        res = Result.objects.get(revision=r, executable=i, benchmark=b, environment=e)
        self.assertTrue(res.value, 456)
        resdate = res.date.strftime("%Y%m%dT%H%M%S")
        selfdate = self.cdate.strftime("%Y%m%dT%H%M%S")
        self.assertTrue(resdate, selfdate)

        r = Revision.objects.get(commitid="456", branch=branch)
        res = Result.objects.get(revision=r, executable=i, benchmark=b, environment=e)
        self.assertTrue(res.value, 457)

        r = Revision.objects.get(commitid="789", branch=branch)
        res = Result.objects.get(revision=r, executable=i, benchmark=b, environment=e)
        self.assertTrue(res.value, 458)

    def test_bad_environment(self):
        """Add result associated with non-existing environment.
           Only change one item in the list.
        """
        data = self.data[0]
        bad_name = "bigdog1"
        data["environment"] = bad_name
        response = self.client.post(self.path, {"json": json.dumps(self.data)})

        self.assertEquals(response.status_code, 400)
        self.assertEquals(response.content, "Environment " + bad_name + " not found")
        data["environment"] = "bigdog"

    def test_empty_argument(self):
        """Should return 400 when making a request with an empty argument"""
        data = self.data[1]
        for key in data:
            backup = data[key]
            data[key] = ""
            response = self.client.post(self.path, {"json": json.dumps(self.data)})
#.........这里部分代码省略.........
开发者ID:AlekSi,项目名称:codespeed,代码行数:101,代码来源:tests.py

示例11: EnvironmentTest

class EnvironmentTest(FixtureTestCase):
    """Test Environment() API
    """

    def setUp(self):
        self.env1_data = dict(
            name="env1",
            cpu="cpu1",
            memory="48kB",
            os="ZX Spectrum OS",
            kernel="2.6.32"
        )
        self.env1 = Environment(**self.env1_data)
        self.env1.save()
        self.env2_data = dict(
            name="env2",
            cpu="z80",
            memory="64kB",
            os="ZX Spectrum OS",
            kernel="2.6.32"
        )
        self.client = Client()
        super(EnvironmentTest, self).setUp()

    def test_get_environment(self):
        """Should get an existing environment"""
        response = self.client.get('/api/v1/environment/1/')
        self.assertEquals(response.status_code, 200)
        self.assertEqual(json.loads(response.content)['name'], "Dual Core")

    def test_get_environment_all_fields(self):
        """Should get all fields for an environment"""
        response = self.client.get('/api/v1/environment/%s/' % (self.env1.id,))
        self.assertEquals(response.status_code, 200)
        for k in self.env1_data.keys():
            self.assertEqual(
                json.loads(response.content)[k], getattr(self.env1, k))

    def test_post(self):
        """Should save a new environment"""
        response = self.client.post('/api/v1/environment/',
                                    data=json.dumps(self.env2_data),
                                    content_type='application/json')
        self.assertEquals(response.status_code, 201)
        response = self.client.get('/api/v1/environment/3/')
        for k, v in self.env2_data.items():
            self.assertEqual(
                json.loads(response.content)[k], v)

    def test_put(self):
        """Should modify an existing environment"""
        modified_data = copy.deepcopy(self.env2_data)
        modified_data['name'] = "env2.2"
        modified_data['memory'] = "128kB"
        response = self.client.put('/api/v1/environment/3/',
                                    data=json.dumps(modified_data),
                                    content_type='application/json')
        self.assertEquals(response.status_code, 201)
        response = self.client.get('/api/v1/environment/3/')
        for k, v in modified_data.items():
            self.assertEqual(
                json.loads(response.content)[k], v)

    def test_delete(self):
        """Should delete an environment"""
        response = self.client.delete('/api/v1/environment/1/',
                                    content_type='application/json')
        self.assertEquals(response.status_code, 204)

        response = self.client.get('/api/v1/environment/1/')
        self.assertEquals(response.status_code, 404)
开发者ID:Kami,项目名称:codespeed,代码行数:71,代码来源:tests_api.py

示例12: ResultBundleResourceTestCase

class ResultBundleResourceTestCase(FixtureTestCase):
    """Submitting new benchmark results"""

    DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
    def setUp(self):
        self.data1 = {
            'commitid': '2',
            'branch': 'default', # Always use default for trunk/master/tip
            'project': 'MyProject',
            'executable': 'myexe O3 64bits',
            'benchmark': 'float',
            'environment': "Bulldozer",
            'result_value': 4000,
            }
        self.data_optional = {
            'std_dev': 0.2,
            'val_min': 2.23,
            'val_max': 3.42,
            'date': datetime.now().strftime(self.DATETIME_FORMAT),
            }
        project_data = dict(
            name="PyPy",
            repo_type="M",
            repo_path="ssh://[email protected]/pypy/pypy",
            repo_user="fridolin",
            repo_pass="secret",
            )
        self.project = Project(**project_data)
        self.project.save()
        self.env1 = Environment(name='Bulldozer')
        self.env1.save()

    def test_post_mandatory(self):
        """Should save a new result with only mandatory data"""
        response = self.client.post('/api/v1/benchmark-result/',
                                    data=json.dumps(self.data1),
                                    content_type='application/json')
        self.assertEquals(response.status_code, 201)
        id = response['Location'].rsplit('/', 2)[-2]
        result = Result.objects.get(pk=int(id))
        # just to make the point
        self.assertIsInstance(result, Result)
        self.assertEqual(result.value, self.data1['result_value'])

    def test_post_all_data(self):
        """Should save a new result with mandatory and optional data"""
        data = dict(self.data1, **self.data_optional)
        response = self.client.post('/api/v1/benchmark-result/',
                                    data=json.dumps(data),
                                    content_type='application/json')
        self.assertEquals(response.status_code, 201)

    def test_get_one(self):
        """Should get a result bundle"""
        response = self.client.get('/api/v1/benchmark-result/1/',
                                    content_type='application/json')
        self.assertEquals(response.status_code, 200)
        response_data = json.loads(response.content)
        for k in ('project', 'result', 'branch', 'benchmark', 'environment',
            'executable', 'revision'):
            self.assertEqual(
                response_data[k],
                '/api/v1/{0}/1/'.format(k,))
开发者ID:iffy,项目名称:codespeed,代码行数:63,代码来源:tests_api.py

示例13: ResultBundleTestCase

class ResultBundleTestCase(FixtureTestCase):

    def setUp(self):
        self.data1 = {
            'commitid': '2',
            'branch': 'default', # Always use default for trunk/master/tip
            'project': 'MyProject',
            'executable': 'myexe O3 64bits',
            'benchmark': 'float',
            'environment': "Bulldozer",
            'result_value': 4000,
            }
        DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
        self.data_optional = {
            'std_dev': 0.2,
            'val_min': 2.23,
            'val_max': 3.42,
            'date': datetime.now().strftime(DATETIME_FORMAT),
            }
        project_data = dict(
            name="PyPy",
            repo_type="M",
            repo_path="ssh://[email protected]/pypy/pypy",
            repo_user="fridolin",
            repo_pass="secret",
            )
        self.project = Project(**project_data)
        self.project.save()
        self.env1 = Environment(name='Bulldozer')
        self.env1.save()

    def test_populate_and_save(self):
        bundle = ResultBundle(**self.data1)
        bundle._populate_obj_by_data()
        # should raise exception if not OK
        bundle.save()
        self.assert_(True)

    def test_save_same_result_again(self):
        """Save a previously saved result. Expected is an IntegrityError"""
        modified_data = copy.deepcopy(self.data1)
        modified_data['environment'] = "Dual Core"
        bundle = ResultBundle(**modified_data)
        bundle._populate_obj_by_data()
        self.assertRaises(IntegrityError, bundle.save)

    def test_for_nonexistent_environment(self):
        """Save data using non existing environment. Expected is an
        ImmediateHttpResponse
        """
        modified_data = copy.deepcopy(self.data1)
        modified_data['environment'] = "Foo the Bar"
        self.assertRaises(ImmediateHttpResponse, ResultBundle, **modified_data)

    def test_insufficient_data(self):
        """See if Result() is saved w/ insufficient data"""
        modified_data = copy.deepcopy(self.data1)
        modified_data.pop('environment')
        self.assertRaises(ImmediateHttpResponse, ResultBundle, **modified_data)

    def test_date_attr_set(self):
        """Check if date attr of Result() is set if not given"""
        # date is set automatically
        modified_data = copy.deepcopy(self.data1)
        bundle = ResultBundle(**modified_data)
        bundle.save()
        self.assertIsInstance(bundle.obj.date, datetime)
        # date set by value
        modified_data['date'] = '2011-05-05 03:01:45'
        ResultBundle(**modified_data)
        # wrong date string
        modified_data['date'] = '2011-05-05T03:01:45'
        self.assertRaises(ImmediateHttpResponse, ResultBundle, **modified_data)

    def test_optional_data(self):
        """Check handling of optional data"""
        data = dict(self.data1.items() + self.data_optional.items())
        bundle = ResultBundle(**data)
        bundle.save()
        self.assertIsInstance(bundle.obj.date, datetime)
        self.assertEqual(bundle.obj.std_dev,
                         float(self.data_optional['std_dev']))
        self.assertEqual(bundle.obj.val_max,
                         float(self.data_optional['val_max']))
        self.assertEqual(bundle.obj.val_min,
                         float(self.data_optional['val_min']))

    def test_non_exiting_items(self):
        """Check handling of optional data"""
        modified_data = copy.deepcopy(self.data1)
        modified_data['commitid'] = '0b31bf33a469ac2cb1949666eea54d69a36c3724'
        modified_data['project'] = 'Cython'
        modified_data['benchmark'] = 'Django Template'
        modified_data['executable'] = 'pypy-jit'
        bundle = ResultBundle(**modified_data)
        bundle.save()
        self.assertEqual(bundle.obj.revision.commitid,
                         modified_data['commitid'])
        self.assertEqual(bundle.obj.benchmark.name,
                         modified_data['benchmark'])
#.........这里部分代码省略.........
开发者ID:iffy,项目名称:codespeed,代码行数:101,代码来源:tests_api.py


注:本文中的codespeed.models.Environment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。