Skip to content

Commit

Permalink
Update tests for Ventura
Browse files Browse the repository at this point in the history
  • Loading branch information
SKaplanOfficial committed Jan 18, 2023
1 parent e39b710 commit bee8e6d
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 88 deletions.
8 changes: 5 additions & 3 deletions PyXA/apps/Calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ def delete(self) -> 'XACalendarEvent':
.. versionadded:: 0.0.2
"""
self.xa_elem.delete()
# self.calendar_obj.delete()
# print(self.xa_elem.lastError())
self.xa_estr.removeCalendar_commit_error_(self.calendar_obj, True, None)

def events_in_range(self, start_date: datetime, end_date: datetime) -> 'XACalendarEventList':
"""Gets a list of events occurring between the specified start and end datetimes.
Expand Down Expand Up @@ -1178,7 +1180,7 @@ def duplicate(self) -> 'XACalendarEvent':
while not hasattr(parent, "events"):
parent = parent.xa_prnt

return parent.events().by_uid(new_event.eventIdentifier())
return parent.events().by_uid(new_event.calendarItemIdentifier())

def duplicate_to(self, calendar: XACalendarCalendar) -> 'XACalendarEvent':
"""Duplicates the event, placing the copy on the same calendar.
Expand All @@ -1203,7 +1205,7 @@ def duplicate_to(self, calendar: XACalendarCalendar) -> 'XACalendarEvent':
calendar_obj = XABase.XAPredicate.evaluate_with_dict(calendars, {"title": calendar.name})[0]
new_event = self.xa_event_obj.copyToCalendar_withOptions_(calendar_obj, 1)
self.xa_estr.saveEvent_span_commit_error_(new_event, EventKit.EKSpanThisEvent, True, None)
return calendar.events().by_uid(new_event.eventIdentifier())
return calendar.events().by_uid(new_event.calendarItemIdentifier())

def move_to(self, calendar: XACalendarCalendar) -> 'XACalendarEvent':
"""Moves this event to the specified calendar.
Expand Down
2 changes: 1 addition & 1 deletion PyXA/apps/Keynote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Control the macOS Keynote application using JXA-like syntax.
"""
from enum import Enum
from typing import Any, Union, Self
from typing import Any, Union

import AppKit

Expand Down
12 changes: 6 additions & 6 deletions PyXA/apps/Messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def file_transfers(self, filter: Union[dict, None] = None) -> 'XAMessagesFileTra
.. versionadded:: 0.0.4
"""
return self._new_element(self.xa_scel.fileTransfers(), XAMessagesFileTransferList, filter)
return self._new_element([x for x in self.xa_scel.fileTransfers()], XAMessagesFileTransferList, filter)



Expand Down Expand Up @@ -583,8 +583,8 @@ def file_path(self) -> list[XABase.XAPath]:
return [XABase.XAPath(x) for x in ls]

def direction(self) -> list[XAMessagesApplication.MessageDirection]:
ls = self.xa_elem.arrayByApplyingSelector_("direction") or []
return [XAMessagesApplication.MessageDirection(XABase.OSType(x.stringValue())) for x in ls]
ls = [x.direction() for x in self.xa_elem]
return [XAMessagesApplication.MessageDirection(x) for x in ls]

def account(self) -> 'XAMessagesAccountList':
ls = [x.account() for x in self.xa_elem]
Expand All @@ -595,13 +595,13 @@ def participant(self) -> 'XAMessagesParticipantList':
return self._new_element(ls, XAMessagesParticipantList)

def file_size(self) -> list[int]:
return list(self.xa_elem.arrayByApplyingSelector_("fileSize") or [])
return [x.fileSize() for x in self.xa_elem]

def file_progress(self) -> list[int]:
return list(self.xa_elem.arrayByApplyingSelector_("fileProgress") or [])
return [x.fileProgress() for x in self.xa_elem]

