Ejemplo n.º 1
0
 def testArgPassing(self):
   expected = os.path.join('part1', 'part2', 'part3')
   with self.assertOutputMatches('%s\n' % expected):
     __main__.main(
         ['__main__.py', 'os.path', 'join', 'part1', 'part2', 'part3'])
   with self.assertOutputMatches('%s\n' % expected):
     __main__.main(
         ['__main__.py', 'os', 'path', '-', 'join', 'part1', 'part2', 'part3'])
Ejemplo n.º 2
0
 def testArgPassing(self):
     expected = os.path.join("part1", "part2", "part3")
     with self.assertOutputMatches("%s\n" % expected):
         __main__.main(
             ["__main__.py", "os.path", "join", "part1", "part2", "part3"])
     with self.assertOutputMatches("%s\n" % expected):
         __main__.main([
             "__main__.py", "os", "path", "-", "join", "part1", "part2",
             "part3"
         ])
Ejemplo n.º 3
0
  def testFileNameModuleDuplication(self):
    # Confirm that a file that masks a module still loads the module.
    with self.assertOutputMatches('gettempdir'):
      dirname = os.path.dirname(self.file.name)
      with testutils.ChangeDirectory(dirname):
        with open('tempfile', 'w'):
          __main__.main([
              '__main__.py',
              'tempfile',
          ])

        os.remove('tempfile')
Ejemplo n.º 4
0
  def testFileNameModuleFileFailure(self):
    # Confirm that an invalid file that masks a non-existent module fails.
    with self.assertRaisesRegex(ValueError,
                                r'Fire can only be called on \.py files\.'):  # pylint: disable=line-too-long,  # pytype: disable=attribute-error
      dirname = os.path.dirname(self.file.name)
      with testutils.ChangeDirectory(dirname):
        with open('foobar', 'w'):
          __main__.main([
              '__main__.py',
              'foobar',
          ])

        os.remove('foobar')
Ejemplo n.º 5
0
 def testFileNameFailure(self):
   # Confirm that an existing file without a .py suffix raises a ValueError.
   with self.assertRaises(ValueError):
     __main__.main(
         ['__main__.py', self.file2.name, 'Foo', 'double', '--n', '2'])
Ejemplo n.º 6
0
 def testFileNameFire(self):
   # Confirm that the file is correctly imported and doubles the number.
   with self.assertOutputMatches('4'):
     __main__.main(
         ['__main__.py', self.file.name, 'Foo', 'double', '--n', '2'])
Ejemplo n.º 7
0
 def testNameSetting(self):
   # Confirm one of the usage lines has the gettempdir member.
   with self.assertOutputMatches('gettempdir'):
     __main__.main(['__main__.py', 'tempfile'])
Ejemplo n.º 8
0
 def testFileNameFailure(self):
     # Confirm that an existing file without a .py suffix raises a ValueError.
     with self.assertRaises(ValueError):
         __main__.main(
             ["__main__.py", self.file2.name, "Foo", "double", "--n", "2"])
Ejemplo n.º 9
0
 def testFileNameFire(self):
     # Confirm that the file is correctly imported and doubles the number.
     with self.assertOutputMatches("4"):
         __main__.main(
             ["__main__.py", self.file.name, "Foo", "double", "--n", "2"])
Ejemplo n.º 10
0
 def testNameSetting(self):
     # Confirm one of the usage lines has the gettempdir member.
     with self.assertOutputMatches("gettempdir"):
         __main__.main(["__main__.py", "tempfile"])