[Logging-commits] r67 - in oo/pkg: . R inst/unitTest man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Apr 15 16:07:54 CEST 2011


Author: mariotomo
Date: 2011-04-15 16:07:54 +0200 (Fri, 15 Apr 2011)
New Revision: 67

Modified:
   oo/pkg/DESCRIPTION
   oo/pkg/NAMESPACE
   oo/pkg/R/methods.R
   oo/pkg/inst/unitTest/runit.data.interaction.R
   oo/pkg/man/Logger.Rd
Log:
adapted unit testing to logging.oo


Modified: oo/pkg/DESCRIPTION
===================================================================
--- oo/pkg/DESCRIPTION	2011-04-15 13:46:28 UTC (rev 66)
+++ oo/pkg/DESCRIPTION	2011-04-15 14:07:54 UTC (rev 67)
@@ -1,5 +1,5 @@
 Package: logging.oo
-Version: 0.5-65
+Version: 0.5-66
 Date: 2010-06-17
 Title: oo interface for the logging package
 Author: Mario Frasca <mariotomo at gmail.com>

Modified: oo/pkg/NAMESPACE
===================================================================
--- oo/pkg/NAMESPACE	2011-04-15 13:46:28 UTC (rev 66)
+++ oo/pkg/NAMESPACE	2011-04-15 14:07:54 UTC (rev 67)
@@ -1,3 +1,4 @@
 # $Id: NAMESPACE 61 2011-02-11 11:34:43Z mariotomo $
-export(Logger
+export(Logger,
+       getLogger
        )

Modified: oo/pkg/R/methods.R
===================================================================
--- oo/pkg/R/methods.R	2011-04-15 13:46:28 UTC (rev 66)
+++ oo/pkg/R/methods.R	2011-04-15 14:07:54 UTC (rev 67)
@@ -42,3 +42,6 @@
                         info = function(...) { log(loglevels["INFO"], ...) },
                         warn = function(...) { log(loglevels["WARN"], ...) },
                         error = function(...) { log(loglevels["ERROR"], ...) }))
+
+getLogger <- function(name = "")
+  Logger$new(name)

Modified: oo/pkg/inst/unitTest/runit.data.interaction.R
===================================================================
--- oo/pkg/inst/unitTest/runit.data.interaction.R	2011-04-15 13:46:28 UTC (rev 66)
+++ oo/pkg/inst/unitTest/runit.data.interaction.R	2011-04-15 14:07:54 UTC (rev 67)
@@ -4,63 +4,49 @@
 # $Id$
 
 test.000.getLoggerWithoutInitializingDoesNotCrash <- function() {
-  rootLogger <- getLogger("")
+  rootLogger <- Logger$new("")
 }
 
 test.001.defaultLoggingLevelIsINFO <- function() {
   basicConfig()
-  rootLogger <- getLogger('')
+  root <- Logger$new('')
   expect <- logging:::loglevels['INFO']
-  checkEquals(rootLogger[['level']], expect)
+  checkEquals(root[['level']], expect)
 }
 
 test.002.canInitializeTwice <- function() {
   basicConfig()
-  rootLogger <- getLogger('')
+  root <- Logger$new('')
   expect <- logging:::loglevels['INFO']
-  checkEquals(rootLogger[['level']], expect)
+  checkEquals(root[['level']], expect)
 }
 
 # end of functions that must be tested first
 
 test.canGetRootLoggerWithoutName <- function() {
-  rootLogger1 <- getLogger('')
-  rootLogger2 <- getLogger()
-  checkEquals(rootLogger1, rootLogger2)
+  root1 <- Logger$new('')
+  root2 <- Logger$new()
+  checkEquals(root1, root2)
 }
 