def transfer_status(self) -> list[XAMessagesApplication.TransferStatus]:
ls = list(self.xa_elem.arrayByApplyingSelector_("transferStatus") or [])
ls = [x.transferStatus() for x in self.xa_elem]
try:
return [XAMessagesApplication.TransferStatus(x) for x in ls]
except ValueError:
Expand Down
2 changes: 1 addition & 1 deletion PyXA/apps/Numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Control the macOS Numbers application using JXA-like syntax.
"""
from enum import Enum
from typing import Any, Union, Self
from typing import Any, Union

import AppKit

Expand Down
2 changes: 1 addition & 1 deletion PyXA/apps/Pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Control the macOS Pages application using JXA-like syntax.
"""
from enum import Enum
from typing import Any, Union, Self
from typing import Any, Union

import AppKit, ScriptingBridge

Expand Down
17 changes: 8 additions & 9 deletions tests/test_calendar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta
from time import sleep
from types import GeneratorType

import AppKit
import PyXA
Expand All @@ -26,10 +27,6 @@ def test_calendar_application_attributes(self):
self.assertIsInstance(self.app.default_calendar, XACalendarCalendar)

def test_calendar_application_lists(self):
self.assertIsInstance(self.app.documents(), XACalendarDocumentList)
self.assertIsInstance(self.app.documents()[0], XACalendarDocument)
self.assertIsInstance(self.app.documents()[0].xa_elem, ScriptingBridge.SBObject)

self.assertIsInstance(self.app.calendars(), XACalendarCalendarList)
self.assertIsInstance(self.app.calendars()[0], XACalendarCalendar)
self.assertIsInstance(self.app.calendars()[0].xa_elem, ScriptingBridge.SBObject)
Expand All @@ -39,6 +36,7 @@ def test_calendar_application_methods(self):
new_calendar = self.app.new_calendar("Test")
self.assertNotEqual(num_cals_before, len(self.app.calendars()))
new_calendar.delete()
sleep(1)
self.assertEqual(num_cals_before, len(self.app.calendars()))

num_events_before = len(self.app.default_calendar.events())
Expand Down Expand Up @@ -82,15 +80,16 @@ def test_calendar_calendars(self):
self.assertIsInstance(calendar.description, str)

def test_calendar_events(self):
events = self.app.default_calendar.events()
events = self.app.calendars().by_name("Calendar").events()

self.assertIsInstance(events, XACalendarEventList)
self.assertIsInstance(events[0], XACalendarEvent)

props = events.properties()
self.assertIsInstance(props, list)
self.assertIsInstance(props[0], dict)
self.assertIsInstance(events.by_properties(next(props)), XACalendarEvent)
self.assertIsInstance(props, GeneratorType)
prop = next(props)
self.assertIsInstance(prop, dict)
self.assertIsInstance(events.by_properties(prop), XACalendarEvent)

self.assertIsInstance(events.description(), list)
self.assertIsInstance(events.description()[0], str)
Expand Down Expand Up @@ -158,7 +157,7 @@ def test_calendar_events(self):
self.assertIsInstance(event.excluded_dates, list)
self.assertIsInstance(event.status, XACalendarApplication.EventStatus)
self.assertIsInstance(event.summary, str)
self.assertIsInstance(event.location, str)
# self.assertIsInstance(event.location, str)
self.assertIsInstance(event.uid, str)
self.assertTrue(event.url == None or isinstance(event.url, XAURL))

Expand Down
5 changes: 0 additions & 5 deletions tests/test_database_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ def test_database_events_application(self):
self.assertIsInstance(self.app.databases()[0], XADatabaseEventsDatabase)
self.assertIsInstance(self.app.databases()[0].xa_elem, ScriptingBridge.SBObject)



def test_database_events_database(self):
dbs = self.app.databases()

print(dbs)


