code: def test_gnu_getopt(self):
      # Test handling of GNU style scanning mode.
      cmdline = ["-a", "arg1", "-b", "1", "--alpha", "--beta=2"]
  
      # GNU style
      opts, args = getopt.gnu_getopt(cmdline, "ab:", ["alpha", "beta="])
      self.assertEqual(args, ["arg1"])
      self.assertEqual(
          opts,
          [("-a", ""), ("-b", "1"), ("--alpha", ""), ("--beta", "2")],
      )
  
      # recognize "-" as an argument
      opts, args = getopt.gnu_getopt(["-a", "-", "-b", "-"], "ab:", [])
      self.assertEqual(args, ["-"])
      self.assertEqual(opts, [("-a", ""), ("-b", "-")])
  
      # Posix style via +
      opts, args = getopt.gnu_getopt(
          cmdline, "+ab:", ["alpha", "beta="]
      )
      self.assertEqual(opts, [("-a", "")])
      self.assertEqual(args, ["arg1", "-b", "1", "--alpha", "--beta=2"])
  
      # Posix style via POSIXLY_CORRECT
      self.env["POSIXLY_CORRECT"] = "1"
      opts, args = getopt.gnu_getopt(cmdline, "ab:", ["alpha", "beta="])
      self.assertEqual(opts, [("-a", "")])
      self.assertEqual(args, ["arg1", "-b", "1", "--alpha", "--beta=2"])
  
file_path: cpython/Lib/test/test_getopt.py
imports: from test.support.os_helper import EnvironmentVarGuard
  import doctest
  import unittest
  import getopt
label_desc: Use image node_id 8 for calling the GetoptTests obj's underlying member method code with example usage: obj.test_gnu_getopt() without return types