Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python suites #1164

Merged
merged 2 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def script_3(self):
raise SkipScript

def helper(self):
if openc3.script.RUNNING_SCRIPT and openc3.script.RUNNING_SCRIPT.manual:
if RunningScript.manual:
answer = ask("Are you sure?")
else:
answer = "y"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_3(self):
raise SkipTestCase

def helper(self):
if openc3.script.RUNNING_SCRIPT and openc3.script.RUNNING_SCRIPT.manual:
if RunningScript.manual:
answer = ask("Are you sure?")
else:
answer = "y"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-->

<template>
<v-dialog v-model="show" scrollable width="600">
<v-dialog v-model="show" scrollable width="800">
<v-card>
<v-system-bar>
<v-spacer />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,7 @@ class TestSuite(Suite):
let pythonRegex2 = new RegExp(
'^\\s*(if|def|while|else|elif|class).*:\\s*$',
)
let pythonRegex3 = new RegExp('\\(f"') // f strings
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(f" doesn't exist anywhere in our ruby code

let text = this.editor.getValue()
let lines = text.split('\n')
for (let line of lines) {
Expand All @@ -2140,6 +2141,9 @@ class TestSuite(Suite):
if (line.match(pythonRegex2)) {
return 'python'
}
if (line.match(pythonRegex3)) {
return 'python'
}
}
return 'unknown' // otherwise unknown
},
Expand Down
10 changes: 1 addition & 9 deletions openc3-cosmos-script-runner-api/scripts/running_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,6 @@ def running_script_method(method, *args, **kwargs):
RAILS_ROOT = os.path.abspath(os.path.join(__file__, "../.."))


class StopScript(Exception):
pass


class SkipScript(Exception):
pass


class RunningScript:
# Matches the following test cases:
# class MySuite(TestSuite)
Expand Down Expand Up @@ -526,7 +518,7 @@ def post_line_instrumentation(self, filename, line_number):
self.handle_output_io(filename, line_number)

def exception_instrumentation(self, filename, line_number):
exc_type, error, exc_tb = sys.exc_info()
_, error, _ = sys.exc_info()
if (
issubclass(error.__class__, StopScript)
or issubclass(error.__class__, SkipScript)
Expand Down
44 changes: 26 additions & 18 deletions openc3/python/openc3/script/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,21 @@ def run(self):
result = self.run_group_setup(group_class, True)
if result:
results.append(result)
yield result
if (
result.exceptions and group_class.abort_on_exception
) or result.stopped:
raise StopScript
yield result
if (
result.exceptions and group_class.abort_on_exception
) or result.stopped:
raise StopScript
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of bad indentation was breaking running Groups and Suites


case "GROUP_TEARDOWN":
result = self.run_group_teardown(group_class, True)
if result:
results.append(result)
yield result
if (
result.exceptions and group_class.abort_on_exception
) or result.stopped:
raise StopScript
yield result
if (
result.exceptions and group_class.abort_on_exception
) or result.stopped:
raise StopScript

# Teardown the suite
result = self.run_teardown(True)
Expand Down Expand Up @@ -330,9 +330,11 @@ def run(self):
result = self.run_setup()
if result:
results.append(result)
yield result
if (results[-1].exceptions and Group.abort_on_exception) or results[-1].stopped:
raise StopScript
yield result
if (results[-1].exceptions and Group.abort_on_exception) or results[
-1
].stopped:
raise StopScript

# Run all the scripts
for method_name in self.__class__.scripts():
Expand All @@ -347,9 +349,11 @@ def run(self):
result = self.run_teardown()
if result:
results.append(result)
yield result
if (results[-1].exceptions and Group.abort_on_exception) or results[-1].stopped:
raise StopScript
yield result
if (results[-1].exceptions and Group.abort_on_exception) or results[
-1
].stopped:
raise StopScript
return results

# Run a specific script method
Expand Down Expand Up @@ -442,14 +446,18 @@ def run_method(self, object, method_name):
return result

def run_setup(self):
result = None
if "setup" in dir(self):
ScriptStatus.instance().status = f"{self.__class__} : setup"
return self.run_script("setup")
result = self.run_script("setup")
return result

def run_teardown(self):
result = None
if "teardown" in dir(self):
ScriptStatus.instance().status = f"{self.__class__} : teardown"
return self.run_script("teardown")
result = self.run_script("teardown")
return result

@classmethod
def get_num_scripts(cls):
Expand Down
2 changes: 2 additions & 0 deletions openc3/templates/target/targets/TARGET/lib/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# <%= target_object %>.utility()
# For more information see the OpenC3 scripting guide

from openc3.script import *

class <%= target_class %>:
def utility(self):
pass
Loading