aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wick...@apache.org
Subject [1/4] Make style consistent with build-support/python/checkstyle-check
Date Thu, 05 Jun 2014 16:49:36 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master ca4adf93f -> 467f84285


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/467f8428/src/test/python/apache/thermos/core/test_failure_limit.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/thermos/core/test_failure_limit.py b/src/test/python/apache/thermos/core/test_failure_limit.py
index a37f44f..ae6503d 100644
--- a/src/test/python/apache/thermos/core/test_failure_limit.py
+++ b/src/test/python/apache/thermos/core/test_failure_limit.py
@@ -22,15 +22,15 @@ class TestFailureLimit(RunnerTestBase):
   @classmethod
   def task(cls):
     task = Task(
-      name = "failing_task",
-      resources = Resources(cpu = 1.0, ram = 16*1024*1024, disk = 16*1024),
-      max_failures = 2,
-      processes = [
-        Process(name = "a", max_failures=1, min_duration=1, cmdline="echo hello world"),
-        Process(name = "b", max_failures=1, min_duration=1, cmdline="exit 1"),
-        Process(name = "c", max_failures=1, min_duration=1, cmdline="echo hello world")
+      name="failing_task",
+      resources=Resources(cpu=1.0, ram=16 * 1024 * 1024, disk=16 * 1024),
+      max_failures=2,
+      processes=[
+          Process(name="a", max_failures=1, min_duration=1, cmdline="echo hello world"),
+          Process(name="b", max_failures=1, min_duration=1, cmdline="exit 1"),
+          Process(name="c", max_failures=1, min_duration=1, cmdline="echo hello world")
       ],
-      constraints = [{'order': ['a', 'b', 'c']}]
+      constraints=[{'order': ['a', 'b', 'c']}]
     )
     return task.interpolate()[0]
 
@@ -53,11 +53,12 @@ class TestTaskSucceedsIfMaxFailures0(RunnerTestBase):
     ex = base(cmdline="exit 1")
     hw = base(cmdline="echo hello world")
     task = Task(
-      name = "failing_task",
-      resources = Resources(cpu = 1.0, ram = 16*1024*1024, disk = 16*1024),
-      max_failures = 0,
-      processes = [ex(name='f1'), ex(name='f2'), ex(name='f3'),
-                   hw(name='s1'), hw(name='s2'), hw(name='s3')])
+      name="failing_task",
+      resources=Resources(cpu=1.0, ram=16 * 1024 * 1024, disk=16 * 1024),
+      max_failures=0,
+      processes=[
+          ex(name='f1'), ex(name='f2'), ex(name='f3'),
+          hw(name='s1'), hw(name='s2'), hw(name='s3')])
     return task.interpolate()[0]
 
   def test_runner_state_failure(self):

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/467f8428/src/test/python/apache/thermos/core/test_finalization.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/thermos/core/test_finalization.py b/src/test/python/apache/thermos/core/test_finalization.py
index 972785f..2b0ee05 100644
--- a/src/test/python/apache/thermos/core/test_finalization.py
+++ b/src/test/python/apache/thermos/core/test_finalization.py
@@ -23,7 +23,7 @@ class TestRegularFinalizingTask(RunnerTestBase):
   def task(cls):
     main = Process(name="main", cmdline="date && echo hello world")
     finalizer = Process(name="finalizer", cmdline="date", final=True)
-    task = Task(name="task_with_finalizer", processes = [main, finalizer])
+    task = Task(name="task_with_finalizer", processes=[main, finalizer])
     return task.interpolate()[0]
 
   def test_runner_state(self):

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/467f8428/src/test/python/apache/thermos/core/test_helper.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/thermos/core/test_helper.py b/src/test/python/apache/thermos/core/test_helper.py
index 26288fa..5809611 100644
--- a/src/test/python/apache/thermos/core/test_helper.py
+++ b/src/test/python/apache/thermos/core/test_helper.py
@@ -82,7 +82,10 @@ def test_scan_process():
   with mock.patch(PSUTIL_PATH) as p_mock:
     class WrappedNoSuchProcess(psutil.NoSuchProcess):
       # psutil.NoSuchProcess exception requires an argument, but mock doesn't support that.
