Пример #1
0
class TestScriptOutput(unittest.TestCase):
    def setUp(self):
        self.sandbox = SandBox()
        self.script_path = self.sandbox.path_to_jsbsim_file('scripts',
                                                            'c1722.xml')

    def tearDown(self):
        self.sandbox.erase()

    def test_no_output(self):
        fdm = CreateFDM(self.sandbox)
        fdm.load_script(self.script_path)
        fdm.run_ic()
        ExecuteUntil(fdm, 10.)

        self.assertFalse(self.sandbox.exists('output.csv'),
                         msg="Results have unexpectedly been written to 'output.csv'")

    def test_output_from_file(self):
        tree = et.parse(self.sandbox.elude(self.script_path))
        output_tag = et.SubElement(tree.getroot(), 'output')
        output_tag.attrib['file'] = self.sandbox.elude(self.sandbox.path_to_jsbsim_file('tests', 'output.xml'))
        tree.write(self.sandbox('c1722_0.xml'))

        fdm = CreateFDM(self.sandbox)
        fdm.load_script('c1722_0.xml')
        fdm.run_ic()
        ExecuteUntil(fdm, 10.)

        self.assertTrue(self.sandbox.exists('output.csv'),
                        msg="The file 'output.csv' has not been created")

    def test_output(self):
        tree = et.parse(self.sandbox.elude(self.script_path))
        output_tag = et.SubElement(tree.getroot(), 'output')
        output_tag.attrib['name'] = 'test.csv'
        output_tag.attrib['type'] = 'CSV'
        output_tag.attrib['rate'] = '10'
        property_tag = et.SubElement(output_tag, 'property')
        property_tag.text = 'position/vrp-radius-ft'
        tree.write(self.sandbox('c1722_0.xml'))

        fdm = CreateFDM(self.sandbox)
        fdm.load_script('c1722_0.xml')
        fdm.run_ic()
        ExecuteUntil(fdm, 10.)

        self.assertTrue(self.sandbox.exists(output_tag.attrib['name']),
                        msg="The file 'output.csv' has not been created")
        orig = pd.read_csv(self.sandbox('JSBout172B.csv'))
        test = pd.read_csv(self.sandbox('test.csv'))
        self.assertEqual(np.max(orig['Time']-test['Time']), 0.0)
        pname = '/fdm/jsbsim/' + property_tag.text
        self.assertEqual(np.max(orig[pname]-test[pname]), 0.0)
Пример #2
0
from JSBSim_utils import CreateFDM, ExecuteUntil, SandBox

sandbox = SandBox()

#
# 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(sandbox)
fdm.load_script(sandbox.path_to_jsbsim_file('scripts', 'c1722.xml'))

fdm.run_ic()
ExecuteUntil(fdm, 1.0)

if not sandbox.exists('JSBout172B.csv'):
  print "Standard run: the file 'JSBout172B.csv' should exist."
  sys.exit(-1) # 'make test' will report the test failed.

#
# Reset the simulation and check that iteration number is correctly appended to
# the filename.
#
fdm.reset_to_initial_conditions(1)
ExecuteUntil(fdm, 1.0)

if not sandbox.exists('JSBout172B_0.csv'):
  print "Reset: the file 'JSBout172B_0.csv' should exist."
  sys.exit(-1) # 'make test' will report the test failed.

#
Пример #3
0
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'),
                      msg="New FDM: 'oops.csv' should not exist.")
      self.assertTrue(self.sandbox.exists('JSBout172B.csv'),
                      msg="New FDM: 'JSBout172B.csv' should exist.")

      #
      # The new file name 'oops.csv' has been ignored.
      # Check if it is now taken into account.
      #
      fdm.reset_to_initial_conditions(1)
      ExecuteUntil(fdm, 1.0)

      self.assertTrue(self.sandbox.exists('oops.csv'),
                      msg="Reset new FDM: 'oops.csv' should exist.")
Пример #4
0
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'),
                        msg="New FDM: 'oops.csv' should not exist.")
        self.assertTrue(self.sandbox.exists('JSBout172B.csv'),
                        msg="New FDM: 'JSBout172B.csv' should exist.")

        #
        # The new file name 'oops.csv' has been ignored.
        # Check if it is now taken into account.
        #
        fdm.reset_to_initial_conditions(1)
        ExecuteUntil(fdm, 1.0)

        self.assertTrue(self.sandbox.exists('oops.csv'),
                        msg="Reset new FDM: 'oops.csv' should exist.")