-test.canFindLoggingLevels <- function() {
-  checkEquals(logging:::loglevels[['NOTSET']], 0)
-  checkEquals(logging:::loglevels[['DEBUG']], 10)
-  checkEquals(logging:::loglevels[['INFO']], 20)
-  checkEquals(logging:::loglevels[['WARN']], 30)
-  checkEquals(logging:::loglevels[['ERROR']], 40)
-  checkEquals(logging:::loglevels[['FATAL']], 50)
-}
-
-test.fineLevelsAreOrdered <- function() {
-  checkEquals(logging:::loglevels[['FINEST']] < logging:::loglevels[['FINER']], TRUE)
-  checkEquals(logging:::loglevels[['FINER']] < logging:::loglevels[['FINE']], TRUE)
-  checkEquals(logging:::loglevels[['FINE']] < logging:::loglevels[['DEBUG']], TRUE)
-}
-
 test.canSetLoggerLevelByNamedValue <- function() {
   basicConfig()
-  setLevel(logging:::loglevels['DEBUG'], '')
-  rootLogger <- getLogger('')
+  root <- Logger$new('')
+  root$setLevel(logging:::loglevels['DEBUG'])
   expect <- logging:::loglevels['DEBUG']
-  checkEquals(rootLogger[['level']], expect)
+  checkEquals(root[['level']], expect)
 }
 
 test.canSetLoggerLevelByName <- function() {
   basicConfig()
-  setLevel('DEBUG', '')
-  rootLogger <- getLogger('')
+  root <- getLogger('')
+  root$setLevel('DEBUG')
   expect <- logging:::loglevels['DEBUG']
-  checkEquals(rootLogger[['level']], expect)
+  checkEquals(root[['level']], expect)
 }
 
 logged <- NULL
+
 mockAction <- function(msg, handler) {
   logged <<- c(logged, msg)
 }