-      def __init__(self): pass
+
+      def __init__(self):
+        pass
+
     p_mock.side_effect = WrappedNoSuchProcess
     assert TRH.scan_process(
         make_runner_state(cpid=None), PROCESS_NAME) == (None, None, set())

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/467f8428/src/test/python/apache/thermos/core/test_process.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/thermos/core/test_process.py b/src/test/python/apache/thermos/core/test_process.py
index ed66f73..223393d 100644
--- a/src/test/python/apache/thermos/core/test_process.py
+++ b/src/test/python/apache/thermos/core/test_process.py
@@ -16,7 +16,6 @@ import grp
 import os
 import pwd
 import random
-import threading
 import time
 
 import mock
@@ -35,19 +34,21 @@ class TestProcess(Process):
   def execute(self):
     super(TestProcess, self).execute()
     os._exit(0)
+
   def finish(self):
     pass
 
 
 def wait_for_rc(checkpoint, timeout=5.0):
   start = time.time()
-  trr = ThriftRecordReader(open(checkpoint), RunnerCkpt)
-  while time.time() < start + timeout:
-    record = trr.read()
-    if record and record.process_status and record.process_status.return_code is not None:
-      return record.process_status.return_code
-    else:
-      time.sleep(0.1)
+  with open(checkpoint) as fp:
+    trr = ThriftRecordReader(fp, RunnerCkpt)
+    while time.time() < start + timeout:
+      record = trr.read()
+      if record and record.process_status and record.process_status.return_code is not None:
+        return record.process_status.return_code
+      else:
+        time.sleep(0.1)
 
 
 def get_other_nonroot_user():
@@ -94,7 +95,7 @@ def test_simple_process_other_user(*args):
 
     p = TestProcess('process', 'echo hello world', 0, taskpath, sandbox, user=some_user.pw_name)
     p.start()
-    rc = wait_for_rc(taskpath.getpath('process_checkpoint'))
+    wait_for_rc(taskpath.getpath('process_checkpoint'))
 
     # since we're not actually root, the best we can do is check the right things were attempted
     assert os.setgroups.calledwith([g.gr_gid for g in grp.getgrall() if some_user.pw_name
in g])
@@ -108,7 +109,7 @@ def test_other_user_fails_nonroot():
     sandbox = setup_sandbox(td, taskpath)
 
     with pytest.raises(Process.PermissionError):
