Skip to content

Commit

Permalink
Use snapshots for tests (#37)
Browse files Browse the repository at this point in the history
* Add syrupy

* Use snapshots for modules

* Fix

* Change the rest

* Remove unused imports

* Remove unused imports
  • Loading branch information
timmo001 committed Apr 7, 2024
1 parent ea77cf8 commit 3fd80b1
Show file tree
Hide file tree
Showing 58 changed files with 775 additions and 790 deletions.
1 change: 1 addition & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pytest-cov==5.0.0
pytest-sugar==1.0.0
pytest-timeout==2.3.1
pytest==8.1.1
syrupy==4.6.1
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_action.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_action
Action(command='command', data={'key': 'value'}, label='label')
# ---
26 changes: 26 additions & 0 deletions tests/__snapshots__/test_const.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# serializer version: 1
# name: test_model_map
dict({
<Model.BATTERY: 'battery'>: <class 'systembridgemodels.modules.battery.Battery'>,
<Model.CPU: 'cpu'>: <class 'systembridgemodels.modules.cpu.CPU'>,
<Model.DATA: 'data'>: <class 'systembridgemodels.modules.ModulesData'>,
<Model.DISKS: 'disks'>: <class 'systembridgemodels.modules.disks.Disks'>,
<Model.DISPLAYS: 'displays'>: <class 'systembridgemodels.modules.displays.Display'>,
<Model.GPUS: 'gpus'>: <class 'systembridgemodels.modules.gpus.GPU'>,
<Model.KEYBOARD_KEY: 'keyboard_key'>: <class 'systembridgemodels.keyboard_key.KeyboardKey'>,
<Model.KEYBOARD_TEXT: 'keyboard_text'>: <class 'systembridgemodels.keyboard_text.KeyboardText'>,
<Model.MEDIA: 'media'>: <class 'systembridgemodels.modules.media.Media'>,
<Model.MEDIA_DIRECTORIES: 'media_directories'>: <class 'systembridgemodels.media_directories.MediaDirectory'>,
<Model.MEDIA_FILE: 'media_file'>: <class 'systembridgemodels.media_files.MediaFile'>,
<Model.MEDIA_FILES: 'media_files'>: <class 'systembridgemodels.media_files.MediaFiles'>,
<Model.MEMORY: 'memory'>: <class 'systembridgemodels.modules.memory.Memory'>,
<Model.NETWORKS: 'networks'>: <class 'systembridgemodels.modules.networks.Networks'>,
<Model.NOTIFICATION: 'notification'>: <class 'systembridgemodels.notification.Notification'>,
<Model.OPEN_PATH: 'open_path'>: <class 'systembridgemodels.open_path.OpenPath'>,
<Model.OPEN_URL: 'open_url'>: <class 'systembridgemodels.open_url.OpenUrl'>,
<Model.PROCESSES: 'processes'>: <class 'systembridgemodels.modules.processes.Process'>,
<Model.RESPONSE: 'response'>: <class 'systembridgemodels.response.Response'>,
<Model.SENSORS: 'sensors'>: <class 'systembridgemodels.modules.sensors.Sensors'>,
<Model.SYSTEM: 'system'>: <class 'systembridgemodels.modules.system.System'>,
})
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_keyboard_key.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_keyboard_key
KeyboardKey(key='A')
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_keyboard_text.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_keyboard_text
KeyboardText(text='Test')
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_media_control.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_media_control
MediaControl(action='PLAY', value=True)
# ---
6 changes: 6 additions & 0 deletions tests/__snapshots__/test_media_directories.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# serializer version: 1
# name: test_media_directories
list([
MediaDirectory(key='music', path='path/to/file'),
])
# ---
27 changes: 27 additions & 0 deletions tests/__snapshots__/test_media_files.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# serializer version: 1
# name: test_media_files
MediaFiles(files=[MediaFile(name='file1', path='path/to/file1', fullpath='/full/path/to/file1', size=100, last_accessed=100.0, created=100.0, modified=100.0, is_directory=False, is_file=True, is_link=False, mime_type='text/plain')], path='path/to/file')
# ---
# name: test_media_files_dict
dict({
'files': list([
dict({
'created': 100.0,
'fullpath': '/full/path/to/file1',
'is_directory': False,
'is_file': True,
'is_link': False,
'last_accessed': 100.0,
'mime_type': 'text/plain',
'modified': 100.0,
'name': 'file1',
'path': 'path/to/file1',
'size': 100,
}),
]),
'path': 'path/to/file',
})
# ---
# name: test_media_files_dict[media-files-dict-converted]
MediaFiles(files=[MediaFile(name='file1', path='path/to/file1', fullpath='/full/path/to/file1', size=100, last_accessed=100.0, created=100.0, modified=100.0, is_directory=False, is_file=True, is_link=False, mime_type='text/plain')], path='path/to/file')
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_media_get_file.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_media_get_file
MediaGetFile(base='music', path='path/to/file')
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_media_get_files.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_media_get_files
MediaGetFiles(base='music', path='path/to/file')
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_media_play.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_media_play
MediaPlay(url='https://www.example.com/audio.mp3', album='Album', artist='Artist', autoplay=True, cover='https://www.example.com/cover.png', title='Title', volume=100)
# ---
29 changes: 29 additions & 0 deletions tests/__snapshots__/test_notification.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# serializer version: 1
# name: test_notification
Notification(title='Title', message='Message', icon='https://www.example.com/icon.png', image='https://www.example.com/image.png', actions=[Action(command='COMMAND_TEST', label='LABEL_TEST', data={'test': 'test'})], timeout=1000, audio=Audio(source='https://www.example.com/audio.mp3', volume=100))
# ---
# name: test_notification_dict
dict({
'actions': list([
dict({
'command': 'COMMAND_TEST',
'data': dict({
'test': 'test',
}),
'label': 'LABEL_TEST',
}),
]),
'audio': dict({
'source': 'https://www.example.com/audio.mp3',
'volume': 100,
}),
'icon': 'https://www.example.com/icon.png',
'image': 'https://www.example.com/image.png',
'message': 'Message',
'timeout': 1000,
'title': 'Title',
})
# ---
# name: test_notification_dict[notification-dict-converted]
Notification(title='Title', message='Message', icon='https://www.example.com/icon.png', image='https://www.example.com/image.png', actions=[Action(command='COMMAND_TEST', label='LABEL_TEST', data={'test': 'test'})], timeout=1000, audio=Audio(source='https://www.example.com/audio.mp3', volume=100))
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_open_path.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_open_path
OpenPath(path='/path/to/file')
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_open_url.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_open_url
OpenUrl(url='https://www.example.com')
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_request.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_request
Request(id='abc123', event='EVENT_TEST', data={'test': 'test'})
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_response.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_response
Response(id='abc123', type='TYPE_TEST', data={'test': 'test'}, subtype='SUBTYPE_TEST', message='MESSAGE_TEST', module='MODULE_TEST')
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_settings.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_settings
Settings(api=SettingsAPI(token='token', port=9170), autostart=False, keyboard_hotkeys=[], log_level='INFO', media=SettingsMedia(directories=[]))
# ---
4 changes: 4 additions & 0 deletions tests/__snapshots__/test_update.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_update
Update(version='4.1.1.dev0')
# ---
4 changes: 4 additions & 0 deletions tests/modules/__snapshots__/test_battery.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_battery
Battery(is_charging=True, percentage=98.4, time_remaining=12)
# ---
99 changes: 99 additions & 0 deletions tests/modules/__snapshots__/test_cpu.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# serializer version: 1
# name: test_cpu
CPU(count=4, frequency=CPUFrequency(current=2.3, min=0.8, max=3.1), load_average=1.5, per_cpu=[PerCPU(id=0, frequency=CPUFrequency(current=2.3, min=0.8, max=3.1), power=50.0, times=CPUTimes(user=120.0, system=30.0, idle=600.0, interrupt=0.0, dpc=0.0), times_percent=CPUTimes(user=20.0, system=5.0, idle=100.0, interrupt=0.0, dpc=0.0), usage=20.0, voltage=1.2)], power=200.0, stats=CPUStats(ctx_switches=1000, interrupts=500, soft_interrupts=200, syscalls=8000), temperature=45.0, times=CPUTimes(user=480.0, system=120.0, idle=2400.0, interrupt=0.0, dpc=0.0), times_percent=CPUTimes(user=80.0, system=20.0, idle=400.0, interrupt=0.0, dpc=0.0), usage=80.0, voltage=1.2)
# ---
# name: test_cpu_dict
dict({
'count': 4,
'frequency': dict({
'current': 2.3,
'max': 3.1,
'min': 0.8,
}),
'load_average': 1.5,
'per_cpu': list([
dict({
'frequency': dict({
'current': 2.3,
'max': 3.1,
'min': 0.8,
}),
'id': 0,
'power': 50.0,
'times': dict({
'dpc': 0.0,
'idle': 600.0,
'interrupt': 0.0,
'system': 30.0,
'user': 120.0,
}),
'times_percent': dict({
'dpc': 0.0,
'idle': 100.0,
'interrupt': 0.0,
'system': 5.0,
'user': 20.0,
}),
'usage': 20.0,
'voltage': 1.2,
}),
]),
'power': 200.0,
'stats': dict({
'ctx_switches': 1000,
'interrupts': 500,
'soft_interrupts': 200,
'syscalls': 8000,
}),
'temperature': 45.0,
'times': dict({
'dpc': 0.0,
'idle': 2400.0,
'interrupt': 0.0,
'system': 120.0,
'user': 480.0,
}),
'times_percent': dict({
'dpc': 0.0,
'idle': 400.0,
'interrupt': 0.0,
'system': 20.0,
'user': 80.0,
}),
'usage': 80.0,
'voltage': 1.2,
})
# ---
# name: test_cpu_dict[cpu-dict-converted]
CPU(count=4, frequency=CPUFrequency(current=2.3, min=0.8, max=3.1), load_average=1.5, per_cpu=[PerCPU(id=0, frequency=CPUFrequency(current=2.3, min=0.8, max=3.1), power=50.0, times=CPUTimes(user=120.0, system=30.0, idle=600.0, interrupt=0.0, dpc=0.0), times_percent=CPUTimes(user=20.0, system=5.0, idle=100.0, interrupt=0.0, dpc=0.0), usage=20.0, voltage=1.2)], power=200.0, stats=CPUStats(ctx_switches=1000, interrupts=500, soft_interrupts=200, syscalls=8000), temperature=45.0, times=CPUTimes(user=480.0, system=120.0, idle=2400.0, interrupt=0.0, dpc=0.0), times_percent=CPUTimes(user=80.0, system=20.0, idle=400.0, interrupt=0.0, dpc=0.0), usage=80.0, voltage=1.2)
# ---
# name: test_cpu_per_cpu_dict
dict({
'frequency': dict({
'current': 2.3,
'max': 3.1,
'min': 0.8,
}),
'id': 0,
'power': 50.0,
'times': dict({
'dpc': 0.0,
'idle': 600.0,
'interrupt': 0.0,
'system': 30.0,
'user': 120.0,
}),
'times_percent': dict({
'dpc': 0.0,
'idle': 100.0,
'interrupt': 0.0,
'system': 5.0,
'user': 20.0,
}),
'usage': 20.0,
'voltage': 1.2,
})
# ---
# name: test_cpu_per_cpu_dict[per-cpu-dict-converted]
PerCPU(id=0, frequency=CPUFrequency(current=2.3, min=0.8, max=3.1), power=50.0, times=CPUTimes(user=120.0, system=30.0, idle=600.0, interrupt=0.0, dpc=0.0), times_percent=CPUTimes(user=20.0, system=5.0, idle=100.0, interrupt=0.0, dpc=0.0), usage=20.0, voltage=1.2)
# ---
99 changes: 99 additions & 0 deletions tests/modules/__snapshots__/test_disks.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# serializer version: 1
# name: test_disks
Disks(devices=[Disk(name='name', partitions=[DiskPartition(device='device', mount_point='mountpoint', filesystem_type='fstype', options='options', max_file_size=1, max_path_length=2, usage=DiskUsage(total=1, used=2, free=3, percent=40.2))], io_counters=DiskIOCounters(read_count=3, write_count=4, read_bytes=1, write_bytes=2, read_time=5, write_time=6))], io_counters=DiskIOCounters(read_count=3, write_count=4, read_bytes=1, write_bytes=2, read_time=5, write_time=6))
# ---
# name: test_disks_devices_dict
dict({
'io_counters': dict({
'read_bytes': 1,
'read_count': 3,
'read_time': 5,
'write_bytes': 2,
'write_count': 4,
'write_time': 6,
}),
'name': 'name',
'partitions': list([
dict({
'device': 'device',
'filesystem_type': 'fstype',
'max_file_size': 1,
'max_path_length': 2,
'mount_point': 'mountpoint',
'options': 'options',
'usage': dict({
'free': 3,
'percent': 40.2,
'total': 1,
'used': 2,
}),
}),
]),
})
# ---
# name: test_disks_devices_dict[disks-devices-dict-converted]
Disk(name='name', partitions=[DiskPartition(device='device', mount_point='mountpoint', filesystem_type='fstype', options='options', max_file_size=1, max_path_length=2, usage=DiskUsage(total=1, used=2, free=3, percent=40.2))], io_counters=DiskIOCounters(read_count=3, write_count=4, read_bytes=1, write_bytes=2, read_time=5, write_time=6))
# ---
# name: test_disks_devices_partition_dict
dict({
'device': 'device',
'filesystem_type': 'fstype',
'max_file_size': 1,
'max_path_length': 2,
'mount_point': 'mountpoint',
'options': 'options',
'usage': dict({
'free': 3,
'percent': 40.2,
'total': 1,
'used': 2,
}),
})
# ---
# name: test_disks_devices_partition_dict[disks-devices-partition-dict-converted]
DiskPartition(device='device', mount_point='mountpoint', filesystem_type='fstype', options='options', max_file_size=1, max_path_length=2, usage=DiskUsage(total=1, used=2, free=3, percent=40.2))
# ---
# name: test_disks_dict
dict({
'devices': list([
dict({
'io_counters': dict({
'read_bytes': 1,
'read_count': 3,
'read_time': 5,
'write_bytes': 2,
'write_count': 4,
'write_time': 6,
}),
'name': 'name',
'partitions': list([
dict({
'device': 'device',
'filesystem_type': 'fstype',
'max_file_size': 1,
'max_path_length': 2,
'mount_point': 'mountpoint',
'options': 'options',
'usage': dict({
'free': 3,
'percent': 40.2,
'total': 1,
'used': 2,
}),
}),
]),
}),
]),
'io_counters': dict({
'read_bytes': 1,
'read_count': 3,
'read_time': 5,
'write_bytes': 2,
'write_count': 4,
'write_time': 6,
}),
})
# ---
# name: test_disks_dict[disks-dict-converted]
Disks(devices=[Disk(name='name', partitions=[DiskPartition(device='device', mount_point='mountpoint', filesystem_type='fstype', options='options', max_file_size=1, max_path_length=2, usage=DiskUsage(total=1, used=2, free=3, percent=40.2))], io_counters=DiskIOCounters(read_count=3, write_count=4, read_bytes=1, write_bytes=2, read_time=5, write_time=6))], io_counters=DiskIOCounters(read_count=3, write_count=4, read_bytes=1, write_bytes=2, read_time=5, write_time=6))
# ---
6 changes: 6 additions & 0 deletions tests/modules/__snapshots__/test_displays.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# serializer version: 1
# name: test_displays
list([
Display(id='abc123', name='name', resolution_horizontal=1920, resolution_vertical=1080, x=1920, y=1080, width=1920, height=1080, is_primary=True, pixel_clock=60.0, refresh_rate=60.0),
])
# ---
6 changes: 6 additions & 0 deletions tests/modules/__snapshots__/test_gpus.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# serializer version: 1
# name: test_gpus
list([
GPU(id='abc123', name='name', core_clock=1000.0, core_load=100.0, fan_speed=100.0, memory_clock=1000.0, memory_load=100.0, memory_free=1000.0, memory_used=1000.0, memory_total=1000.0, power_usage=100.0, temperature=100.0),
])
# ---
4 changes: 4 additions & 0 deletions tests/modules/__snapshots__/test_media.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# serializer version: 1
# name: test_media
Media(album_artist='Album Artist', album_title='Album Title', artist='Artist', duration=100, is_fast_forward_enabled=True, is_next_enabled=True, is_pause_enabled=True, is_play_enabled=True, is_previous_enabled=True, is_rewind_enabled=True, is_stop_enabled=True, playback_rate=1.0, position=100, repeat='repeat', shuffle=True, status='status', subtitle='subtitle', thumbnail='thumbnail', title='title', track_number=1, type='type', updated_at=100)
# ---
Loading

0 comments on commit 3fd80b1

Please sign in to comment.