|
| 1 | +require_relative 'test_helper' |
| 2 | +require_relative '../lib/graph_renderer' |
| 3 | +require 'tempfile' |
| 4 | +require 'tmpdir' |
| 5 | +require 'json' |
| 6 | + |
| 7 | +describe GraphRenderer do |
| 8 | + describe '.render' do |
| 9 | + it 'creates a PNG file from JSON data' do |
| 10 | + Dir.mktmpdir do |dir| |
| 11 | + json_path = File.join(dir, 'test.json') |
| 12 | + png_path = File.join(dir, 'test.png') |
| 13 | + |
| 14 | + # Create test JSON file with minimal benchmark data |
| 15 | + json_data = { |
| 16 | + metadata: { |
| 17 | + 'ruby-a' => 'version A' |
| 18 | + }, |
| 19 | + raw_data: { |
| 20 | + 'ruby-a' => { |
| 21 | + 'bench1' => { |
| 22 | + 'bench' => [1.0, 1.1, 0.9] |
| 23 | + } |
| 24 | + } |
| 25 | + } |
| 26 | + } |
| 27 | + File.write(json_path, JSON.generate(json_data)) |
| 28 | + |
| 29 | + result = GraphRenderer.render(json_path, png_path) |
| 30 | + |
| 31 | + assert_equal png_path, result |
| 32 | + assert File.exist?(png_path), 'PNG file should be created' |
| 33 | + assert File.size(png_path) > 0, 'PNG file should not be empty' |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + it 'returns the png_path' do |
| 38 | + Dir.mktmpdir do |dir| |
| 39 | + json_path = File.join(dir, 'test.json') |
| 40 | + png_path = File.join(dir, 'test.png') |
| 41 | + |
| 42 | + json_data = { |
| 43 | + metadata: { 'ruby-a' => 'version A' }, |
| 44 | + raw_data: { 'ruby-a' => { 'bench1' => { 'bench' => [1.0] } } } |
| 45 | + } |
| 46 | + File.write(json_path, JSON.generate(json_data)) |
| 47 | + |
| 48 | + result = GraphRenderer.render(json_path, png_path) |
| 49 | + |
| 50 | + assert_equal png_path, result |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + it 'handles multiple rubies and benchmarks' do |
| 55 | + Dir.mktmpdir do |dir| |
| 56 | + json_path = File.join(dir, 'test.json') |
| 57 | + png_path = File.join(dir, 'test.png') |
| 58 | + |
| 59 | + json_data = { |
| 60 | + metadata: { |
| 61 | + 'ruby-a' => 'version A', |
| 62 | + 'ruby-b' => 'version B' |
| 63 | + }, |
| 64 | + raw_data: { |
| 65 | + 'ruby-a' => { |
| 66 | + 'bench1' => { 'bench' => [1.0, 1.1] }, |
| 67 | + 'bench2' => { 'bench' => [2.0, 2.1] } |
| 68 | + }, |
| 69 | + 'ruby-b' => { |
| 70 | + 'bench1' => { 'bench' => [0.9, 1.0] }, |
| 71 | + 'bench2' => { 'bench' => [1.8, 1.9] } |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + File.write(json_path, JSON.generate(json_data)) |
| 76 | + |
| 77 | + GraphRenderer.render(json_path, png_path) |
| 78 | + |
| 79 | + assert File.exist?(png_path) |
| 80 | + assert File.size(png_path) > 0 |
| 81 | + end |
| 82 | + end |
| 83 | + end |
| 84 | +end |
0 commit comments