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')
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')