~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/python-gflags/test_module_foo.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# Copyright (c) 2009, Google Inc.
 
4
# All rights reserved.
 
5
#
 
6
# Redistribution and use in source and binary forms, with or without
 
7
# modification, are permitted provided that the following conditions are
 
8
# met:
 
9
#
 
10
#     * Redistributions of source code must retain the above copyright
 
11
# notice, this list of conditions and the following disclaimer.
 
12
#     * Redistributions in binary form must reproduce the above
 
13
# copyright notice, this list of conditions and the following disclaimer
 
14
# in the documentation and/or other materials provided with the
 
15
# distribution.
 
16
#     * Neither the name of Google Inc. nor the names of its
 
17
# contributors may be used to endorse or promote products derived from
 
18
# this software without specific prior written permission.
 
19
#
 
20
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
21
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
22
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
23
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
24
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
25
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
26
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
27
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
28
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
29
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
30
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
31
 
 
32
"""Auxiliary module for testing flags.py.
 
33
 
 
34
The purpose of this module is to define a few flags, and declare some
 
35
other flags as being important.  We want to make sure the unit tests
 
36
for flags.py involve more than one module.
 
37
"""
 
38
 
 
39
__author__ = 'Alex Salcianu'
 
40
 
 
41
__pychecker__ = "no-local" # for unittest
 
42
 
 
43
# We use the name 'flags' internally in this test, for historical reasons.
 
44
# Don't do this yourself! :-) Just do 'import gflags; FLAGS=gflags.FLAGS; etc'
 
45
import gflags as flags
 
46
FLAGS = flags.FLAGS
 
47
 
 
48
# For historical reasons we use the name module_bar instead of test_module_bar.
 
49
import test_module_bar as module_bar
 
50
 
 
51
DECLARED_KEY_FLAGS = ['tmod_bar_x', 'tmod_bar_z', 'tmod_bar_t']
 
52
 
 
53
 
 
54
def DefineFlags():
 
55
  """Defines a few flags."""
 
56
  module_bar.DefineFlags()
 
57
  # The 'tmod_foo_' prefix (short for 'test_module_foo') ensures that we
 
58
  # have no name clash with existing flags.
 
59
  flags.DEFINE_boolean('tmod_foo_bool', True, 'Boolean flag from module foo.')
 
60
  flags.DEFINE_string('tmod_foo_str', 'default', 'String flag.')
 
61
  flags.DEFINE_integer('tmod_foo_int', 3, 'Sample int flag.')
 
62
 
 
63
 
 
64
def DeclareKeyFlags():
 
65
  """Declares a few key flags."""
 
66
  for flag_name in DECLARED_KEY_FLAGS:
 
67
    flags.DECLARE_key_flag(flag_name)
 
68
 
 
69
 
 
70
def DeclareExtraKeyFlags():
 
71
  """Declares some extra key flags."""
 
72
  flags.ADOPT_module_key_flags(module_bar)
 
73
 
 
74
 
 
75
def NamesOfDefinedFlags():
 
76
  """Returns: list of names of flags defined by this module."""
 
77
  return ['tmod_foo_bool', 'tmod_foo_str', 'tmod_foo_int']
 
78
 
 
79
 
 
80
def NamesOfDeclaredKeyFlags():
 
81
  """Returns: list of names of key flags for this module."""
 
82
  return NamesOfDefinedFlags() + DECLARED_KEY_FLAGS
 
83
 
 
84
 
 
85
def NamesOfDeclaredExtraKeyFlags():
 
86
  """Returns the list of names of additional key flags for this module.
 
87
 
 
88
  These are the flags that became key for this module only as a result
 
89
  of a call to DeclareExtraKeyFlags() above.  I.e., the flags declared
 
90
  by module_bar, that were not already declared as key for this
 
91
  module.
 
92
 
 
93
  Returns:
 
94
    The list of names of additional key flags for this module.
 
95
  """
 
96
  names_of_extra_key_flags = list(module_bar.NamesOfDefinedFlags())
 
97
  for flag_name in NamesOfDeclaredKeyFlags():
 
98
    while flag_name in names_of_extra_key_flags:
 
99
      names_of_extra_key_flags.remove(flag_name)
 
100
  return names_of_extra_key_flags
 
101
 
 
102
 
 
103
def RemoveFlags():
 
104
  """Deletes the flag definitions done by the above DefineFlags()."""
 
105
  for flag_name in NamesOfDefinedFlags():
 
106
    module_bar.RemoveOneFlag(flag_name)
 
107
  module_bar.RemoveFlags()
 
108
 
 
109
 
 
110
def GetModuleName():
 
111
  """Uses flags._GetCallingModule() to return the name of this module.
 
112
 
 
113
  For checking that _GetCallingModule works as expected.
 
114
 
 
115
  Returns:
 
116
    A string, the name of this module.
 
117
  """
 
118
  # Calling the protected _GetCallingModule generates a lint warning,
 
119
  # but we do not have any other alternative to test that function.
 
120
  return flags._GetCallingModule()