Show
Ignore:
Timestamp:
07/11/08 17:56:49 (5 months ago)
Author:
deveiant
Message:
  • Synched Rakefile with rake-tasklibs
  • Started conversion of synset tests to specs
  • Finished converting lexicon tests to specs
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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