Пример #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'])
Пример #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"
         ])
Пример #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')
Пример #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')
Пример #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'])
Пример #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'])
Пример #7
0
 def testNameSetting(self):
   # Confirm one of the usage lines has the gettempdir member.
   with self.assertOutputMatches('gettempdir'):
     __main__.main(['__main__.py', 'tempfile'])
Пример #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"])
Пример #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"])
Пример #10
0
 def testNameSetting(self):
     # Confirm one of the usage lines has the gettempdir member.
     with self.assertOutputMatches("gettempdir"):
         __main__.main(["__main__.py", "tempfile"])