-      p = TestProcess('process', 'echo hello world', 0, taskpath, sandbox,
+      TestProcess('process', 'echo hello world', 0, taskpath, sandbox,
             user=get_other_nonroot_user().pw_name)
 
 
@@ -119,7 +120,7 @@ def test_log_permissions():
 
     p = TestProcess('process', 'echo hello world', 0, taskpath, sandbox)
     p.start()
-    rc = wait_for_rc(taskpath.getpath('process_checkpoint'))
+    wait_for_rc(taskpath.getpath('process_checkpoint'))
 
     stdout = taskpath.with_filename('stdout').getpath('process_logdir')
     stderr = taskpath.with_filename('stderr').getpath('process_logdir')
@@ -142,7 +143,7 @@ def test_log_permissions_other_user(*mocks):
 
     p = TestProcess('process', 'echo hello world', 0, taskpath, sandbox, user=some_user.pw_name)
     p.start()
-    rc = wait_for_rc(taskpath.getpath('process_checkpoint'))
+    wait_for_rc(taskpath.getpath('process_checkpoint'))
 
     # since we're not actually root, the best we can do is check the right things were attempted
     stdout = taskpath.with_filename('stdout').getpath('process_logdir')

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/467f8428/src/test/python/apache/thermos/core/test_runner_integration.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/thermos/core/test_runner_integration.py b/src/test/python/apache/thermos/core/test_runner_integration.py
index fa84de7..55dbb12 100644
--- a/src/test/python/apache/thermos/core/test_runner_integration.py
+++ b/src/test/python/apache/thermos/core/test_runner_integration.py
@@ -15,36 +15,35 @@
 import os
 from textwrap import dedent
 
-import pytest
-
-from apache.thermos.config.schema import order, Process, Resources, SequentialTask, Task,
Tasks
+from apache.thermos.config.schema import Process, Resources, SequentialTask, Task, Tasks
 from apache.thermos.testing.runner import RunnerTestBase
 
 from gen.apache.thermos.ttypes import ProcessState, TaskState
 
 
 class TestRunnerBasic(RunnerTestBase):
-  portmap = {'named_port': 8123}
+  portmap = {'named_port': 8123}  # noqa
 
   @classmethod
   def task(cls):
-    hello_template = Process(cmdline = "echo 1")
-    t1 = hello_template(name = "t1", cmdline = "echo 1 port {{thermos.ports[named_port]}}")
-    t2 = hello_template(name = "t2")
-    t3 = hello_template(name = "t3")
-    t4 = hello_template(name = "t4")
-    t5 = hello_template(name = "t5")
-    t6 = hello_template(name = "t6")
-    tsk = Task(name = "complex", processes = [t1, t2, t3, t4, t5, t6])
+    hello_template = Process(cmdline="echo 1")
+    t1 = hello_template(name="t1", cmdline="echo 1 port {{thermos.ports[named_port]}}")
+    t2 = hello_template(name="t2")
+    t3 = hello_template(name="t3")
+    t4 = hello_template(name="t4")
+    t5 = hello_template(name="t5")
+    t6 = hello_template(name="t6")
+    tsk = Task(name="complex", processes=[t1, t2, t3, t4, t5, t6])
     # three ways of tasks: t1 t2, t3 t4, t5 t6
-    tsk = tsk(constraints = [{'order': ['t1', 't3']},
-                             {'order': ['t1', 't4']},
-                             {'order': ['t2', 't3']},
-                             {'order': ['t2', 't4']},
-                             {'order': ['t3', 't5']},
-                             {'order': ['t3', 't6']},
-                             {'order': ['t4', 't5']},
-                             {'order': ['t4', 't6']}])
+    tsk = tsk(constraints=[
+        {'order': ['t1', 't3']},
+        {'order': ['t1', 't4']},
+        {'order': ['t2', 't3']},
+        {'order': ['t2', 't4']},
+        {'order': ['t3', 't5']},
+        {'order': ['t3', 't6']},
+        {'order': ['t4', 't5']},
+        {'order': ['t4', 't6']}])
     return tsk
 
   def test_runner_state_success(self):
@@ -66,7 +65,7 @@ class TestRunnerBasic(RunnerTestBase):
 
   def test_runner_has_expected_processes(self):
     processes = self.state.processes
-    process_names = set(['t%d'%k for k in range(1,7)])
+    process_names = set(['t%d' % k for k in range(1, 7)])
     actual_process_names = set(processes.keys())
     assert process_names == actual_process_names, "runner didn't run expected set of processes!"
     for process in processes:
@@ -77,7 +76,7 @@ class TestRunnerBasic(RunnerTestBase):
       history = self.state.processes[process]
       assert history[-1].state == ProcessState.SUCCESS
       if len(history) > 1:
-        for run in range(len(history)-1):
+        for run in range(len(history) - 1):
           assert history[run].state != ProcessState.SUCCESS, (
             "nonterminal processes must not be in SUCCESS state!")
 
@@ -91,14 +90,14 @@ class TestRunnerBasic(RunnerTestBase):
 class TestConcurrencyBasic(RunnerTestBase):
   @classmethod
   def task(cls):
-    hello_template = Process(cmdline = "sleep 1")
+    hello_template = Process(cmdline="sleep 1")
     tsk = Task(
-      name = "complex",
-      processes = [hello_template(name = "process1"),
-                   hello_template(name = "process2"),
-                   hello_template(name = "process3")],
-      resources = Resources(cpu = 1.0, ram = 16*1024*1024, disk = 16*1024),
-      max_concurrency = 1)
+      name="complex",
+      processes=[hello_template(name="process1"),
+                 hello_template(name="process2"),
+                 hello_template(name="process3")],
+      resources=Resources(cpu=1.0, ram=16 * 1024 * 1024, disk=16 * 1024),
+      max_concurrency=1)
     return tsk
 
   def test_runner_state_success(self):
