| 1 |
# vim: set ft=python ts=4 sw=4 expandtab: |
| 2 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 3 |
# |
| 4 |
# C E D A R |
| 5 |
# S O L U T I O N S "Software done right." |
| 6 |
# S O F T W A R E |
| 7 |
# |
| 8 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 9 |
# |
| 10 |
# Copyright (c) 2007,2010,2015 Kenneth J. Pronovici. |
| 11 |
# All rights reserved. |
| 12 |
# |
| 13 |
# This program is free software; you can redistribute it and/or |
| 14 |
# modify it under the terms of the GNU General Public License, |
| 15 |
# Version 2, as published by the Free Software Foundation. |
| 16 |
# |
| 17 |
# This program is distributed in the hope that it will be useful, |
| 18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 20 |
# |
| 21 |
# Copies of the GNU General Public License are available from |
| 22 |
# the Free Software Foundation website, http://www.gnu.org/. |
| 23 |
# |
| 24 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 25 |
# |
| 26 |
# Author : Kenneth J. Pronovici <[email protected]> |
| 27 |
# Language : Python 3 |
| 28 |
# Project : Cedar Backup, release 3 |
| 29 |
# Purpose : Tests span tool functionality. |
| 30 |
# |
| 31 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 32 |
|
| 33 |
######################################################################## |
| 34 |
# Module documentation |
| 35 |
######################################################################## |
| 36 |
|
| 37 |
""" |
| 38 |
Unit tests for CedarBackup3/tools/span.py. |
| 39 |
|
| 40 |
Code Coverage |
| 41 |
============= |
| 42 |
|
| 43 |
This module contains individual tests for the many of the public functions |
| 44 |
and classes implemented in tools/span.py. Where possible, we test functions |
| 45 |
that print output by passing a custom file descriptor. Sometimes, we only |
| 46 |
ensure that a function or method runs without failure, and we don't validate |
| 47 |
what its result is or what it prints out. |
| 48 |
|
| 49 |
Naming Conventions |
| 50 |
================== |
| 51 |
|
| 52 |
I prefer to avoid large unit tests which validate more than one piece of |
| 53 |
functionality, and I prefer to avoid using overly descriptive (read: long) |
| 54 |
test names, as well. Instead, I use lots of very small tests that each |
| 55 |
validate one specific thing. These small tests are then named with an index |
| 56 |
number, yielding something like ``testAddDir_001`` or ``testValidate_010``. |
| 57 |
Each method has a docstring describing what it's supposed to accomplish. I |
| 58 |
feel that this makes it easier to judge how important a given failure is, |
| 59 |
and also makes it somewhat easier to diagnose and fix individual problems. |
| 60 |
|
| 61 |
Full vs. Reduced Tests |
| 62 |
====================== |
| 63 |
|
| 64 |
All of the tests in this module are considered safe to be run in an average |
| 65 |
build environment. There is a no need to use a SPANTESTS_FULL environment |
| 66 |
variable to provide a "reduced feature set" test suite as for some of the |
| 67 |
other test modules. |
| 68 |
|
| 69 |
@author Kenneth J. Pronovici <[email protected]> |
| 70 |
""" |
| 71 |
|
| 72 |
|
| 73 |
######################################################################## |
| 74 |
# Import modules and do runtime validations |
| 75 |
######################################################################## |
| 76 |
|
| 77 |
import unittest |
| 78 |
|
| 79 |
from CedarBackup3.testutil import captureOutput, configureLogging |
| 80 |
from CedarBackup3.tools.span import Options, _usage, _version |
| 81 |
|
| 82 |
####################################################################### |
| 83 |
# Test Case Classes |
| 84 |
####################################################################### |
| 85 |
|
| 86 |
###################### |
| 87 |
# TestFunctions class |
| 88 |
###################### |
| 89 |
|
| 90 |
|
| 91 |
class TestFunctions(unittest.TestCase): |
| 92 |
"""Tests for the public functions.""" |
| 93 |
|
| 94 |
################ |
| 95 |
# Setup methods |
| 96 |
################ |
| 97 |
|
| 98 |
@classmethod |
| 99 |
def setUpClass(cls): |
| 100 |
configureLogging() |
| 101 |
|
| 102 |
def setUp(self): |
| 103 |
pass |
| 104 |
|
| 105 |
def tearDown(self): |
| 106 |
pass |
| 107 |
|
| 108 |
######################## |
| 109 |
# Test simple functions |
| 110 |
######################## |
| 111 |
|
| 112 |
def testSimpleFuncs_001(self): |
| 113 |
""" |
| 114 |
Test that the _usage() function runs without errors. |
| 115 |
We don't care what the output is, and we don't check. |
| 116 |
""" |
| 117 |
captureOutput(_usage) |
| 118 |
|
| 119 |
def testSimpleFuncs_002(self): |
| 120 |
""" |
| 121 |
Test that the _version() function runs without errors. |
| 122 |
We don't care what the output is, and we don't check. |
| 123 |
""" |
| 124 |
captureOutput(_version) |
| 125 |
|
| 126 |
|
| 127 |
######################## |
| 128 |
# TestSpanOptions class |
| 129 |
######################## |
| 130 |
|
| 131 |
|
| 132 |
class TestSpanOptions(unittest.TestCase): |
| 133 |
"""Tests for the SpanOptions class.""" |
| 134 |
|
| 135 |
################ |
| 136 |
# Setup methods |
| 137 |
################ |
| 138 |
|
| 139 |
@classmethod |
| 140 |
def setUpClass(cls): |
| 141 |
configureLogging() |
| 142 |
|
| 143 |
def setUp(self): |
| 144 |
pass |
| 145 |
|
| 146 |
def tearDown(self): |
| 147 |
pass |
| 148 |
|
| 149 |
############################ |
| 150 |
# Test __repr__ and __str__ |
| 151 |
############################ |
| 152 |
|
| 153 |
def testStringFuncs_001(self): |
| 154 |
""" |
| 155 |
Just make sure that the string functions don't have errors (i.e. bad variable names). |
| 156 |
""" |
| 157 |
obj = Options() |
| 158 |
obj.__repr__() |
| 159 |
obj.__str__() |