Uploaded image for project: 'Nuxeo Drive '
  1. Nuxeo Drive
  2. NXDRIVE-1794

[macOS] Enable clipboard access in CI

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 4.1.4
    • Fix Version/s: 4.5.0
    • Component/s: Tests
    • Environment:
      macOS (CI only)

      Description

      Starting with macOS 10.11, the OS has a limitation about the clipboard usage: it's not possible to call CFPasteboardCreate when there is no pasteboard, i.e. when the computer is on the loginwindow.

      This is bad because we cannot test the "Copy-share link" context menu entry. The test is there, in test_context_menu.py, but disabled for macOS.

      We need to a way to have access to the clipboard, even (most importantly) from the CI.
      FTR, this is the current code (that works well outside the CI):

      @staticmethod
      def cb_copy(text: str) -> None:
          """Copy some *text* into the clipboard.
          Emulate: echo "blablabla" | pbcopy w
          """
          with subprocess.Popen(["pbcopy", "w"], stdin=subprocess.PIPE) as p:
              p.stdin.write(text.encode("utf-8"))
              p.stdin.close()
              p.wait()
      
      @staticmethod
      def cb_paste() -> str:
          data = subprocess.check_output(["pbpaste", "r"])
          return data.decode("utf-8")
      

      I used this code too, that works outside the CI (but I prefer to keep the previous code and not use the PyObjC module, it is less readable):

      @staticmethod
      def cb_copy(text: str) -> None:
          from AppKit import NSPasteboard, NSStringPboardType
          from Foundation import NSString, NSUTF8StringEncoding
      
          pb = NSPasteboard.generalPasteboard()
          pb.declareTypes_owner_([NSStringPboardType], None)
          newStr = NSString.stringWithString_(text)
          newData = newStr.nsstring().dataUsingEncoding_(NSUTF8StringEncoding)
          pb.setData_forType_(newData, NSStringPboardType)
      
      @staticmethod
      def cb_paste() -> str:
          from AppKit import NSPasteboard, NSStringPboardType
      
          pb = NSPasteboard.generalPasteboard()
          return pb.stringForType_(NSStringPboardType)
      

      This code suffers from the same issue.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mschoentgen Mickaël Schoentgen
                Reporter:
                mschoentgen Mickaël Schoentgen
                Participants:
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 5 minutes
                  5m