def test_get_flags_for_module(self):
        fv = _flagvalues.FlagValues()
        _defines.DEFINE_string('foo', None, 'help', flag_values=fv)
        module_foo.define_flags(fv)
        flags = fv.get_flags_for_module('__main__')

        self.assertEqual({'foo'}, {flag.name for flag in flags})

        flags = fv.get_flags_for_module(module_foo)
        self.assertEqual({'tmod_foo_bool', 'tmod_foo_int', 'tmod_foo_str'},
                         {flag.name
                          for flag in flags})
 def test_str(self):
     fv = _flagvalues.FlagValues()
     self.assertEqual(str(fv), fv.get_help())
     module_foo.define_flags(fv)
     self.assertEqual(str(fv), fv.get_help())
    def test_get_help(self):
        fv = _flagvalues.FlagValues()
        self.assertMultiLineEqual(
            '''\
--flagfile: Insert flag definitions from the given file into the command line.
  (default: '')
--undefok: comma-separated list of flag names that it is okay to specify on the
  command line even if the program does not define a flag with that name.
  IMPORTANT: flags in this list that have arguments MUST use the --flag=value
  format.
  (default: '')''', fv.get_help())

        module_foo.define_flags(fv)
        self.assertMultiLineEqual(
            '''
absl.flags.tests.module_bar:
  --tmod_bar_t: Sample int flag.
    (default: '4')
    (an integer)
  --tmod_bar_u: Sample int flag.
    (default: '5')
    (an integer)
  --tmod_bar_v: Sample int flag.
    (default: '6')
    (an integer)
  --[no]tmod_bar_x: Boolean flag.
    (default: 'true')
  --tmod_bar_y: String flag.
    (default: 'default')
  --[no]tmod_bar_z: Another boolean flag from module bar.
    (default: 'false')

absl.flags.tests.module_foo:
  --[no]tmod_foo_bool: Boolean flag from module foo.
    (default: 'true')
  --tmod_foo_int: Sample int flag.
    (default: '3')
    (an integer)
  --tmod_foo_str: String flag.
    (default: 'default')

absl.flags:
  --flagfile: Insert flag definitions from the given file into the command line.
    (default: '')
  --undefok: comma-separated list of flag names that it is okay to specify on
    the command line even if the program does not define a flag with that name.
    IMPORTANT: flags in this list that have arguments MUST use the --flag=value
    format.
    (default: '')''', fv.get_help())

        self.assertMultiLineEqual(
            '''
xxxxabsl.flags.tests.module_bar:
xxxx  --tmod_bar_t: Sample int flag.
xxxx    (default: '4')
xxxx    (an integer)
xxxx  --tmod_bar_u: Sample int flag.
xxxx    (default: '5')
xxxx    (an integer)
xxxx  --tmod_bar_v: Sample int flag.
xxxx    (default: '6')
xxxx    (an integer)
xxxx  --[no]tmod_bar_x: Boolean flag.
xxxx    (default: 'true')
xxxx  --tmod_bar_y: String flag.
xxxx    (default: 'default')
xxxx  --[no]tmod_bar_z: Another boolean flag from module bar.
xxxx    (default: 'false')

xxxxabsl.flags.tests.module_foo:
xxxx  --[no]tmod_foo_bool: Boolean flag from module foo.
xxxx    (default: 'true')
xxxx  --tmod_foo_int: Sample int flag.
xxxx    (default: '3')
xxxx    (an integer)
xxxx  --tmod_foo_str: String flag.
xxxx    (default: 'default')

xxxxabsl.flags:
xxxx  --flagfile: Insert flag definitions from the given file into the command
xxxx    line.
xxxx    (default: '')
xxxx  --undefok: comma-separated list of flag names that it is okay to specify
xxxx    on the command line even if the program does not define a flag with that
xxxx    name.  IMPORTANT: flags in this list that have arguments MUST use the
xxxx    --flag=value format.
xxxx    (default: '')''', fv.get_help(prefix='xxxx'))

        self.assertMultiLineEqual(
            '''
absl.flags.tests.module_bar:
  --tmod_bar_t: Sample int flag.
    (default: '4')
    (an integer)
  --tmod_bar_u: Sample int flag.
    (default: '5')
    (an integer)
  --tmod_bar_v: Sample int flag.
    (default: '6')
    (an integer)
  --[no]tmod_bar_x: Boolean flag.
    (default: 'true')
  --tmod_bar_y: String flag.
    (default: 'default')
  --[no]tmod_bar_z: Another boolean flag from module bar.
    (default: 'false')

absl.flags.tests.module_foo:
  --[no]tmod_foo_bool: Boolean flag from module foo.
    (default: 'true')
  --tmod_foo_int: Sample int flag.
    (default: '3')
    (an integer)
  --tmod_foo_str: String flag.
    (default: 'default')''', fv.get_help(include_special_flags=False))