@@ -71,117 +57,134 @@
 
 test.recordIsEmitted.rootToRoot <- function() {
   logReset()
-  addHandler(mockAction)
+  log <- getLogger('test')
+  log$addHandler(mockAction)
   logged <<- NULL
-  logdebug('test')
-  loginfo('test')
-  logerror('test')
+  log$debug('test')
+  log$info('test')
+  log$error('test')
   checkEquals(2, length(logged))
 }
 
 test.recordIsEmitted.tooDeep <- function() {
   logReset()
-  addHandler(mockAction, logger='too.deep')
+  root <- getLogger('')
+  log2 <- getLogger('too.deep')
+  log2$addHandler(mockAction)
   logged <<- NULL
-  logdebug('test')
-  loginfo('test')
-  logerror('test')
+  root$debug('test')
+  root$info('test')
+  root$error('test')
   checkEquals(0, length(logged))
 }
 
 test.recordIsEmitted.unrelated <- function() {
   logReset()
-  addHandler(mockAction, logger='too.deep')
+  log1 <- getLogger('other.branch')
+  log2 <- getLogger('too.deep')
+  log2$addHandler(mockAction)
   logged <<- NULL
-  logdebug('test', logger='other.branch')
-  loginfo('test', logger='other.branch')
-  logerror('test', logger='other.branch')
+  log1$debug('test', logger='other.branch')
+  log1$info('test', logger='other.branch')
+  log1$error('test', logger='other.branch')
   checkEquals(0, length(logged))
 }
 
 test.recordIsEmitted.deepToRoot <- function() {
   logReset()
-  addHandler(mockAction, logger='')
+  root <- getLogger('')
+  log <- getLogger('other.branch')
+  root$addHandler(mockAction)
   logged <<- NULL
-  logdebug('test', logger='other.branch')
-  loginfo('test', logger='other.branch')
-  logerror('test', logger='other.branch')
+  log$debug('test')
+  log$info('test')
+  log$error('test')
   checkEquals(2, length(logged))
 }
 
 test.recordIsEmitted.deepToRoot.DI.dropped <- function() {
   logReset()
-  addHandler(mockAction, level='DEBUG', logger='')
+  root <- getLogger('')
+  log <- getLogger('other.branch')
+  root$addHandler(mockAction, level='DEBUG')
   logged <<- NULL
-  setLevel('other.branch', 'INFO')
-  logdebug('test', logger='other.branch')
-  loginfo('test', logger='other.branch')
-  logerror('test', logger='other.branch')
+  log$setLevel('INFO')
+  log$debug('test')
+  log$info('test')
+  log$error('test')
   checkEquals(2, length(logged))
 }
 
 test.recordIsEmitted.deepToRoot.DD.passed <- function() {
   logReset()
-  addHandler(mockAction, level='DEBUG', logger='')
+  root <- getLogger('')
+  log <- getLogger('other.branch')
+  root$addHandler(mockAction, level='DEBUG')
   logged <<- NULL
-  setLevel('DEBUG', 'other.branch')
-  setLevel('DEBUG', '')
-  logdebug('test', logger='other.branch')
-  loginfo('test', logger='other.branch')
-  logerror('test', logger='other.branch')
+  log$setLevel('DEBUG')
+  root$setLevel('DEBUG')
+  log$debug('test')
+  log$info('test')
+  log$error('test')
   checkEquals(3, length(logged))
 }
 
 test.formattingRecord.lengthZero <- function() {
   logReset()
-  addHandler(mockAction, level='DEBUG', logger='', formatter=mockFormatter)
+  log <- getLogger('')
+  log$addHandler(mockAction, level='DEBUG', formatter=mockFormatter)
   logged <<- NULL
-  loginfo("test '%s'", numeric(0))
+  log$info("test '%s'", numeric(0))
   checkEquals("INFO::test ''", logged)
 }
 
 test.formattingRecord.lengthOne <- function() {
   logReset()
-  addHandler(mockAction, level='DEBUG', logger='', formatter=mockFormatter)
+  log <- getLogger()
+  log$addHandler(mockAction, level='DEBUG', formatter=mockFormatter)
   logged <<- NULL
-  loginfo("test '%s'", 12)
+  log$info("test '%s'", 12)
   checkEquals("INFO::test '12'", logged)
 }
 
 test.formattingRecord.lengthMore <- function() {
   logReset()
-  addHandler(mockAction, level='DEBUG', logger='', formatter=mockFormatter)
+  log <- getLogger()
+  addHandler(mockAction, level='DEBUG', formatter=mockFormatter)
   logged <<- NULL
-  loginfo("test '%s'", c(0, 1, 2))
+  log$info("test '%s'", c(0, 1, 2))
   checkEquals("INFO::test '0,1,2'", logged)
 }
 
 test.formattingRecord.moreArguments <- function() {
   logReset()
-  addHandler(mockAction, level='DEBUG', logger='', formatter=mockFormatter)
+  log <- getLogger()
+  log$addHandler(mockAction, level='DEBUG', formatter=mockFormatter)
   logged <<- NULL
-  loginfo("%s: %d", 'name', 123)
+  log$info("%s: %d", 'name', 123)
   checkEquals("INFO::name: 123", logged)
   logged <<- NULL
-  loginfo("%s: %0.2f", 'name', 123.0)
+  log$info("%s: %0.2f", 'name', 123.0)
   checkEquals("INFO::name: 123.00", logged)
 }
 
 test.formattingRecord.moreArguments.lengthMore <- function() {
   logReset()
-  addHandler(mockAction, level='DEBUG', logger='', formatter=mockFormatter)
+  log <- getLogger()
+  log$addHandler(mockAction, level='DEBUG', formatter=mockFormatter)
   logged <<- NULL
-  loginfo("%s '%s'", 'name', c(0, 1, 2))
+  log$info("%s '%s'", 'name', c(0, 1, 2))
   checkEquals("INFO::name '0,1,2'", logged)
 }
 
 test.formattingRecord.strips.whitespace <- function() {
   logReset()
-  addHandler(mockAction, level='DEBUG', logger='', formatter=mockFormatter)
+  log <- getLogger()
+  log$addHandler(mockAction, level='DEBUG', formatter=mockFormatter)
   logged <<- NULL
-  loginfo("a string with trailing whitespace \n")
+  log$info("a string with trailing whitespace \n")
   checkEquals("INFO::a string with trailing whitespace", logged)
   logged <<- NULL
-  loginfo("  this string has also leading whitespace   ")
+  log$info("  this string has also leading whitespace   ")
   checkEquals("INFO::this string has also leading whitespace", logged)
 }

Modified: oo/pkg/man/Logger.Rd
===================================================================
--- oo/pkg/man/Logger.Rd	2011-04-15 13:46:28 UTC (rev 66)
+++ oo/pkg/man/Logger.Rd	2011-04-15 14:07:54 UTC (rev 67)
@@ -3,6 +3,7 @@
 
 \name{Logger}
 \alias{Logger}
+\alias{getLogger}
 \title{the `Logger` reference class}
 \description{
 
@@ -11,6 +12,7 @@
 }
 \usage{
 logger <- Logger$new(name=name)
+logger <- getLogger(name=name)
 }
 \arguments{
   \item{name}{the name of the logger}



More information about the Logging-commits mailing list