Skip to content

Commit

Permalink
Use tempfile.mkdtemp instead of tempfile.mktemp to create directo…
Browse files Browse the repository at this point in the history
…ries.

The `tempfile.mktemp` function is [deprecated](https://docs.python.org/3/library/tempfile.html#tempfile.mktemp) due to [security issues](https://cwe.mitre.org/data/definitions/377.html).

The switch is easy to do: just a name change

PiperOrigin-RevId: 420370858
Change-Id: I44a0849d161132eacd4f3881fdb615e09c0f02a2
  • Loading branch information
mihaimaruseac committed Jan 25, 2022
1 parent 5154429 commit 74cc54e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions tensorflow/python/debug/lib/debug_data_test.py
Expand Up @@ -147,8 +147,7 @@ def testDumpSizeBytesIsNoneForNonexistentFilePath(self):
class DebugDumpDirTest(test_util.TensorFlowTestCase):

def setUp(self):
self._dump_root = tempfile.mktemp()
os.mkdir(self._dump_root)
self._dump_root = tempfile.mkdtemp()

def tearDown(self):
# Tear down temporary dump directory.
Expand Down Expand Up @@ -179,7 +178,7 @@ def _makeDataDirWithMultipleDevicesAndDuplicateNodeNames(self):

def testDebugDumpDir_nonexistentDumpRoot(self):
with self.assertRaisesRegex(IOError, "does not exist"):
debug_data.DebugDumpDir(tempfile.mktemp() + "_foo")
debug_data.DebugDumpDir(tempfile.mkdtemp() + "_foo")

def testDebugDumpDir_invalidFileNamingPattern(self):
# File name with too few underscores should lead to an exception.
Expand Down

0 comments on commit 74cc54e

Please sign in to comment.