From e95e7462c4db6b9f6d00a080f13245c206bce54b Mon Sep 17 00:00:00 2001 From: parsa shahmaleki Date: Mon, 8 Mar 2021 16:22:28 +0330 Subject: [PATCH 1/3] bpo-43432: add function `clear` to module `os` --- Lib/os.py | 7 +++++++ Lib/test/test_os.py | 8 ++++++++ .../next/Library/2021-03-08-16-08-15.bpo-43432.Aq20oZ.rst | 3 +++ 3 files changed, 18 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2021-03-08-16-08-15.bpo-43432.Aq20oZ.rst diff --git a/Lib/os.py b/Lib/os.py index 05e9c32c5a71177..07150e60bdd284f 100644 --- a/Lib/os.py +++ b/Lib/os.py @@ -1118,3 +1118,10 @@ def add_dll_directory(path): cookie, nt._remove_dll_directory ) + +def clear(): + """ Runs the clear command in the shell """ + if name == 'nt': + system('cls') + else: + system('clear') diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 96fddc7d057663e..d7c4a12fb7a7849 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -4050,6 +4050,14 @@ def test_blocking(self): self.assertEqual(os.get_blocking(fd), True) +class ClearTests(unittest.TestCase): + def test_clear(): + if os.name == 'nt': + pass + # TODO : add test for windows + else: + self.assertIn('\x1b[3J\x1b[H\x1b[2J', subprocess.check_output(sys.executable + ' -c "import os; os.clear()"', shell=True).decode()) + class ExportsTests(unittest.TestCase): def test_os_all(self): diff --git a/Misc/NEWS.d/next/Library/2021-03-08-16-08-15.bpo-43432.Aq20oZ.rst b/Misc/NEWS.d/next/Library/2021-03-08-16-08-15.bpo-43432.Aq20oZ.rst new file mode 100644 index 000000000000000..863dad8f0ed5f07 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-03-08-16-08-15.bpo-43432.Aq20oZ.rst @@ -0,0 +1,3 @@ +Added function `clear` to module `os`. +This function clears the screen by running `cls` in windows and `clear` in unix. +Patch by parsa shahmaleki From 6380a2d346f359ca806bfa1bbfda038f6b4857d2 Mon Sep 17 00:00:00 2001 From: parsa shahmaleki Date: Mon, 8 Mar 2021 16:40:20 +0330 Subject: [PATCH 2/3] remove test --- Lib/test/test_os.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index d7c4a12fb7a7849..134356a40088b83 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -4050,15 +4050,6 @@ def test_blocking(self): self.assertEqual(os.get_blocking(fd), True) -class ClearTests(unittest.TestCase): - def test_clear(): - if os.name == 'nt': - pass - # TODO : add test for windows - else: - self.assertIn('\x1b[3J\x1b[H\x1b[2J', subprocess.check_output(sys.executable + ' -c "import os; os.clear()"', shell=True).decode()) - - class ExportsTests(unittest.TestCase): def test_os_all(self): self.assertIn('open', os.__all__) From c70e3b283d3464b70ab1ec12a83c39d3e6aa5db3 Mon Sep 17 00:00:00 2001 From: parsa shahmaleki Date: Mon, 8 Mar 2021 16:42:32 +0330 Subject: [PATCH 3/3] update Lib/test/test_os.py --- Lib/test/test_os.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 134356a40088b83..96fddc7d057663e 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -4050,6 +4050,7 @@ def test_blocking(self): self.assertEqual(os.get_blocking(fd), True) + class ExportsTests(unittest.TestCase): def test_os_all(self): self.assertIn('open', os.__all__)