Esempio n. 1
0
    def test__connect_to_application__close_application__application_has_closed(
            self) -> None:
        kill_all_open_flexloggers()
        app = Application.launch()
        # Opening a project will make closing the application take longer
        app.open_project(get_project_path("DefaultProject"))

        app2 = Application(app.server_port)
        app2.close()

        assert_no_flexloggers_running()
Esempio n. 2
0
 def test__launch_application__launch_application_again__raises_exception(
         self) -> None:
     kill_all_open_flexloggers()
     with Application.launch():
         # We expect this to fail because we don't support multiple instances of FlexLogger
         # running at the same time.
         new_app = None
         try:
             with pytest.raises(RuntimeError):
                 new_app = Application.launch(timeout=20)
         finally:
             # if the test fails, try not to mess up future tests
             if new_app is not None:
                 new_app.close()
Esempio n. 3
0
 def test__launch_application__close_application__using_application_raises_exception(
     self, ) -> None:
     kill_all_open_flexloggers()
     app = Application.launch()
     app.close()
     with pytest.raises(FlexLoggerError):
         app.open_project(get_project_path("DefaultProject"))
Esempio n. 4
0
 def test__close_project_with_channels__get_value__exception_raised(
         self, app: Application) -> None:
     project = app.open_project(get_project_path("ProjectWithProducedData"))
     channel_specification = project.open_channel_specification_document()
     project.close()
     with pytest.raises(FlexLoggerError):
         channel_specification.get_channel_value("Channel 1")
Esempio n. 5
0
 def test__launch_flexlogger_and_disconnect__connect_to_existing_and_open_project__is_not_None(
     self, ) -> None:
     kill_all_open_flexloggers()
     project_path = get_project_path("DefaultProject")
     server_port = -1
     try:
         with Application.launch() as app:
             server_port = app.server_port
             # This should prevent FlexLogger from closing when app goes out of scope
             app.disconnect()
         with Application(server_port=server_port) as app:
             project = app.open_project(project_path)
             assert project is not None
     finally:
         if server_port != -1:
             Application(server_port=server_port).close()
 def test__close_project__get_test_properties__exception_raised(
         self, app: Application) -> None:
     project = app.open_project(get_project_path("ProjectWithProducedData"))
     logging_specification = project.open_logging_specification_document()
     project.close()
     with pytest.raises(FlexLoggerError):
         logging_specification.get_test_properties()
Esempio n. 7
0
 def test__open_project__active_project_path_matches_loaded_path(
         self) -> None:
     with copy_project("DefaultProject") as new_project_path:
         with Application.launch() as app:
             project = app.open_project(new_project_path)
             assert os.path.samefile(project.project_file_path,
                                     new_project_path)
Esempio n. 8
0
 def test__launch_application__open_and_close_project__active_project_is_none(
         self) -> None:
     kill_all_open_flexloggers()
     with Application.launch() as app:
         project = app.open_project(get_project_path("DefaultProject"))
         project.close()
         active_project = app.get_active_project()
         assert active_project is None
Esempio n. 9
0
 def test__launch_application__open_project__active_project_matches_open_project(
         self) -> None:
     kill_all_open_flexloggers()
     with Application.launch() as app:
         project = app.open_project(get_project_path("DefaultProject"))
         active_project = app.get_active_project()
         assert active_project is not None
         assert project._identifier == active_project._identifier
Esempio n. 10
0
 def test__open_project__close_application__using_project_raises_exception(
         self) -> None:
     kill_all_open_flexloggers()
     app = Application.launch()
     project = app.open_project(get_project_path("DefaultProject"))
     app.close()
     with pytest.raises(FlexLoggerError):
         project.open_channel_specification_document()
Esempio n. 11
0
 def test__open_project__close_project__using_original_project_raises_exception(
         self) -> None:
     kill_all_open_flexloggers()
     project_path = get_project_path("DefaultProject")
     with Application.launch() as app:
         first_project = app.open_project(project_path)
         first_project.close()
         with pytest.raises(FlexLoggerError):
             first_project.open_channel_specification_document()
