|
| 1 | +#!/usr/bin/env python |
1 | 2 | ''' |
2 | 3 | Test code for the python version of HdrHistogram. |
3 | 4 |
|
|
25 | 26 | from hdrh.histogram import HdrHistogram |
26 | 27 |
|
27 | 28 |
|
28 | | -ENCODE_SAMPLES_HDRHISTOGRAM_C = [ |
29 | | - # standard Hdr test histogram |
30 | | - 'HISTFAAAACF4nJNpmSzMwMDAzAABMJoRTM6Y1mD/ASLwN5oJAFuQBYU=', |
31 | | - 'HISTFAAAACh4nJNpmSzMwMDAyQABzFCaEUzOmNZg/wEisL2Kaasc00ImJgCC8Qbe' |
32 | | -] |
33 | | - |
34 | | -def dump_histogram(encoded_histogram): |
35 | | - print('\nDumping histogram: ' + encoded_histogram) |
36 | | - histogram = HdrHistogram.decode(encoded_histogram) |
37 | | - |
38 | | - histogram.output_percentile_distribution(open(os.devnull, 'wb'), 1) |
39 | | - # sys.stdout.buffer will raise AttributeError in python 2.7 |
40 | | - try: |
41 | | - # python 3 requires .buffer to write bytes |
42 | | - output = sys.stdout.buffer |
43 | | - except AttributeError: |
44 | | - # in python 2.7, bytes can be writtent to sys.stdout |
45 | | - output = sys.stdout |
46 | | - histogram.output_percentile_distribution(output, 1) |
47 | | - |
48 | 29 | def test_dump_histogram(): |
| 30 | + ENCODE_SAMPLES_HDRHISTOGRAM_C = [ |
| 31 | + # standard Hdr test histogram |
| 32 | + 'HISTFAAAACF4nJNpmSzMwMDAzAABMJoRTM6Y1mD/ASLwN5oJAFuQBYU=', |
| 33 | + 'HISTFAAAACh4nJNpmSzMwMDAyQABzFCaEUzOmNZg/wEisL2Kaasc00ImJgCC8Qbe' |
| 34 | + ] |
49 | 35 | for hdrh in ENCODE_SAMPLES_HDRHISTOGRAM_C: |
50 | | - dump_histogram(hdrh) |
51 | | - |
52 | | -def main(): |
53 | | - args = sys.argv[1:] |
54 | | - if args: |
55 | | - encoded_histograms = args |
56 | | - else: |
57 | | - encoded_histograms = ENCODE_SAMPLES_HDRHISTOGRAM_C |
58 | | - |
59 | | - for hdrh in encoded_histograms: |
60 | | - dump_histogram(hdrh) |
61 | | - |
| 36 | + HdrHistogram.dump(hdrh, output=open(os.devnull, 'wb')) |
| 37 | + HdrHistogram.dump(hdrh) |
62 | 38 |
|
63 | | -if __name__ == '__main__': |
64 | | - main() |
0 commit comments