本文整理汇总了Python中JSBSim_utils.SandBox.delete_csv_files方法的典型用法代码示例。如果您正苦于以下问题:Python SandBox.delete_csv_files方法的具体用法?Python SandBox.delete_csv_files怎么用?Python SandBox.delete_csv_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSBSim_utils.SandBox
的用法示例。
在下文中一共展示了SandBox.delete_csv_files方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestICOverride
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import delete_csv_files [as 别名]
class TestICOverride(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
def test_IC_override(self):
# Run the script c1724.xml
script_path = self.sandbox.path_to_jsbsim_file('scripts', 'c1724.xml')
fdm = CreateFDM(self.sandbox)
fdm.load_script(script_path)
vt0 = fdm.get_property_value('ic/vt-kts')
fdm.run_ic()
ExecuteUntil(fdm, 1.0)
# Check that the total velocity exported in the output file matches the IC
# defined in the initialization file
ref = Table()
ref.ReadCSV(self.sandbox('JSBout172B.csv'))
for col, title in enumerate(ref._lines[0]):
if title == 'V_{Total} (ft/s)':
self.assertTrue(abs(ref._lines[1][col] - (vt0 / fpstokts)) < 1E-5,
msg="Original script %s\nThe total velocity is %f. The value %f was expected" % (script_path, ref._lines[1][col], vt0 / fpstokts))
break
else:
self.fail("The total velocity is not exported in %s" % (script_path,))
# Now, we will re-run the same test but the IC will be overridden in the scripts
# The initial total velocity is increased by 1 ft/s
vt0 += 1.0
# The script c1724.xml is loaded and the following line is added in it:
# <property value="..."> ic/vt-kts </property>
# The modified script is then saved with the named 'c1724_0.xml'
tree = et.parse(self.sandbox.elude(script_path))
run_tag = tree.getroot().find("./run")
property = et.SubElement(run_tag, 'property')
property.text = 'ic/vt-kts'
property.attrib['value'] = str(vt0)
tree.write(self.sandbox('c1724_0.xml'))
# Re-run the same check than above. This time we are making sure than the total
# initial velocity is increased by 1 ft/s
self.sandbox.delete_csv_files()
# Because JSBSim internals use static pointers, we cannot rely on Python
# garbage collector to decide when the FDM is destroyed otherwise we can
# get dangling pointers.
del fdm
fdm = CreateFDM(self.sandbox)
fdm.load_script('c1724_0.xml')
self.assertTrue(abs(fdm.get_property_value('ic/vt-kts') - vt0) < 1E-5,
msg="Modified script %s\nThe total velocity in the IC (%f) is different from %f" % (self.sandbox('JSBout172B.csv'), fdm.get_property_value('ic/vt-kts'), vt0))
fdm.run_ic()
ExecuteUntil(fdm, 1.0)
mod = Table()
mod.ReadCSV(self.sandbox('JSBout172B.csv'))
for col, title in enumerate(mod._lines[0]):
if title == 'V_{Total} (ft/s)':
self.assertTrue(abs(mod._lines[1][col] - (vt0 / fpstokts)) < 1E-5,
msg="Modified script %s\nThe total velocity is %f. The value %f was expected" % (self.sandbox('JSBout172B.csv'), mod._lines[1][col], vt0 / fpstokts))
break
else:
self.fail("The total velocity is not exported in %s" % (sandbox('JSBout172B.csv'),))
示例2: ExecuteUntil
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import delete_csv_files [as 别名]
fdm.set_output_filename(0, 'this_one.csv')
fdm.set_output_filename(0, 'that_one.csv')
fdm.reset_to_initial_conditions(1)
ExecuteUntil(fdm, 1.0)
if sandbox.exists('this_one.csv') or not sandbox.exists('that_one.csv'):
if sandbox.exists('this_one.csv'):
print "Output name overwritten: 'this_one.csv' should not exist."
if not sandbox.exists('that_one.csv'):
print "Output name overwritten: 'that_one.csv' should exist."
sys.exit(-1) # 'make test' will report the test failed.
#
# Check again on a brand new FDM
#
sandbox.delete_csv_files()
fdm = CreateFDM(sandbox)
fdm.load_script(sandbox.path_to_jsbsim_file('scripts', 'c1722.xml'))
fdm.run_ic()
fdm.set_output_filename(0,'oops.csv') # Oops!! Changed my mind
ExecuteUntil(fdm, 1.0)
if sandbox.exists('oops.csv') or not sandbox.exists('JSBout172B.csv'):
if sandbox.exists('oops.csv'):
print "New FDM: 'oops.csv' should not exist."
if not sandbox.exists('JSBout172B.csv'):
print "New FDM: 'JSBout172B.csv' should exist."
sys.exit(-1) # 'make test' will report the test failed.
#
示例3: TestModelLoading
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import delete_csv_files [as 别名]
class TestModelLoading(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
def BuildReference(self, script_name):
# Run the script
self.script = self.sandbox.path_to_jsbsim_file(os.path.join('scripts',
script_name))
self.sandbox.delete_csv_files()
fdm = CreateFDM(self.sandbox)
fdm.set_output_directive(self.sandbox.path_to_jsbsim_file('tests',
'output.xml'))
fdm.load_script(self.script)
fdm.set_property_value('simulation/randomseed', 0.0)
fdm.run_ic()
ExecuteUntil(fdm, 50.0)
self.ref = Table()
self.ref.ReadCSV(self.sandbox("output.csv"))
# Since the script will work with modified versions of the aircraft XML
# definition file, we need to make a copy of the directory that contains
# all the input data of that aircraft
tree, self.aircraft_name, self.path_to_jsbsim_aircrafts = CopyAircraftDef(self.script, self.sandbox)
self.aircraft_path = self.sandbox('aircraft', self.aircraft_name)
def ProcessAndCompare(self, section):
# Here we determine if the original aircraft definition <section> is
# inline or read from an external file.
tree = et.parse(os.path.join(self.path_to_jsbsim_aircrafts,
self.aircraft_name + '.xml'))
root = tree.getroot()
# Iterate over all the tags named <section>
for section_element in root.findall(section):
if 'file' in section_element.keys():
self.InsertAndCompare(section_element, tree)
else:
self.DetachAndCompare(section_element, tree)
def DetachAndCompare(self, section_element, tree):
# Extract <section> from the original aircraft definition file and copy
# it in a separate XML file 'section.xml'
section_tree = et.ElementTree(element=section_element)
if 'name' in section_element.keys():
section = section_element.attrib['name']
else:
section = section_element.tag
section_tree.write(os.path.join(self.aircraft_path, section+'.xml'),
xml_declaration=True)
# Now, we need to clean up the aircraft definition file from all
# references to <section>. We just need a single <section> tag that
# points to the file 'section.xml'
for element in list(section_element):
section_element.remove(element)
section_element.attrib = {'file': section+'.xml'}
tree.write(os.path.join(self.aircraft_path, self.aircraft_name+'.xml'),
xml_declaration=True)
self.Compare(section)
def InsertAndCompare(self, section_element, tree):
file_name = append_xml(section_element.attrib['file'])
section_file = os.path.join(self.path_to_jsbsim_aircrafts, file_name)
# If <section> is actually <system>, we need to iterate over all the
# directories in which the file is allowed to be stored until the file
# is located.
if not os.path.exists(section_file) and section_element.tag == 'system':
section_file = os.path.join(self.path_to_jsbsim_aircrafts, "systems", file_name)
if not os.path.exists(section_file):
section_file = self.sandbox.elude(self.sandbox.path_to_jsbsim_file("systems", file_name))
# The original <section> tag is dropped and replaced by the content of
# the file.
section_root = et.parse(section_file).getroot()
del section_element.attrib['file']
section_element.attrib.update(section_root.attrib)
section_element.extend(section_root)
tree.write(os.path.join(self.aircraft_path, self.aircraft_name+'.xml'))
self.Compare(section_element.tag+" file:"+section_file)
def Compare(self, section):
# Rerun the script with the modified aircraft definition
self.sandbox.delete_csv_files()
fdm = CreateFDM(self.sandbox)
# We need to tell JSBSim that the aircraft definition is located in the
# directory build/.../aircraft
fdm.set_aircraft_path('aircraft')
#.........这里部分代码省略.........
示例4: ResetOutputFiles
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import delete_csv_files [as 别名]
class ResetOutputFiles(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
def test_reset_output_files(self):
#
# Regular run that checks the correct CSV file is created
# We are just checking its existence, not its content. To accelerate the
# test execution, the simulation is interrupted after 1.0sec of simulated
# time.
#
fdm = CreateFDM(self.sandbox)
fdm.load_script(self.sandbox.path_to_jsbsim_file('scripts', 'c1722.xml'))
fdm.run_ic()
ExecuteUntil(fdm, 1.0)
self.assertTrue(self.sandbox.exists('JSBout172B.csv'),
msg="Standard run: the file 'JSBout172B.csv' should exist.")
#
# Reset the simulation and check that iteration number is correctly
# appended to the filename.
#
fdm.reset_to_initial_conditions(1)
ExecuteUntil(fdm, 1.0)
self.assertTrue(self.sandbox.exists('JSBout172B_0.csv'),
msg="Reset: the file 'JSBout172B_0.csv' should exist.")
#
# Change the output filename and check that the naming logic is reset
# (e.g. that no iteration number is appended to the filename)
#
fdm.set_output_filename(0, 'dummy.csv')
fdm.reset_to_initial_conditions(1)
ExecuteUntil(fdm, 1.0)
self.assertTrue(self.sandbox.exists('dummy.csv'),
msg="Output name renaming: the file 'dummy.csv' should exist.")
#
# Call FGFDMExec::SetOutputFileName() after the simulation is reset. And
# verify that the new output file name is ignored until the next call to
# FGOutput::SetStartNewOutput(). This should be so according to the
# documentation of FGOutput::SetOutputName().
#
fdm.reset_to_initial_conditions(1)
fdm.set_output_filename(0, 'dummyx.csv')
ExecuteUntil(fdm, 1.0)
self.assertTrue(not self.sandbox.exists('dummyx.csv'),
msg="Late renaming: 'dummyx.csv' should not exist.")
self.assertTrue(self.sandbox.exists('dummy_0.csv'),
msg="Late renaming: 'dummy_0.csv' should exist.")
#
# Check that the new filename is taken into account when the simulation is
# reset.
#
fdm.reset_to_initial_conditions(1)
ExecuteUntil(fdm, 1.0)
self.assertTrue(self.sandbox.exists('dummyx.csv'),
msg="Reset after late renaming: 'dummyx.csv' should exist.")
#
# Check against multiple calls to FGFDMExec::SetOutputFileName()
#
fdm.set_output_filename(0, 'this_one.csv')
fdm.set_output_filename(0, 'that_one.csv')
fdm.reset_to_initial_conditions(1)
ExecuteUntil(fdm, 1.0)
self.assertTrue(not self.sandbox.exists('this_one.csv'),
msg="Output name overwritten: 'this_one.csv' should not exist.")
self.assertTrue(self.sandbox.exists('that_one.csv'),
msg="Output name overwritten: 'that_one.csv' should exist.")
#
# Check again on a brand new FDM
#
self.sandbox.delete_csv_files()
# Because JSBSim internals use static pointers, we cannot rely on Python
# garbage collector to decide when the FDM is destroyed otherwise we can
# get dangling pointers.
del fdm
fdm = CreateFDM(self.sandbox)
fdm.load_script(self.sandbox.path_to_jsbsim_file('scripts', 'c1722.xml'))
fdm.run_ic()
fdm.set_output_filename(0,'oops.csv') # Oops!! Changed my mind
ExecuteUntil(fdm, 1.0)
self.assertTrue(not self.sandbox.exists('oops.csv'),
#.........这里部分代码省略.........
示例5: TestICOverride
# 需要导入模块: from JSBSim_utils import SandBox [as 别名]
# 或者: from JSBSim_utils.SandBox import delete_csv_files [as 别名]
class TestICOverride(unittest.TestCase):
def setUp(self):
self.sandbox = SandBox()
def tearDown(self):
self.sandbox.erase()
def test_IC_override(self):
# Run the script c1724.xml
script_path = self.sandbox.path_to_jsbsim_file('scripts', 'c1724.xml')
fdm = CreateFDM(self.sandbox)
fdm.load_script(script_path)
vt0 = fdm.get_property_value('ic/vt-kts')
fdm.run_ic()
self.assertEqual(fdm.get_property_value('simulation/sim-time-sec'), 0.0)
self.assertAlmostEqual(fdm.get_property_value('velocities/vt-fps'),
vt0 / fpstokts, delta=1E-7)
ExecuteUntil(fdm, 1.0)
# Check that the total velocity exported in the output file matches the
# IC defined in the initialization file
ref = Table()
ref.ReadCSV(self.sandbox('JSBout172B.csv'))
self.assertEqual(ref.get_column('Time')[1], 0.0)
self.assertAlmostEqual(ref.get_column('V_{Total} (ft/s)')[1],
vt0 / fpstokts, delta=1E-7)
# Now, we will re-run the same test but the IC will be overridden in the
# script. The initial total velocity is increased by 1 ft/s
vt0 += 1.0
# The script c1724.xml is loaded and the following line is added in it:
# <property value="..."> ic/vt-kts </property>
# The modified script is then saved with the named 'c1724_0.xml'
tree = et.parse(self.sandbox.elude(script_path))
run_tag = tree.getroot().find("./run")
property = et.SubElement(run_tag, 'property')
property.text = 'ic/vt-kts'
property.attrib['value'] = str(vt0)
tree.write(self.sandbox('c1724_0.xml'))
# Re-run the same check than above. This time we are making sure than
# the total initial velocity is increased by 1 ft/s
self.sandbox.delete_csv_files()
# Because JSBSim internals use static pointers, we cannot rely on Python
# garbage collector to decide when the FDM is destroyed otherwise we can
# get dangling pointers.
del fdm
fdm = CreateFDM(self.sandbox)
fdm.load_script('c1724_0.xml')
self.assertAlmostEqual(fdm.get_property_value('ic/vt-kts'), vt0,
delta=1E-6)
fdm.run_ic()
self.assertEqual(fdm.get_property_value('simulation/sim-time-sec'), 0.0)
self.assertAlmostEqual(fdm.get_property_value('velocities/vt-fps'),
vt0 / fpstokts, delta=1E-6)
ExecuteUntil(fdm, 1.0)
mod = Table()
mod.ReadCSV(self.sandbox('JSBout172B.csv'))
self.assertAlmostEqual(mod.get_column('V_{Total} (ft/s)')[1],
vt0 / fpstokts, delta=1E-6)