Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: tracing/tracing/value/histogram_unittest.py

Issue 2977283002: Ownership into GenericSets (Closed)
Patch Set: Fix reserved info reference Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2017 The Chromium Authors. All rights reserved. 1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json 5 import json
6 import math 6 import math
7 import time 7 import time
8 import unittest 8 import unittest
9 9
10 from tracing.value import histogram 10 from tracing.value import histogram
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 self.assertEqual(1, hist.GetApproximatePercentile(0.5)) 526 self.assertEqual(1, hist.GetApproximatePercentile(0.5))
527 self.assertEqual(2, hist.GetApproximatePercentile(0.9)) 527 self.assertEqual(2, hist.GetApproximatePercentile(0.9))
528 self.assertEqual(3, hist.GetApproximatePercentile(1)) 528 self.assertEqual(3, hist.GetApproximatePercentile(1))
529 hist.AddSample(4) 529 hist.AddSample(4)
530 self.assertEqual(0, hist.GetApproximatePercentile(0)) 530 self.assertEqual(0, hist.GetApproximatePercentile(0))
531 self.assertEqual(1, hist.GetApproximatePercentile(0.4)) 531 self.assertEqual(1, hist.GetApproximatePercentile(0.4))
532 self.assertEqual(2, hist.GetApproximatePercentile(0.7)) 532 self.assertEqual(2, hist.GetApproximatePercentile(0.7))
533 self.assertEqual(3, hist.GetApproximatePercentile(0.9)) 533 self.assertEqual(3, hist.GetApproximatePercentile(0.9))
534 self.assertEqual(4, hist.GetApproximatePercentile(1)) 534 self.assertEqual(4, hist.GetApproximatePercentile(1))
535 535
536 class OwnershipUnittest(unittest.TestCase):
537
538 def testInitRequiresEmailsAsIterable(self):
539 with self.assertRaises(TypeError):
540 _ = histogram.Ownership(123)
541
542 def testInitEmailsDefaultValue(self):
543 owner_empty_emails = histogram.Ownership(None)
544 self.assertEqual(owner_empty_emails.emails, [])
545 self.assertIsNone(owner_empty_emails.component)
546
547 def testInitRequiredComponentAsStr(self):
548 with self.assertRaises(TypeError):
549 _ = histogram.Ownership([], ['foo'])
550
551 def testEmails(self):
552 ownership = histogram.Ownership([])
553 self.assertEqual(ownership.emails, [])
554
555 ownership = histogram.Ownership(['alice@chromium.org'])
556 self.assertEqual(ownership.emails, ['alice@chromium.org'])
557
558 def testComponent(self):
559 ownership = histogram.Ownership([])
560 self.assertIsNone(ownership.component)
561
562 ownership = histogram.Ownership([], 'fooBar')
563 self.assertEqual(ownership.component, 'fooBar')
564
565 def testFromDict(self):
566 sample_emails = ['alice@chromium.org', 'bob@chromium.org']
567
568 ownership_dict = {'emails': sample_emails}
569 ownership_no_component = histogram.Ownership.FromDict(ownership_dict)
570 self.assertEqual(ownership_no_component.emails, sample_emails)
571 self.assertIsNone(ownership_no_component.component)
572
573 ownership_dict['component'] = 'fooBar'
574 ownership_with_component = histogram.Ownership.FromDict(ownership_dict)
575 self.assertEqual(ownership_with_component.emails, sample_emails)
576 self.assertEqual(ownership_with_component.component, 'fooBar')
577
578 def testAsDict(self):
579 sample_emails = ['alice@chromium.org']
580
581 ownership_no_component = histogram.Ownership(sample_emails)
582 ownership_dict_no_component = ownership_no_component.AsDict()
583
584 sample_emails.append('bob@chromium.org')
585
586 ownership_with_component = histogram.Ownership(sample_emails, 'fooBar')
587
588 self.assertEqual(ownership_dict_no_component['emails'],
589 ['alice@chromium.org'])
590 self.assertNotIn('component', ownership_dict_no_component)
591 self.assertEqual(ownership_with_component.AsDict()['component'], 'fooBar')
592
593 def testEquality(self):
594 ownership0 = histogram.Ownership(['alice@chromium.org'], 'foo')
595 ownership1 = histogram.Ownership(['alice@chromium.org'], 'foo')
596
597 self.assertEqual(ownership0, ownership1)
598
599 def testInequality(self):
600 ownership0 = histogram.Ownership(['alice@chromium.org'], 'foo')
601 ownership1 = histogram.Ownership(['alice@chromium.org'], 'bar')
602
603 self.assertNotEqual(ownership0, ownership1)
604
605 class BreakdownUnittest(unittest.TestCase): 536 class BreakdownUnittest(unittest.TestCase):
606 537
607 def testRoundtrip(self): 538 def testRoundtrip(self):
608 bd = histogram.Breakdown() 539 bd = histogram.Breakdown()
609 bd.Set('one', 1) 540 bd.Set('one', 1)
610 bd.Set('m1', -1) 541 bd.Set('m1', -1)
611 bd.Set('inf', float('inf')) 542 bd.Set('inf', float('inf'))
612 bd.Set('nun', float('nan')) 543 bd.Set('nun', float('nan'))
613 bd.Set('ninf', float('-inf')) 544 bd.Set('ninf', float('-inf'))
614 d = bd.AsDict() 545 d = bd.AsDict()
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 hist5.diagnostics['a'] = histogram.UnmergeableDiagnosticSet( 1073 hist5.diagnostics['a'] = histogram.UnmergeableDiagnosticSet(
1143 [events, generic2]) 1074 [events, generic2])
1144 hist.diagnostics.Merge(hist5.diagnostics, hist, hist5) 1075 hist.diagnostics.Merge(hist5.diagnostics, hist, hist5)
1145 self.assertIsInstance( 1076 self.assertIsInstance(
1146 hist.diagnostics['a'], histogram.UnmergeableDiagnosticSet) 1077 hist.diagnostics['a'], histogram.UnmergeableDiagnosticSet)
1147 diagnostics = list(hist.diagnostics['a']) 1078 diagnostics = list(hist.diagnostics['a'])
1148 self.assertIs(generic, diagnostics[0]) 1079 self.assertIs(generic, diagnostics[0])
1149 self.assertIs(related_set, diagnostics[1]) 1080 self.assertIs(related_set, diagnostics[1])
1150 self.assertIs(events, diagnostics[2]) 1081 self.assertIs(events, diagnostics[2])
1151 self.assertIs(generic2, diagnostics[3]) 1082 self.assertIs(generic2, diagnostics[3])
OLDNEW
« tracing/tracing/value/diagnostics/reserved_names.html ('K') | « tracing/tracing/value/histogram.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698