Esempio n. 12
0
 def test__make_change_to_project__close_application__no_save_dialog_box(
         self) -> None:
     kill_all_open_flexloggers()
     with copy_project("ProjectWithProducedData") as new_project_path:
         with Application.launch() as app:
             project = app.open_project(new_project_path)
             logging_specification = project.open_logging_specification_document(
             )
             logging_specification.set_log_file_name("SomeNewName")
Esempio n. 13
0
def main(project_path):
    """Launch FlexLogger, open a project, and get the loaded project's file path."""
    with Application.launch() as app:
        project = app.open_project(path=project_path)
        print("Project file path: " + str(project.project_file_path))
        print("Press Enter to close the project...")
        input()
        project.close()
    return 0
Esempio n. 14
0
    def test__launch_application__close_application__application_has_closed(
            self) -> None:
        kill_all_open_flexloggers()

        with Application.launch() as app:
            # Opening a project will make closing the application take longer
            app.open_project(get_project_path("DefaultProject"))

        assert_no_flexloggers_running()
Esempio n. 15
0
 def test__open_project__open_different_project__using_original_project_raises_exception(
     self, ) -> None:
     kill_all_open_flexloggers()
     project_path = get_project_path("DefaultProject")
     second_project_path = get_project_path("ProjectWithTestProperties")
     with Application.launch() as app:
         first_project = app.open_project(project_path)
         app.open_project(second_project_path)
         with pytest.raises(FlexLoggerError):
             first_project.open_channel_specification_document()
Esempio n. 16
0
def main(project_path):
    """Launch FlexLogger, open a project, start and stop the test session."""
    with Application.launch() as app:
        project = app.open_project(path=project_path)
        test_session = project.test_session
        test_session.start()
        print("Test started. Press Enter to stop the test and close the project...")
        input()
        test_session.stop()
        project.close()
    return 0
def main(project_path):
    """Launch FlexLogger, open a project, and disables a channel."""
    with Application.launch() as app:
        project = app.open_project(path=project_path)
        channel_name = input("Enter the name of the channel to disable: ")
        channel_specification = project.open_channel_specification_document()
        channel_specification.set_channel_enabled(channel_name, False)
        print("Channel disabled. Press Enter to close the project...")
        input()
        project.close()
    return 0
def main():
    """Connect to an already running instance of FlexLogger with an open project

    Note that before connecting to an already running instance of FlexLogger,
    the Automation server preference must be enabled. You can enable this preference by opening the
    "File>>Preferences" menu item, and then enabling the "Automation server" preference in the
    "General" tab.
    """
    app = Application()
    project = app.get_active_project()
    if project is None:
        print("No project is open in FlexLogger!")
        return 1
    test_session_state = project.test_session.state
    print("The test session state is:")
    print(test_session_state)
    print("Press Enter to disconnect from FlexLogger...")
    input()
    app.disconnect()
    return 0
Esempio n. 19
0
def open_project(application: Application, project_name: str) -> Iterator[Project]:
    """Copy the project with name project_name in the assets directory to a temp directory and open it.

    This function returns a ContextManager, so it should be used in a `with` statement,
    and when it goes out of scope it will close the project and delete the temporary directory.
    """
    with copy_project(project_name) as project_path:
        project = application.open_project(project_path)
        try:
            yield project
        finally:
            project.close()
def app() -> Iterator[Application]:
    """Fixture for launching FlexLogger.

    This is useful to improve test time by not launching/closing FlexLogger in every test.
    """
    app = Application.launch()
    yield app
    try:
        app.close()
    except FlexLoggerError:
        # utils.kill_all_open_flexloggers may have killed this process already, that's fine
        pass
def main(project_path):
    """Launch FlexLogger, open a project, and gets the log file base path and name."""
    with Application.launch() as app:
        project = app.open_project(path=project_path)
        logging_specification = project.open_logging_specification_document()
        log_file_base_path = logging_specification.get_log_file_base_path()
        log_file_name = logging_specification.get_log_file_name()
        print("Log file base path: " + log_file_base_path)
        print("Log file name: " + log_file_name)
        print("Press Enter to close the project...")
        input()
        project.close()
    return 0