@@ -119,45 +118,44 @@ class TestConcurrencyBasic(RunnerTestBase):
 class TestRunnerEnvironment(RunnerTestBase):
   @classmethod
   def task(cls):
-    setup_bashrc = Process(name = "setup_bashrc", cmdline = dedent(
-    """
-    mkdir -p .profile.d
-    cat <<EOF > .thermos_profile
-    for i in .profile.d/*.sh ; do
-      if [ -r "\\$i" ]; then
-        . \\$i
-      fi
-    done
-    EOF
-    """))
-
-    setup_foo = Process(name = "setup_foo", cmdline = dedent(
-    """
-    cat <<EOF > .profile.d/setup_foo.sh
-    export FOO=1
-    EOF
-    """))
-
-    setup_bar = Process(name = "setup_bar", cmdline = dedent(
-    """
-    cat <<EOF > .profile.d/setup_bar.sh
-    export BAR=2
-    EOF
-    """))
-
-    foo_recipe = SequentialTask(processes = [setup_bashrc, setup_foo])
-    bar_recipe = SequentialTask(processes = [setup_bashrc, setup_bar])
+    setup_bashrc = Process(name="setup_bashrc", cmdline=dedent(
+        """
+        mkdir -p .profile.d
+        cat <<EOF > .thermos_profile
+        for i in .profile.d/*.sh ; do
+          if [ -r "\\$i" ]; then
+            . \\$i
+          fi
+        done
+        EOF
+        """))
+
+    setup_foo = Process(name="setup_foo", cmdline=dedent(
+        """
+        cat <<EOF > .profile.d/setup_foo.sh
+        export FOO=1
+        EOF
+        """))
+
+    setup_bar = Process(name="setup_bar", cmdline=dedent(
+        """
+        cat <<EOF > .profile.d/setup_bar.sh
+        export BAR=2
+        EOF
+        """))
+
+    foo_recipe = SequentialTask(processes=[setup_bashrc, setup_foo])
+    bar_recipe = SequentialTask(processes=[setup_bashrc, setup_bar])
     all_recipes = Tasks.combine(foo_recipe, bar_recipe)
 
-    run = Process(name = "run", cmdline = dedent(
-    """
-    echo $FOO $BAR > expected_output.txt
-    """
-    ))
+    run = Process(name="run", cmdline=dedent(
+        """
+        echo $FOO $BAR > expected_output.txt
+        """))
 
-    my_task = Task(processes = [run],
-                   resources = Resources(cpu = 1.0, ram = 16*1024*1024, disk = 16*1024))
-    return Tasks.concat(all_recipes, my_task, name = "my_task")
+    my_task = Task(processes=[run],
+                   resources=Resources(cpu=1.0, ram=16 * 1024 * 1024, disk=16 * 1024))
+    return Tasks.concat(all_recipes, my_task, name="my_task")
 
   def test_runner_state_success(self):
     assert self.state.statuses[-1].state == TaskState.SUCCESS

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/467f8428/src/test/python/apache/thermos/core/test_staged_kill.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/thermos/core/test_staged_kill.py b/src/test/python/apache/thermos/core/test_staged_kill.py
index e0a3d14..faa23ae 100644
--- a/src/test/python/apache/thermos/core/test_staged_kill.py
+++ b/src/test/python/apache/thermos/core/test_staged_kill.py
@@ -22,17 +22,14 @@ import pytest
 from twitter.common.process import ProcessProviderFactory
 from twitter.common.quantity import Amount, Time
 
-from apache.thermos.config.schema import Process, Resources, Task
+from apache.thermos.config.schema import Process, Task
 from apache.thermos.core.runner import TaskRunner
 from apache.thermos.monitoring.monitor import TaskMonitor
 from apache.thermos.testing.runner import Runner
 
 from gen.apache.thermos.ttypes import ProcessState, TaskState
 