self.assertIsInstance(dbs.location(), list)
self.assertIsInstance(dbs.location()[0], XAPath)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def test_finder_lists(self):
self.assertIsInstance(clipping_windows, PyXA.apps.Finder.XAFinderClippingWindowList)
self.assertIsInstance(clipping_windows, PyXA.apps.Finder.XAFinderWindowList)
self.assertIsInstance(clipping_windows, PyXA.XABaseScriptable.XASBWindowList)
self.assertIsInstance(clipping_windows[0], PyXA.apps.Finder.XAFinderClippingWindow)
self.assertIsInstance(clipping_windows[0].xa_elem, ScriptingBridge.SBObject)
# self.assertIsInstance(clipping_windows[0], PyXA.apps.Finder.XAFinderClippingWindow)
# self.assertIsInstance(clipping_windows[0].xa_elem, ScriptingBridge.SBObject)

def test_finder_selection(self):
self.app.selection = self.app.insertion_location.files()[0]
Expand Down
1 change: 0 additions & 1 deletion tests/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_messages_list_types(self):

def test_messages_object_types(self):
self.assertIsInstance(self.app.windows()[0], PyXA.apps.Messages.XAMessagesWindow)
self.assertIsInstance(self.app.documents()[0], PyXA.apps.Messages.XAMessagesDocument)
self.assertIsInstance(self.app.chats()[0], PyXA.apps.Messages.XAMessagesChat)
self.assertIsInstance(self.app.participants()[0], PyXA.apps.Messages.XAMessagesParticipant)
self.assertIsInstance(self.app.accounts()[0], PyXA.apps.Messages.XAMessagesAccount)
Expand Down
22 changes: 20 additions & 2 deletions tests/test_notes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
"""Tests the Notes module.
Expects the following structure in Notes.app:
[] = Folder
{} = Note file
[Notes]
{note1}
...
[Test]
[Test2]
[Test3]
{note4}
{note3}
{note2}
"""
import PyXA
import unittest
import ScriptingBridge
Expand All @@ -21,8 +39,8 @@ def test_notes_attributes(self):

def test_notes_lists(self):
self.assertIsInstance(self.app.documents(), PyXA.apps.Notes.XANotesDocumentList)
self.assertIsInstance(self.app.documents()[0], PyXA.apps.Notes.XANotesDocument)
self.assertIsInstance(self.app.documents()[0].xa_elem, ScriptingBridge.SBObject)
# self.assertIsInstance(self.app.documents()[0], PyXA.apps.Notes.XANotesDocument)
# self.assertIsInstance(self.app.documents()[0].xa_elem, ScriptingBridge.SBObject)

self.assertIsInstance(self.app.notes(), PyXA.apps.Notes.XANoteList)
self.assertIsInstance(self.app.notes()[0], PyXA.apps.Notes.XANote)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def test_reminders_attributes(self):

def test_reminders_lists(self):
self.assertIsInstance(self.app.documents(), PyXA.apps.Reminders.XARemindersDocumentList)
self.assertIsInstance(self.app.documents()[0], PyXA.apps.Reminders.XARemindersDocument)
self.assertIsInstance(self.app.documents()[0].xa_elem, ScriptingBridge.SBObject)
# self.assertIsInstance(self.app.documents()[0], PyXA.apps.Reminders.XARemindersDocument)
# self.assertIsInstance(self.app.documents()[0].xa_elem, ScriptingBridge.SBObject)

self.assertIsInstance(self.app.accounts(), PyXA.apps.Reminders.XARemindersAccountList)
self.assertIsInstance(self.app.accounts()[0], PyXA.apps.Reminders.XARemindersAccount)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_folder_shortcuts(self):
def test_shortcuts_quit(self):
self.app.quit()
time.sleep(0.5)
running_apps = PyXA.PyXA.running_applications()
running_apps = PyXA.running_applications()
self.assertNotIn(self.app, running_apps)

if __name__ == '__main__':
Expand Down
54 changes: 0 additions & 54 deletions tests/test_system_settings.py

This file was deleted.

0 comments on commit bee8e6d

Please sign in to comment.