Esempio n. 22
0
 def test__disconnect_application__using_application_raises_exception(
         self) -> None:
     kill_all_open_flexloggers()
     original_app = Application.launch()
     try:
         new_app = Application(server_port=original_app.server_port)
         new_app.disconnect()
         with pytest.raises(FlexLoggerError):
             new_app.open_project(get_project_path("DefaultProject"))
     finally:
         original_app.close()
def project_with_produced_data(app: Application) -> Iterator[Project]:
    """Fixture for opening ProjectWithProducedData.

    This is useful to improve test time by not opening/closing this project in every test.
    """
    with copy_project("ProjectWithProducedData") as project_path:
        project = app.open_project(project_path)
        yield project
        try:
            project.close()
        except FlexLoggerError:
            # utils.kill_all_open_flexloggers may have killed this process already, that's fine
            pass
Esempio n. 24
0
 def test__remove_channel_specification_file__open_project__raises_exception(
         self, app: Application) -> None:
     with copy_project("DefaultProject") as project_path:
         cache_dir = project_path.parent / ".cache"
         if cache_dir.exists():
             rmtree(str(cache_dir))
         (project_path.parent / "Channel Specification.flxio").unlink()
         project = None
         try:
             with pytest.raises(FlexLoggerError):
                 project = app.open_project(project_path)
         finally:
             if project is not None:
                 project.close()
def main(project_path):
    """Launch FlexLogger, open a project, and sets the value of a test property."""
    with Application.launch() as app:
        project = app.open_project(path=project_path)
        test_property_name = input(
            "Enter the name of the test property to set the value of: ")
        test_property_value = input("Enter the test property value: ")
        logging_specification = project.open_logging_specification_document()
        logging_specification.set_test_property(test_property_name,
                                                test_property_value)
        print("Test property set. Press Enter to close the project...")
        input()
        project.close()
    return 0
Esempio n. 26
0
def main(project_path):
    """Launch FlexLogger, open a project, and get the value of a channel."""
    with Application.launch() as app:
        project = app.open_project(path=project_path)
        channel_name = input(
            "Enter the name of the channel to get the value of: ")
        channel_specification = project.open_channel_specification_document()
        channel_value = channel_specification.get_channel_value(channel_name)
        print("Channel value:")
        print(channel_value)
        print("Press Enter to close the project...")
        input()
        project.close()
    return 0
def main(argv: List[str]) -> int:
    """Connect to FlexLogger and start a test"""
    with Application.launch() as app:
        project = app.open_project(argv[0])
        temp_dir = argv[1]
        logging_specification = project.open_logging_specification_document()
        logging_specification.set_log_file_base_path(temp_dir)
        logging_specification.set_log_file_name("ShouldNotExist.tdms")
        logging_specification.set_test_property("prompts on start",
                                                "some value", True)
        project.test_session.start()
        # Make sure that if this does start running, it will actually log data
        # before we close the project.
        time.sleep(5)
    return 0
def main(project_path):
    """Launch FlexLogger, open a project, start the test session and add a note."""
    with Application.launch() as app:
        project = app.open_project(path=project_path)
        test_session = project.test_session
        test_session.start()
        note = input("Test started. Enter a note to log: ")
        test_session.add_note(note)
        print(
            "Note added. Press Enter to stop the test and close the project..."
        )
        input()

        test_session.stop()
        project.close()
    return 0
Esempio n. 29
0
def main(project_path):
    """Interactively manage the state of the FlexLogger project test session.

    Launch FlexLogger, open the specified project and interactively
    manage the state of the FlexLogger project test session.
    """
    print("Launching FlexLogger . . .")
    with Application.launch() as app:
        print("Loading FlexLogger project . . .")
        project = app.open_project(path=project_path)
        test_session = project.test_session

        _show_interactive_menu(test_session)

        print("Closing FlexLogger project . . .")
        project.close()
    return 0
def main(project_path):
    """Interactively get and set FlexLogger channel values.

    Launch FlexLogger, open the specified project and interactively
    get and set FlexLogger channel values.
    """
    print("Launching FlexLogger . . .")
    with Application.launch() as app:
        print("Loading FlexLogger project . . .")
        project = app.open_project(path=project_path)
        channel_specification_document = project.open_channel_specification_document(
        )

        _show_interactive_menu(channel_specification_document)

        print("Closing FlexLogger project . . .")
        project.close()
    return 0