Skip to content

Commit

Permalink
Slightly drier ATOMS Test class
Browse files Browse the repository at this point in the history
  • Loading branch information
ytti committed Dec 21, 2024
1 parent e8edd19 commit 7e134a5
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions spec/model/model_atoms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ def initialize(model, desc)
def skip?
@skip
end

def get_filename(type)
ext = type == 'output' ? '.txt' : '.yaml'
[@model, @desc, type].join(':') + ext
end

def load_file(file_name)
ext = File.extname(file_name)
if ext == '.yaml'
YAML.load_file(File.join(DIRECTORY, file_name))
else
File.read(File.join(DIRECTORY, file_name))
end
rescue StandardError
nil
end
end

class TestOutput < Test
Expand All @@ -44,12 +60,8 @@ class TestOutput < Test
def initialize(model, desc)
super

simulation_file = [model, desc, 'simulation'].join(':') + '.yaml'
output_file = [model, desc, 'output'].join(':') + '.txt'

@simulation = YAML.load_file(File.join(DIRECTORY, simulation_file)) rescue nil
@output = File.read(File.join(DIRECTORY, output_file)) rescue nil

@simulation = load_file(get_filename('simulation'))
@output = load_file(get_filename('output'))
@skip = true unless @simulation && @output
end
end
Expand All @@ -60,9 +72,7 @@ class TestPrompt < Test
def initialize(model, desc)
super

data_file = [model, desc, 'prompt'].join(':') + '.yaml'
@data = YAML.load_file(File.join(DIRECTORY, data_file)) rescue nil

@data = load_file(get_filename('prompt'))
@skip = true unless @data
end
end
Expand Down

0 comments on commit 7e134a5

Please sign in to comment.