Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QT for Python and TDD (Test Driven Development)
Forum Updated to NodeBB v4.3 + New Features

QT for Python and TDD (Test Driven Development)

Scheduled Pinned Locked Moved Solved Qt for Python
8 Posts 3 Posters 361 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Greg Alvord
    wrote on 10 Dec 2024, 19:27 last edited by
    #1

    Pyside6 seems to use "lazy" creation.
    For example, after creating a failing test for QMainWindow then I add it, and the test passes as it should.
    Next, I wanted a menu bar. Since there was not one explicitly added by me I wrote a test for the menu bar expecting it to fail. The test passed.
    Because PySide6 automatically creates a menuBar() lazily when creating a QMainWindow instance I need a different approach than testing for the existence of things I have not yet created.

    I need some insights on how to use TDD in the context of QT implemented via PySide6.

    J 1 Reply Last reply 10 Dec 2024, 19:34
    0
    • G Greg Alvord
      10 Dec 2024, 19:27

      Pyside6 seems to use "lazy" creation.
      For example, after creating a failing test for QMainWindow then I add it, and the test passes as it should.
      Next, I wanted a menu bar. Since there was not one explicitly added by me I wrote a test for the menu bar expecting it to fail. The test passed.
      Because PySide6 automatically creates a menuBar() lazily when creating a QMainWindow instance I need a different approach than testing for the existence of things I have not yet created.

      I need some insights on how to use TDD in the context of QT implemented via PySide6.

      J Offline
      J Offline
      JonB
      wrote on 10 Dec 2024, 19:34 last edited by JonB 12 Oct 2024, 19:35
      #2

      @Greg-Alvord
      Just so you know, this has nothing to do with PySide (or Python). It is the behaviour of Qt's QMainWindow. QMenuBar *QMainWindow::menuBar() const

      Returns the menu bar for the main window. This function creates and returns an empty menu bar if the menu bar does not exist.)

      That's just how it is, and probably equivalents elsewhere.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Greg Alvord
        wrote on 10 Dec 2024, 19:54 last edited by
        #3

        OK. However, I still need to know how to apply TDD paradyme when building with a QT based package. If QT creates stuff in anticipation of it being used that is fine as long are there is a strategy for writing tests that fail when work has not yet been done.

        S 1 Reply Last reply 10 Dec 2024, 20:03
        0
        • G Greg Alvord
          10 Dec 2024, 19:54

          OK. However, I still need to know how to apply TDD paradyme when building with a QT based package. If QT creates stuff in anticipation of it being used that is fine as long are there is a strategy for writing tests that fail when work has not yet been done.

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 10 Dec 2024, 20:03 last edited by
          #4

          @Greg-Alvord hi,

          Are you creating a subclass of QToolBar ? Then check the type of what is returned.

          Are you just creating a QToolBar and populate it before setting it ? Check that it should be not empty.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Greg Alvord
            wrote on 10 Dec 2024, 20:50 last edited by
            #5

            Thank you @SGaist.
            I conclude that I am going to need a boat load of interium tests to discovery what was auto created after each TDD interantion to prepare for the next one. Not what I was expecting, but also not unreasonable.

            1 Reply Last reply
            0
            • G Greg Alvord has marked this topic as solved on 10 Dec 2024, 20:51
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 10 Dec 2024, 21:56 last edited by
              #6

              No, you need to read the documentation of the classes you are going to use before writing your tests.

              There's not that many cases like QMainWindow's tool bar.

              Also, you should take the time to ponder about the test you are writing: do you really need a test to validate the presence of a QToolBar or do you rather need to test that when some action from that toolbar is triggered, some reaction happens ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              J 1 Reply Last reply 11 Dec 2024, 08:35
              2
              • S SGaist
                10 Dec 2024, 21:56

                No, you need to read the documentation of the classes you are going to use before writing your tests.

                There's not that many cases like QMainWindow's tool bar.

                Also, you should take the time to ponder about the test you are writing: do you really need a test to validate the presence of a QToolBar or do you rather need to test that when some action from that toolbar is triggered, some reaction happens ?

                J Offline
                J Offline
                JonB
                wrote on 11 Dec 2024, 08:35 last edited by
                #7

                @SGaist said in QT for Python and TDD (Test Driven Development):

                No, you need to read the documentation of the classes you are going to use before writing your tests.

                This I agree with 100%.

                There's not that many cases like QMainWindow's tool bar.

                Ummm. That depends on what the OP regards as such a "case". I don't know. Libraries often create objects for you, which seems to be what they are not happy with. A QTableWidget represents a table view UI plus a data model. It creates it for you, though you can replace it. Some overloads of QImage() allocate their own data area to copy the data passed in, some do not and use the data passed in as-is which must persist through its lifetime. And so on. I do not see which cases the OP will regard as problematic and which not.

                S 1 Reply Last reply 11 Dec 2024, 21:34
                1
                • J JonB
                  11 Dec 2024, 08:35

                  @SGaist said in QT for Python and TDD (Test Driven Development):

                  No, you need to read the documentation of the classes you are going to use before writing your tests.

                  This I agree with 100%.

                  There's not that many cases like QMainWindow's tool bar.

                  Ummm. That depends on what the OP regards as such a "case". I don't know. Libraries often create objects for you, which seems to be what they are not happy with. A QTableWidget represents a table view UI plus a data model. It creates it for you, though you can replace it. Some overloads of QImage() allocate their own data area to copy the data passed in, some do not and use the data passed in as-is which must persist through its lifetime. And so on. I do not see which cases the OP will regard as problematic and which not.

                  S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 11 Dec 2024, 21:34 last edited by
                  #8

                  @JonB in that case the OP would be testing Qt rather than his own code.

                  Nothing wrong with writing tests that allows to understand and confirm how a given framework works as advertised but it should not be the base for the tests of your actual code as it is a different goal.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1

                  1/8

                  10 Dec 2024, 19:27

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved