diff options
author | Abseil Team <absl-team@google.com> | 2018-11-26 10:40:27 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-11-26 10:40:39 -0800 |
commit | 1193ccf0c81e722723be5376e6ed1d198ea506bb (patch) | |
tree | 13cc59088d94b79712dd81daa09e1b9af4ab3682 /absl/tests | |
parent | bb3a213b7705abff1043ae4df3ac98e2962a35da (diff) | |
download | absl-py-1193ccf0c81e722723be5376e6ed1d198ea506bb.tar.gz |
Make absl python help flags closer to cpp versions
- Passing --nohelp or --help=false should not display help messages
- Serializing and re-parsing an empty argv should not spontaneously invoke help and exit (due to a false-ish --nohelp being externalized and re-passed, causing the above)
PiperOrigin-RevId: 222848707
Diffstat (limited to 'absl/tests')
-rw-r--r-- | absl/tests/app_test.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/absl/tests/app_test.py b/absl/tests/app_test.py index 9fca67f..261c665 100644 --- a/absl/tests/app_test.py +++ b/absl/tests/app_test.py @@ -306,5 +306,37 @@ class FunctionalTests(absltest.TestCase): self.assertIn('during real_main', stdout) +class FlagValuesExternalizationTest(absltest.TestCase): + """Test to make sure FLAGS can be serialized out and parsed back in.""" + + @flagsaver.flagsaver + def test_nohelp_doesnt_show_help(self): + with self.assertRaisesWithPredicateMatch(SystemExit, + lambda e: e.code == 1): + app.run( + len, + argv=[ + './program', '--nohelp', '--helpshort=false', '--helpfull=0', + '--helpxml=f' + ]) + + @flagsaver.flagsaver + def test_serialize_roundtrip(self): + # Use the global 'FLAGS' as the source, to ensure all the framework defined + # flags will go through the round trip process. + flags.DEFINE_string('testflag', 'testval', 'help', flag_values=FLAGS) + + new_flag_values = flags.FlagValues() + new_flag_values.append_flag_values(FLAGS) + + FLAGS.testflag = 'roundtrip_me' + argv = ['binary_name'] + FLAGS.flags_into_string().splitlines() + + self.assertNotEqual(new_flag_values['testflag'], FLAGS.testflag) + new_flag_values(argv) + self.assertEqual(new_flag_values.testflag, FLAGS.testflag) + del FLAGS.testflag + + if __name__ == '__main__': absltest.main() |