Changeset 93

Show
Ignore:
Timestamp:
07/11/08 17:56:49 (7 weeks ago)
Author:
deveiant
Message:
  • Synched Rakefile with rake-tasklibs
  • Started conversion of synset tests to specs
  • Finished converting lexicon tests to specs
Location:
branches/rakefile-work
Files:
3 modified
1 moved

Legend:

Unmodified
Added
Removed
  • branches/rakefile-work/Rakefile

    r92 r93  
    6060SPEC_EXCLUDES = 'spec,/Library/Ruby,/var/lib,/usr/local/lib' 
    6161 
    62 COVERAGE_MINIMUM = 83.0 
    63  
    64 RELEASE_FILES = FileList[ TEXT_FILES + SPEC_FILES + LIB_FILES + EXT_FILES ] 
     62TESTDIR       = BASEDIR + 'tests' 
     63TEST_FILES    = Pathname.glob( TESTDIR + '**/*.tests.rb' ) 
     64 
     65RELEASE_FILES = FileList[ TEXT_FILES + SPEC_FILES + TEST_FILES + LIB_FILES + EXT_FILES ] 
    6566 
    6667 
     
    192193### Cruisecontrol task 
    193194desc "Cruisecontrol build" 
    194 task :cruise => [:clean, 'coverage:verify', :package] do |task| 
     195task :cruise => [:clean, :spec, :package] do |task| 
    195196    raise "Artifacts dir not set." if ARTIFACTS_DIR.to_s.empty? 
    196197    artifact_dir = ARTIFACTS_DIR.cleanpath 
  • branches/rakefile-work/lib/wordnet/lexicon.rb

    r87 r93  
    161161    def checkpoint( bytes=0, minutes=0 ) 
    162162        @env.checkpoint 
    163     end 
    164  
    165  
    166     ### Return a list of archival logfiles that can be removed 
    167     ### safely. (BerkeleyDB-specific). 
    168     def archlogs 
    169         return @env.log_archive( BDB::ARCH_ABS ) 
    170163    end 
    171164 
     
    206199        # that fails, trying morphological conversion. 
    207200        entry = @index_db[ wordkey ] 
     201 
    208202        if entry.nil? && (word = self.morph( word, part_of_speech )) 
     203            wordkey = self.make_word_key( word, part_of_speech ) 
    209204            entry = @index_db[ wordkey ] 
    210205        end 
     
    396391        word = word.gsub( /\s+/, '_' ) 
    397392        return "#{word}%#{pos}" 
     393    end 
     394 
     395 
     396    ### Return a list of archival logfiles that can be removed 
     397    ### safely. (BerkeleyDB-specific). 
     398    def archlogs 
     399        return @env.log_archive( BDB::ARCH_ABS ) 
    398400    end 
    399401 
  • branches/rakefile-work/spec/wordnet/lexicon_spec.rb

    r87 r93  
    6363    ################################################################# 
    6464 
    65     it "passes a read-only flagset to BDB when created in :readonly mode" do 
     65    it "defaults to being in :readonly mode" do 
    6666        env = stub( "bdb environment handle", :open_db => nil ) 
    6767        BDB::Env.should_receive( :new ). 
     
    6969            and_return( env ) 
    7070 
    71         WordNet::Lexicon.new( @path.to_s ) 
    72     end 
    73      
    74     it "passes a read/write flagset to BDB when created in :writable mode" do 
     71        lex = WordNet::Lexicon.new( @path.to_s ) 
     72 
     73        lex.should be_readonly() 
     74        lex.should_not be_readwrite() 
     75    end 
     76     
     77    it "can be created in :writable mode" do 
    7578        env = stub( "bdb environment handle", :open_db => nil ) 
    7679        BDB::Env.should_receive( :new ). 
     
    7881            and_return( env ) 
    7982 
    80         WordNet::Lexicon.new( @path.to_s, :writable ) 
     83        lex = WordNet::Lexicon.new( @path.to_s, :writable ) 
     84 
     85        lex.should_not be_readonly() 
     86        lex.should be_readwrite() 
    8187    end 
    8288     
     
    8793            and_return( env ) 
    8894 
    89         WordNet::Lexicon.new( @path.to_s, :readwrite ) 
    90     end 
    91      
    92  
    93     describe "created in the default configuration" do 
     95        lex = WordNet::Lexicon.new( @path.to_s, :readwrite ) 
     96 
     97        lex.should_not be_readonly() 
     98        lex.should be_readwrite() 
     99    end 
     100     
     101 
     102    describe "created in readonly mode" do 
     103 
     104        before( :each ) do 
     105            @env = mock( "bdb environment handle" ) 
     106            BDB::Env.stub!( :new ).and_return( @env ) 
     107            @env.stub!( :open_db ) 
     108 
     109            @lexicon = WordNet::Lexicon.new( @path.to_s, :readonly ) 
     110        end 
     111 
     112 
     113        it "doesn't try to remove logs" do 
     114            @env.should_not_receive( :log_archive ) 
     115            @lexicon.clean_logs 
     116        end 
     117         
     118         
     119    end 
     120 
     121 
     122    describe "created in readwrite mode" do 
     123 
     124        before( :each ) do 
     125            @env = mock( "bdb environment handle" ) 
     126            BDB::Env.stub!( :new ).and_return( @env ) 
     127            @env.stub!( :open_db ) 
     128 
     129            @lexicon = WordNet::Lexicon.new( @path.to_s, :readwrite ) 
     130        end 
     131         
     132 
     133        it "can be closed" do 
     134            @env.should_receive( :close ) 
     135            @lexicon.close 
     136        end 
     137 
     138        it "provides a delegator for the checkpoint method of the underlying database" do 
     139            @env.should_receive( :checkpoint ) 
     140            @lexicon.checkpoint 
     141        end 
     142     
     143        it "provides an interface to clean up database transaction logs" do 
     144            @env.should_receive( :log_archive ).with( BDB::ARCH_ABS ). 
     145                and_return([ :log1, :log2 ]) 
     146            File.should_receive( :chmod ).with( 0777, :log1 ) 
     147            File.should_receive( :delete ).with( :log1 ) 
     148            File.should_receive( :chmod ).with( 0777, :log2 ) 
     149            File.should_receive( :delete ).with( :log2 ) 
     150             
     151            @lexicon.clean_logs 
     152        end 
     153         
     154     
     155    end 
     156     
     157 
     158    describe "with a converted WordNet database" do 
    94159 
    95160        before( :all ) do 
     
    113178         
    114179         
    115         it "returns the root word as the morphology of a dictionary word it knows about" do 
     180        it "returns the root word as the morphological conversion of a dictionary word it knows about" do 
    116181            @lexicon.morph( "angriest", WordNet::Adjective ).should == 'angry' 
    117182        end 
    118183 
    119184 
    120         it "returns nil as the morphology of a dictionary word it doesn't know about" do 
     185        it "returns nil as the morphological conversion of a dictionary word it doesn't know about" do 
    121186            @lexicon.morph( "Passomoquoddy", WordNet::Noun ).should be_nil() 
    122187        end 
     
    125190        it "returns the 'reverse morph' of dictionary words it knows about" do 
    126191            @lexicon.reverse_morph( "angry" ).should == 'angriest%a' 
     192        end 
     193 
     194 
     195        it "tries looking up a failing via its morphological conversion if the original fails" do 
     196            synsets = @lexicon.lookup_synsets( 'angriest', WordNet::Adjective ) 
     197             
     198            synsets.should_not be_nil() 
     199            synsets.first.should be_an_instance_of( WordNet::Synset ) 
     200            synsets.first.words.should include( 'angry' ) 
     201        end 
     202 
     203 
     204        it "returns only the requested sense if a sense is specified" do 
     205            synset = @lexicon.lookup_synsets( 'run', WordNet::Verb, 4 ) 
     206            synset.should be_an_instance_of( WordNet::Synset ) 
     207            synset.words.first.should =~ /operate/i 
    127208        end 
    128209         
     
    161242                should be_an_instance_of( WordNet::Synset ) 
    162243        end 
    163          
    164     end 
    165  
    166  
    167     ### Test synset creation via factory method 
    168     def test_lexicon_create_synset_should_create_a_new_synset 
    169         synset = nil 
    170  
    171         assert_nothing_raised do 
    172             synset = @lexicon.create_synset( "Ruby", WordNet::Noun ) 
    173         end 
    174         assert_instance_of WordNet::Synset, synset 
    175     end 
    176  
    177  
    178     def test_lexicon_should_be_readonly_if_opened_in_readonly_mode 
    179         make_testing_directory do |path| 
    180             lex = WordNet::Lexicon::new( path, :readwrite ).checkpoint 
    181             lex = nil 
    182              
    183             lex = WordNet::Lexicon.new( path, :readonly ) 
    184             assert_equal true, lex.readonly? 
    185             assert_equal false, lex.readwrite? 
    186         end 
    187     end 
    188  
    189  
    190     def test_lexicon_should_be_readwrite_if_opened_in_readwrite_mode 
    191         make_testing_directory do |path| 
    192             lex = WordNet::Lexicon::new( path, :readwrite ) 
    193  
    194             assert_equal false, lex.readonly? 
    195             assert_equal true, lex.readwrite? 
    196         end 
    197     end 
    198  
    199  
    200  
    201     # :TODO: Test store_synset()? 
    202  
     244 
     245    end 
    203246 
    204247end 
  • branches/rakefile-work/spec/wordnet/synset_spec.rb

    r87 r93  
    1 #!/usr/bin/ruby 
    2  
    3 require "wntestcase" 
    4 require "bdb" 
    5  
    6 class SynsetTests < WordNet::TestCase 
     1#!/usr/bin/env ruby 
     2 
     3BEGIN { 
     4    require 'pathname' 
     5    basedir = Pathname.new( __FILE__ ).dirname.parent.parent 
     6 
     7    libdir = basedir + 'lib' 
     8 
     9    $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir ) 
     10} 
     11 
     12begin 
     13    require 'fileutils' 
     14    require 'tmpdir' 
     15    require 'bdb' 
     16    require 'spec/runner' 
     17    require 'spec/lib/helpers' 
     18 
     19    require 'wordnet/lexicon' 
     20    require 'wordnet/synset' 
     21rescue LoadError 
     22    unless Object.const_defined?( :Gem ) 
     23        require 'rubygems' 
     24        retry 
     25    end 
     26    raise 
     27end 
     28 
     29 
     30##################################################################### 
     31### C O N T E X T S 
     32##################################################################### 
     33 
     34describe WordNet::Synset do 
    735 
    836    Accessors = [ 
     
    6896         
    6997 
    70     ### Make sure the Lexicon's loaded 
    71     def setup 
    72         super 
    73  
    74         @blankSyn = WordNet::Synset::new( @lexicon, "1%n", WordNet::Noun ) 
    75         @traversalSyn = @lexicon.lookup_synsets( 'linguistics', :noun, 1 ) 
    76     end 
    77  
     98    before( :each ) do 
     99        @blank_syn = WordNet::Synset::new( @lexicon, "1%n", WordNet::Noun ) 
     100        @traversal_syn = @lexicon.lookup_synsets( 'linguistics', :noun, 1 ) 
     101    end 
     102     
    78103 
    79104    #################################################################