Module: Pocolog::TestHelpers
- Defined in:
- lib/pocolog/test_helpers.rb
Defined Under Namespace
Classes: RecordingReporter
Instance Attribute Summary collapse
-
#int32_t ⇒ Object
readonly
For convenience, the test helpers create a int32_t type and use it by default.
Instance Method Summary collapse
- #assert_report_empty ⇒ Object
- #assert_report_includes(kind, message) ⇒ Object
-
#close_logfile ⇒ Object
Close the current logfile (either created or opened).
-
#create_logfile(basename) ⇒ Object
Create a new logfile.
-
#create_logfile_stream(name, samples_rt = [], samples_lg = [], samples_value = [], type: int32_t, metadata: {}) ⇒ Object
Create a stream on the last created logfile.
- #flush_logfile ⇒ Object
- #logfile_path(*basename) ⇒ Object
- #logfile_tell ⇒ Object
- #logfiles_dir ⇒ Object
- #move_logfile_path(new_dir, delete_current: true) ⇒ Object
-
#open_logfile(path, index_dir: nil, close_current: true) ⇒ Object
Open an existing logfile.
- #open_logfile_stream(basename, stream_name, close_current: true, index_dir: nil) ⇒ Object
- #recording_reporter ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
- #write_logfile_sample(rt, lg, value) ⇒ Object
Instance Attribute Details
#int32_t ⇒ Object (readonly)
For convenience, the test helpers create a int32_t type and use it by default
10 11 12 |
# File 'lib/pocolog/test_helpers.rb', line 10 def int32_t @int32_t end |
Instance Method Details
#assert_report_empty ⇒ Object
59 60 61 |
# File 'lib/pocolog/test_helpers.rb', line 59 def assert_report_empty assert @__recording_reporter..empty? end |
#assert_report_includes(kind, message) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pocolog/test_helpers.rb', line 63 def assert_report_includes(kind, ) return if @__recording_reporter.match?(kind, ) = "reporter did not receive any #{kind.inspect} message "\ "matching #{}. Received messages:\n " += @__recording_reporter . .map { |k, m| "#{k.inspect}: #{m}" } .join("\n ") flunk() end |
#close_logfile ⇒ Object
Close the current logfile (either created or opened)
116 117 118 119 120 121 122 123 |
# File 'lib/pocolog/test_helpers.rb', line 116 def close_logfile return unless @__current_logfile @__current_logfile.close logfile = @__current_logfile @__current_logfile = nil logfile end |
#create_logfile(basename) ⇒ Object
Create a new logfile
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/pocolog/test_helpers.rb', line 94 def create_logfile(basename) path = logfile_path(basename) if File.exist?(index_path = Logfiles.default_index_filename(path)) FileUtils.rm(index_path) end @__current_logfile = Pocolog::Logfiles.create(path) return path unless block_given? begin yield path ensure close_logfile end end |
#create_logfile_stream(name, samples_rt = [], samples_lg = [], samples_value = [], type: int32_t, metadata: {}) ⇒ Object
Create a stream on the last created logfile
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/pocolog/test_helpers.rb', line 130 def create_logfile_stream( name, samples_rt = [], samples_lg = [], samples_value = [], type: int32_t, metadata: {} ) stream = @__current_logfile.create_stream(name, type, ) samples_rt.zip(samples_lg, samples_value).each do |rt, lg, v| stream.write(rt, lg, v) end @__current_stream = stream stream end |
#flush_logfile ⇒ Object
111 112 113 |
# File 'lib/pocolog/test_helpers.rb', line 111 def flush_logfile @__current_logfile.flush end |
#logfile_path(*basename) ⇒ Object
170 171 172 |
# File 'lib/pocolog/test_helpers.rb', line 170 def logfile_path(*basename) File.(File.join(*basename), @__logfiles_dir) end |
#logfile_tell ⇒ Object
125 126 127 |
# File 'lib/pocolog/test_helpers.rb', line 125 def logfile_tell @__current_logfile.io.tell end |
#logfiles_dir ⇒ Object
166 167 168 |
# File 'lib/pocolog/test_helpers.rb', line 166 def logfiles_dir @__logfiles_dir end |
#move_logfile_path(new_dir, delete_current: true) ⇒ Object
77 78 79 80 81 |
# File 'lib/pocolog/test_helpers.rb', line 77 def move_logfile_path(new_dir, delete_current: true) FileUtils.rm_rf(@__logfiles_dir) if delete_current FileUtils.mkdir_p(new_dir) @__logfiles_dir = new_dir end |
#open_logfile(path, index_dir: nil, close_current: true) ⇒ Object
Open an existing logfile
147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/pocolog/test_helpers.rb', line 147 def open_logfile(path, index_dir: nil, close_current: true) close_logfile if @__current_logfile && close_current logfile = Pocolog::Logfiles.open(logfile_path(path), index_dir: index_dir) if block_given? begin yield(logfile) ensure close_logfile end else logfile end end |
#open_logfile_stream(basename, stream_name, close_current: true, index_dir: nil) ⇒ Object
160 161 162 163 164 |
# File 'lib/pocolog/test_helpers.rb', line 160 def open_logfile_stream(basename, stream_name, close_current: true, index_dir: nil) open_logfile(basename, close_current: close_current, index_dir: index_dir) .stream(stream_name) end |
#recording_reporter ⇒ Object
55 56 57 |
# File 'lib/pocolog/test_helpers.rb', line 55 def recording_reporter @__recording_reporter end |
#setup ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/pocolog/test_helpers.rb', line 12 def setup @__logfiles_dir = Dir.mktmpdir registry = Typelib::Registry.new @int32_t = registry.create_numeric '/int32_t', 4, :sint @__recording_reporter = RecordingReporter.new super end |
#teardown ⇒ Object
83 84 85 86 |
# File 'lib/pocolog/test_helpers.rb', line 83 def teardown FileUtils.rm_rf @__logfiles_dir super end |
#write_logfile_sample(rt, lg, value) ⇒ Object
142 143 144 |
# File 'lib/pocolog/test_helpers.rb', line 142 def write_logfile_sample(rt, lg, value) @__current_stream.write(rt, lg, value) end |