-sleepy_process = Process(
-  name = "sleepy",
-  cmdline = "sleep 3",
-  min_duration = 1)
+sleepy_process = Process(name="sleepy", cmdline="sleep 3", min_duration=1)
 
 ignore_script = [
   "import time, signal",
@@ -107,7 +104,7 @@ class ProcessPidTestCase(object):
 class TestRunnerKill(RunnerBase, ProcessPidTestCase):
   @classmethod
   def task(cls):
-    task = Task(name = "task", processes = [sleepy_process(name="process")])
+    task = Task(name="task", processes=[sleepy_process(name="process")])
     return task.interpolate()[0]
 
   def test_coordinator_kill(self):
@@ -136,9 +133,9 @@ class TestRunnerKill(RunnerBase, ProcessPidTestCase):
 class TestRunnerKillProcessTrappingSIGTERM(RunnerBase):
   @classmethod
   def task(cls):
-    task = Task(name = "task",
-                finalization_wait = 3,
-                processes = [ignorant_process(name="ignorant_process")])
+    task = Task(name="task",
+                finalization_wait=3,
+                processes=[ignorant_process(name="ignorant_process")])
     return task.interpolate()[0]
 
   def test_coordinator_kill(self):
@@ -224,7 +221,6 @@ class TestRunnerKillProcessTrappingSIGTERM(RunnerBase):
     assert preempter.state.processes['ignorant_process'][-1].state == ProcessState.KILLED
 
 
-
 SIMPLEFORK_SCRIPT = """
 cat <<EOF | %(INTERPRETER)s -
 from __future__ import print_function
@@ -244,12 +240,13 @@ else:
   while not os.path.exists('exit.txt'):
     time.sleep(0.1)
 EOF
-""" % { 'INTERPRETER': sys.executable }
+""" % {'INTERPRETER': sys.executable}
+
 
 class TestRunnerKillProcessGroup(RunnerBase):
   @classmethod
   def task(cls):
-    task = Task(name = "task", processes = [Process(name="process", cmdline=SIMPLEFORK_SCRIPT)])
+    task = Task(name="task", processes=[Process(name="process", cmdline=SIMPLEFORK_SCRIPT)])
     return task.interpolate()[0]
 
   def test_pg_is_killed(self):

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/467f8428/src/test/python/apache/thermos/monitoring/test_disk.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/thermos/monitoring/test_disk.py b/src/test/python/apache/thermos/monitoring/test_disk.py
index cc3c20a..913f87d 100644
--- a/src/test/python/apache/thermos/monitoring/test_disk.py
+++ b/src/test/python/apache/thermos/monitoring/test_disk.py
@@ -12,9 +12,7 @@
 # limitations under the License.
 #
 
-import atexit
 import os
-import sys
 import time
 from tempfile import mkstemp
 
@@ -47,7 +45,7 @@ def _run_collector_tests(collector, target, wait):
   wait()
   assert collector.value >= TEST_AMOUNT_1.as_(Data.BYTES)
 
-  f2 = make_file(TEST_AMOUNT_2, dir=target)
+  make_file(TEST_AMOUNT_2, dir=target)
   wait()
   assert collector.value >= TEST_AMOUNT_SUM.as_(Data.BYTES)
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/467f8428/src/test/sh/org/apache/aurora/e2e/http_example.py
----------------------------------------------------------------------
diff --git a/src/test/sh/org/apache/aurora/e2e/http_example.py b/src/test/sh/org/apache/aurora/e2e/http_example.py
index 04f7fa5..675ece8 100644
--- a/src/test/sh/org/apache/aurora/e2e/http_example.py
+++ b/src/test/sh/org/apache/aurora/e2e/http_example.py
@@ -12,8 +12,10 @@
 # limitations under the License.
 #
 from __future__ import print_function
-from sys import argv
+
 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
+from sys import argv
+
 
 class RequestHandler(BaseHTTPRequestHandler):
   def do_GET(self):


Mime
View raw message