Skip to content

Commit

Permalink
more unit tests for spectrogram and caching
Browse files Browse the repository at this point in the history
  • Loading branch information
cofiem committed Nov 2, 2012
1 parent d1cd3a4 commit ee9d5e3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/models/permission.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Permission < ActiveRecord::Base
extend Enumerize
#extend Enumerize

# relations
belongs_to :user
Expand All @@ -13,7 +13,7 @@ class Permission < ActiveRecord::Base
# belongs_to :user

# enumerations
enumerize :level, :in => [:owner, :write, :read, :none], :default => :none, predicates: true
#enumerize :level, :in => [:owner, :write, :read, :none], :default => :none, predicates: true

# validation
validates :level, :presence => true
Expand Down
6 changes: 3 additions & 3 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Tag < ActiveRecord::Base
extend Enumerize
#extend Enumerize

# relations
has_many :audio_event_tags
Expand All @@ -15,8 +15,8 @@ class Tag < ActiveRecord::Base
validates_as_paranoid

# enums
enumerize :class, :in => [:looks_like, :sounds_like], predicates: true
enumerize :type_of_tag, :in => [:common_name, :species_name], predicates: true
#enumerize :class, :in => [:looks_like, :sounds_like], predicates: true
#enumerize :type_of_tag, :in => [:common_name, :species_name], predicates: true

# validation
validates :is_taxanomic, :presence => true
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/audio_sox.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'OS'

module AudioSox
include OS
@sox_path = if OS.windows? then "./vendor/bin/sox/windows/sox.exe" else "sox" end
Expand Down
17 changes: 6 additions & 11 deletions lib/modules/spectrogram.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require 'OS'
require 'open3'

module Spectrogram
@sox_path = if OS.windows? then "./vendor/bin/sox/windows/sox.exe" else "sox" end
@sox_arguments_verbose = "-V"
Expand All @@ -16,13 +13,8 @@ module Spectrogram
# An existing image file will not be overwritten.
# possible parameters: :window :colour :format
def self.generate(source, target, modify_parameters)

# check for existing image, and do not overwrite
if File.exist?(target)
Rails.logger.warn "Target path for spectrogram generation already exists: #{target}."
return [ "", "", "", source, File.exist?(source), target, File.exist?(target) ]
end

raise ArgumentError, "Target path for spectrogram generation already exists: #{target}." unless !File.exist?(target)

# sox command to create a spectrogram from an audio file
command = "#@sox_path #@sox_arguments_verbose \"#{source}\" #@sox_arguments_output_audio #@sox_arguments_sample_rate #@sox_arguments_spectrogram #@sox_arguments_output \"#{target}\""

Expand All @@ -31,7 +23,10 @@ def self.generate(source, target, modify_parameters)

# log the command
Rails.logger.debug "Spectrogram generation return status #{status.exitstatus}. Command: #{command}"


# check for source file problems
raise ArgumentError, "Source file was not a valid audio file: #{source}." if stderr_str.include? 'FAIL formats: can\'t open input file'

# package up all the available information and return it
result = [ stdout_str, stderr_str, status, source, File.exist?(source), target, File.exist?(target) ]
end
Expand Down

0 comments on commit ee9d5e3

Please sign in to comment.