Permalink
Browse files

Implemented tests, fixed bugs found by tests

  • Loading branch information...
1 parent 1395749 commit d90278e8391ed3db51468f27c0a220879f7d2865 @paulcbetts committed Dec 11, 2007
Showing with 38 additions and 466 deletions.
  1. +6 −5 lib/library.rb
  2. +3 −2 lib/song.rb
  3. +4 −1 lib/taggers/estelle-taglib.rb
  4. +6 −0 lib/taggers/taglib.rb
  5. +0 −69 lib/utility.rb
  6. +1 −8 test/test_library.rb
  7. +2 −4 test/test_song.rb
  8. +0 −350 test/test_taglib.rb
  9. +16 −27 test/test_utility.rb
View
@@ -36,25 +36,26 @@
DefaultTaggerPath = File.join(File.dirname(__FILE__), 'taggers')
class MusicLibrary < Logger::Application
- @taggers = nil
- @tag_info = nil
- @album_info = nil
- @md5_index = nil
public
attr_writer :is_soundtrack
def initialize
super(self.class.to_s())
self.level = $logging_level
+
+ @taggers = nil
+ @tag_info = nil
+ @album_info = nil
+ @md5_index = nil
end
def clear
@tag_info = nil
@album_info = nil
end
- def empty?; not @tag_info or @tag_info.empty?; end
+ def empty?; (not @tag_info) or @tag_info.empty?; end
def size; (@tag_info ? @tag_info.size : 0); end
View
@@ -45,8 +45,8 @@ def get_canonical_artist
FeaturingList.each { |x| s.sub!(x, ',') }
# Then, split on any sort of punctuation
- artists = s.split(/[;,:\|-]/)
- artists.delete_if { |x| x.chomp.empty? }
+ artists = s.split(/[;,:\|-]/).collect {|x| super_chomp(x)}
+ artists.delete_if { |x| super_chomp(x).empty? }
@data[:canonical_artist] = (artists.sort.join ',')
end
@@ -91,6 +91,7 @@ def []=(key, val)
def checked_tag(key, invalid_chars, checking_proc)
@@sub_table ||= {}
data = @data[key] || "<#{key}>" # Write the original key back
+ return data unless data =~ invalid_chars
# Switch out the data with a replacement if we've got one
data = @@sub_table[data] || data
@@ -22,6 +22,7 @@
$:.unshift File.dirname(__FILE__)
# Ruby standard library
+require 'rubygems'
require 'logger'
require 'gettext'
require 'pathname'
@@ -34,6 +35,8 @@
include GetText
+$logging_level ||= ($DEBUG ? Logger::DEBUG : Logger::ERROR)
+
class TagLibTagger < Logger::Application
include Singleton
@@ -58,7 +61,7 @@ def song_info(path)
begin
f = TagLib::File.new(path.to_s)
rescue Exception
- #log DEBUG, "Couldn't read #{path.to_s}"
+ log DEBUG, "Couldn't read #{path.to_s}"
return nil
end
View
@@ -112,6 +112,12 @@ class BadAudioProperties < Exception
class File
def initialize(p)
+ # Init variables so we don't get warnings on test
+ @path = nil
+ @file = nil
+ @tag = nil
+ @audio = nil
+
@path = p
if not @path
raise BadPath.new
View
@@ -29,75 +29,6 @@
require 'song'
require 'settings'
-class Task
- def initialize(call, params, do_safe = false)
- @call = call
- if do_safe and params
- @params = params.collect { |x| x.clone }
- else
- @params = (params ? params : [])
- end
- end
-
- def invoke
- @call.call(*@params) if @call
- end
-
- attr_reader :call, :params
-end
-
-
-class TaskQueue < Queue
- protected :shift
- protected :deq
- protected :pop
-
- public
- def initialize(yield_every = 0)
- super()
- @do_quit = false
- @pause = false
- @the_thread = nil
- @yield_every = yield_every
- end
-
- def start
- if @the_thread
- @pause = false
- @the_thread.run if @the_thread.stop?
- return
- end
-
- # Start the thread
- @the_thread = Thread.new(@yield_every) do |yield_every|
- count = 0
- puts "Starting loop"
- while not @do_quit do
- Thread.stop if @pause
- puts "Running: size = #{size()}"
- self.pop.invoke
- count += 1
- Thread.pass if yield_every > 0 and (count % yield_every == 0)
- end
- end
- @the_thread.run
- end
-
- def clear_and_halt()
- clear
- return unless @the_thread
- @the_thread.kill
- @the_thread = nil
- end
-
- attr :pause
-end
-
-
-##############################
-# Miscellaneous Functions
-##############################
-
ToEscape = [
[ '\\', "\\\\" ],
[ '"', "\"" ],
View
@@ -1,17 +1,10 @@
-# Code Generated by ZenTest v. 3.6.1
-# classname: asrt / meth = ratio%
-# MusicLibrary: 0 / 11 = 0.00%
-
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'test/unit' unless defined? $ZENTEST and $ZENTEST
require 'library'
+require 'yaml'
class TestMusicLibrary < Test::Unit::TestCase
- def test_clear
- raise NotImplementedError, 'Need to write test_clear'
- end
-
def test_create_action_list
raise NotImplementedError, 'Need to write test_create_action_list'
end
View
@@ -19,8 +19,8 @@ def test_class_sub_table_equals
def test_checked_tag
@ts[:test] = 'foo'
- assert_equal('bar', @ts.checked_tag(:test, /oo/, lambda {|x| 'bar'}))
- assert_equal('foo', @ts.checked_tag(:test, /oz/, lambda {|x| 'bar'}))
+ assert_equal('bar', @ts.checked_tag(:test, /oo/, lambda {|x,y,z| 'bar'}))
+ assert_equal('foo', @ts.checked_tag(:test, /oz/, lambda {|x,y,z| 'bar'}))
end
def test_get_canonical_artist
@@ -52,5 +52,3 @@ def test_to_hash
assert_equal({:foo => 'bar', :baz => 'bamf'}, @ts.to_hash)
end
end
-
-# Number of errors detected: 8
Oops, something went wrong.

0 comments on commit d90278e

Please sign in to comment.