Bake-off Code 1

Here's the unit test for the top-level procedure for the Python version. (I drifted from the original design.) test-g2o.py

#!/usr/bin/env python
import unittest
from mock import Mock
import g2o
from calendar import Calendar

class TestSynch(unittest.TestCase):

def test_synchCalendars(self):
mGoogleCalendar = Mock({"merge":Calendar})
mOutlookCalendar = Mock({"merge":Calendar})
mOutlookCalendar.mockAddReturnValues(assign=mOutlookCalendar)
mGoogleCalendar .mockAddReturnValues(assign=mGoogleCalendar)

assert g2o.synchCalendars(mGoogleCalendar, mOutlookCalendar),
              "synch failed"

unittest.main()

... and the comparable Ruby edition test-g2o.rb

#!/usr/bin/env ruby
require 'test/unit' unless defined? $ZENTEST
require 'test/unit/mock' unless defined? $ZENTEST
require 'g2o'

class TestSynch < Test::Unit::TestCase

def test_synchCalendars

mGoogleCalendar = Test::Unit::MockObject(GoogleCalendar).new
mGoogleCalendar.setReturnValues(:assign=>mGoogleCalendar, :merge=>Proc::new {Calendar.new})
mGoogleCalendar.activate

mOutlookCalendar = Test::Unit::MockObject(OutlookCalendar).new
mOutlookCalendar.setReturnValues(:assign=>mOutlookCalendar, :merge=>Proc::new {Calendar.new})
mOutlookCalendar.activate

assert synchCalendars(mGoogleCalendar, mOutlookCalendar)
end
end

Now the main functions: g2o.py
#!/usr/bin/env python
from outlook.ocalendar import OutlookCalendar
from google.gcalendar import GoogleCalendar

def synchCalendars(gooCal, outCal):
result = gooCal.merge(outCal) # Could just as well have done outCal.merge
gooCal.assign(result).persist
outCal.assign(result).persist
return True

g2o.rb

#!/usr/bin/env ruby
require 'outlook/ocalendar'
require 'google/gcalendar'

def synchCalendars(gooCal, outCal)
result = gooCal.merge(outCal) # Could just as well have done outCal.merge
gooCal.assign(result).persist
outCal.assign(result).persist
return true
end

The Outlook and Google calendar classes are just empty class stubs at this point. I'll show them once they have some code in them. I'm interested in hearing from Ruby or Python programmers with tips on how to make these more Ruby-ish or Pythonic. More code coming soon.

Add new comment