forked from getredash/redash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_script.py
More file actions
36 lines (25 loc) · 1.46 KB
/
test_script.py
File metadata and controls
36 lines (25 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import subprocess
from _pytest.monkeypatch import MonkeyPatch
from redash.query_runner.script import query_to_script_path, run_script
from tests import BaseTestCase
class TestQueryToScript(BaseTestCase):
monkeypatch = MonkeyPatch()
def test_unspecified(self):
self.assertEqual("/foo/bar/baz.sh", query_to_script_path("*", "/foo/bar/baz.sh"))
def test_specified(self):
self.assertRaises(IOError, lambda: query_to_script_path("/foo/bar", "baz.sh"))
self.monkeypatch.setattr(os.path, "exists", lambda x: True)
self.assertEqual(["/foo/bar/baz.sh"], query_to_script_path("/foo/bar", "baz.sh"))
class TestRunScript(BaseTestCase):
monkeypatch = MonkeyPatch()
def test_success(self):
self.monkeypatch.setattr(subprocess, "check_output", lambda script, shell: "test")
self.assertEqual(("test", None), run_script("/foo/bar/baz.sh", True))
def test_failure(self):
self.monkeypatch.setattr(subprocess, "check_output", lambda script, shell: None)
self.assertEqual((None, "Error reading output"), run_script("/foo/bar/baz.sh", True))
self.monkeypatch.setattr(subprocess, "check_output", lambda script, shell: "")
self.assertEqual((None, "Empty output from script"), run_script("/foo/bar/baz.sh", True))
self.monkeypatch.setattr(subprocess, "check_output", lambda script, shell: " ")
self.assertEqual((None, "Empty output from script"), run_script("/foo/bar/baz.sh", True))