Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 23 additions & 104 deletions maxdiff/tests/test.py
Original file line number Diff line number Diff line change
@@ -1,123 +1,42 @@
# Tests if the content of the test scripts is equal to the result of the conversion scripts.
# Tests if the contents of the stored textual representations (the baselines)
# are still equal to the results of the maxdiff conversion script.
# If not, displays the diff between the two.

import sys
import unittest
from io import StringIO
from unittest.mock import patch
import os.path
from test_parse import parse


class TestStringMethods(unittest.TestCase):
def test_parse_device(self):
def test_all_parsing(self):
self.maxDiff = None

expected_path, test_path = get_test_path_files("EncryptedTest.amxd")
files = [
"Test.amxd",
"EncryptedTest.amxd",
"FrozenTest.amxd",
"Test.maxpat",
"PatcherWithLocalStyles.maxpat",
"/Test Project/Zipped.als",
"/Test Project/Test.als",
"MalFormedJsonTest.maxpat",
"ConflictMarkerTest.maxpat",
"WithGarbage.amxd",
]

with open(expected_path, mode="r") as expected_file:
expected = expected_file.read()
actual = parse(test_path)
self.assertEqual(expected, actual)

def test_parse_encrypted_device(self):
self.maxDiff = None

expected_path, test_path = get_test_path_files("Test.amxd")

with open(expected_path, mode="r") as expected_file:
expected = expected_file.read()
actual = parse(test_path)
self.assertEqual(expected, actual)

def test_parse_frozen_device(self):
self.maxDiff = None

expected_path, test_path = get_test_path_files("FrozenTest.amxd")

with open(expected_path, mode="r") as expected_file:
expected = expected_file.read()
actual = parse(test_path)
self.assertEqual(expected, actual)

def test_parse_maxpat(self):
self.maxDiff = None

expected_path, test_path = get_test_path_files("Test.maxpat")

with open(expected_path, mode="r") as expected_file:
expected = expected_file.read()
actual = parse(test_path)

self.assertEqual(expected, actual)

def test_parse_maxpat_with_styles(self):
self.maxDiff = None
expected_path, test_path = get_test_path_files("PatcherWithLocalStyles.maxpat")

with open(expected_path, mode="r") as expected_file:
expected = expected_file.read()
actual = parse(test_path)

self.assertEqual(expected, actual)

def test_parse_als_zipped(self):
self.maxDiff = None

expected_path, test_path = get_test_path_files("/Test Project/Zipped.als")

with open(expected_path, mode="r") as expected_file:
expected = expected_file.read()
actual = parse(test_path)
self.assertEqual(expected, actual)

def test_parse_als_unzipped(self):
self.maxDiff = None

# result of an unzipped set should be same as a zipped set
expected_path, test_path = get_test_path_files("/Test Project/Test.als")

with open(expected_path, mode="r") as expected_file:
expected = expected_file.read()
actual = parse(test_path)
self.assertEqual(expected, actual)

def test_parse_malformed_maxpat(self):
self.maxDiff = None

expected_path, test_path = get_test_path_files("MalFormedJsonTest.maxpat")
for file_name in files:
with self.subTest(file=file_name):
self.assertDiffsEqual(file_name)

with open(expected_path, mode="r") as expected_file:
expected = expected_file.read()
actual = parse(test_path)
self.assertEqual(expected, actual)

def test_parse_maxpat_with_merge_conficts(self):
self.maxDiff = None

expected_path, test_path = get_test_path_files("ConflictMarkerTest.maxpat")

with open(expected_path, mode="r") as expected_file:
expected = expected_file.read()
actual = parse(test_path)
self.assertEqual(expected, actual)

def test_parse_with_garbage(self):
self.maxDiff = None

expected_path, test_path = get_test_path_files("WithGarbage.amxd")
def assertDiffsEqual(self, file_name):
test_path = get_test_path_file(f"test_files/{file_name}")
expected_path = get_test_path_file(f"test_baselines/{file_name}.txt")

with open(expected_path, mode="r") as expected_file:
expected = expected_file.read()
actual = parse(test_path)
self.assertEqual(expected, actual)


def get_test_path_files(file_name):
expected = get_test_path_file(f"test_baselines/{file_name}.txt")
test = get_test_path_file(f"test_files/{file_name}")

return (expected, test)
actual = parse(test_path)
self.assertEqual(expected, actual)


def get_test_path_file(file_name):
Expand Down
6 changes: 3 additions & 3 deletions maxdiff/tests/test_baselines/FrozenTest.amxd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ MIDI Effect Device
-------------------
Device is frozen
----- Contents -----
Test.amxd: 36528 bytes, modified at 2025/06/26 12:53:53 UTC <= Device
ParamAbstraction.maxpat: 1570 bytes, modified at 2024/05/24 13:59:36 UTC, 2 instances
MyAbstraction.maxpat: 2015 bytes, modified at 2025/02/14 11:10:38 UTC, 6 instances
Test.amxd: 36531 bytes, modified at 2026/01/28 10:27:01 UTC <= Device
ParamAbstraction.maxpat: 956 bytes, modified at 2026/01/28 10:25:56 UTC, 2 instances
MyAbstraction.maxpat: 1369 bytes, modified at 2026/01/28 10:26:01 UTC, 6 instances
AbstractionWithParameter.maxpat: 1569 bytes, modified at 2024/05/24 13:59:36 UTC, 2 instances
hz-icon.svg: 484 bytes, modified at 2024/05/24 13:59:36 UTC, 3 instances
beat-icon.svg: 533 bytes, modified at 2024/05/24 13:59:36 UTC, 3 instances
Expand Down
12 changes: 5 additions & 7 deletions maxdiff/tests/test_baselines/Test.amxd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ dependency_cache:
{'name': 'TestScript.js', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'TEXT', 'implicit': 1}
{'name': 'VisibleBang.js', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'TEXT', 'implicit': 1}
{'name': 'beat-icon.svg', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'svg', 'implicit': 1}
{'name': 'collContent.txt', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'TEXT', 'implicit': 1}
{'name': 'fpic.png', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'PNG', 'implicit': 1}
{'name': 'hz-icon.svg', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'svg', 'implicit': 1}
{'name': 'my-maxnode-basic.js', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'TEXT', 'implicit': 1}
{'name': 'myTestTable', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'TEXT', 'implicit': 1}
{'name': 'mystorage.json', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'JSON', 'implicit': 1}
{'name': 'myxfade.genjit', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'gJIT', 'implicit': 1}
{'name': 'shakerkicksnare.aif', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'AIFF', 'implicit': 1}
{'name': 'times3.gendsp', 'bootpath': '~/maxdevtools/maxdiff/tests/test_files', 'type': 'gDSP', 'implicit': 1}
Expand All @@ -39,7 +37,7 @@ project:
collContent.txt

----------- patcher -----------
appversion: 9.0.7-x64-1 | rect: [91, 153, 1288, 310] | openrect: [0, 0, 0, 169] | default_fontsize: 10.0 | default_fontname: Arial Bold | gridsize: [8, 8] | boxanimatetime: 500 | latency: 0 | is_mpe: 0 | external_mpe_tuning_enabled: 0 | platform_compatibility: 0 | autosave: 0
appversion: 9.0.10-x64-1 | rect: [91, 153, 1288, 310] | openrect: [0, 0, 0, 169] | default_fontsize: 10.0 | default_fontname: Arial Bold | gridsize: [8, 8] | boxanimatetime: 500 | latency: 0 | is_mpe: 0 | external_mpe_tuning_enabled: 0 | platform_compatibility: 0 | autosave: 0
----------- objects -----------
[comment NOTE: after any changes to this device, also update FrozenTest.amxd]
[poly~ MyAbstraction]
Expand All @@ -50,7 +48,7 @@ appversion: 9.0.7-x64-1 | rect: [91, 153, 1288, 310] | openrect: [0, 0, 0, 169]
[coll]
[p ImplicitDependencies] varname: ImplicitDependencies
----------- patcher -----------
appversion: 9.0.7-x64-1 | rect: [60, 130, 639, 710]
appversion: 9.0.10-x64-1 | rect: [60, 130, 639, 710]
----------- objects -----------
[js TestScript] filename: TestScript | parameter_enable: 0
[comment We would expect implicit dependencies for these but they don't seem to be added.] bubble: 1 | bubbleside: 2 | linecount: 2
Expand Down Expand Up @@ -83,7 +81,7 @@ appversion: 9.0.7-x64-1 | rect: [91, 153, 1288, 310] | openrect: [0, 0, 0, 169]
[message read myTestTable] (0) => (0) [table myTestTable]
[bpatcher ThisWasAnAbstractionBeforeEmbeddingIt.maxpat] embed: 1
----------- patcher -----------
appversion: 9.0.7-x64-1 | rect: [927, 431, 640, 480]
appversion: 9.0.10-x64-1 | rect: [927, 431, 640, 480]
----------- objects -----------
[live.comment Embedded]
[live.numbox] parameter: <longname: EmbeddedParam | modmode: 3 | shortname: Embedded | type: 0 | unitstyle: 0>
Expand All @@ -97,7 +95,7 @@ appversion: 9.0.7-x64-1 | rect: [91, 153, 1288, 310] | openrect: [0, 0, 0, 169]
[button]
[gen @t exponent]
----------- patcher -----------
appversion: 9.0.7-x64-1 | classnamespace: dsp.gen | rect: [84, 144, 653, 641]
appversion: 9.0.10-x64-1 | classnamespace: dsp.gen | rect: [84, 144, 653, 641]
----------- objects -----------
[codebox]
//============================================================
Expand Down Expand Up @@ -140,7 +138,7 @@ appversion: 9.0.7-x64-1 | rect: [91, 153, 1288, 310] | openrect: [0, 0, 0, 169]
[coll @embed 1] coll_data: {'count': 2, 'data': [{'key': 0, 'value': ['test']}, {'key': 1, 'value': ['another', 'test']}]} | embed: 1 | precision: 6
[p MySubpatcher]
----------- patcher -----------
appversion: 9.0.7-x64-1 | rect: [805, 282, 271, 250]
appversion: 9.0.10-x64-1 | rect: [805, 282, 271, 250]
----------- objects -----------
[live.dial] parameter: <longname: In a subpatcher | modmode: 0 | shortname: live.dial | type: 0 | unitstyle: 0>
[t b b]
Expand Down
2 changes: 1 addition & 1 deletion maxdiff/tests/test_baselines/Test.maxpat.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
----------- patcher -----------
appversion: 8.5.5-x64-1 | rect: [59, 106, 325, 253] | autosave: 0
appversion: 9.0.10-x64-1 | rect: [59, 106, 325, 253] | autosave: 0
----------- objects -----------
[button]
[button]
Expand Down
Binary file modified maxdiff/tests/test_files/FrozenTest.amxd
Binary file not shown.
32 changes: 3 additions & 29 deletions maxdiff/tests/test_files/MyAbstraction.maxpat
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,16 @@
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 8,
"minor" : 6,
"revision" : 2,
"major" : 9,
"minor" : 0,
"revision" : 10,
"architecture" : "x64",
"modernui" : 1
}
,
"classnamespace" : "box",
"rect" : [ 312.0, 228.0, 221.0, 176.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 1,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 1,
"objectsnaponopen" : 1,
"statusbarvisible" : 2,
"toolbarvisible" : 1,
"lefttoolbarpinned" : 0,
"toptoolbarpinned" : 0,
"righttoolbarpinned" : 0,
"bottomtoolbarpinned" : 0,
"toolbars_unpinned_last_save" : 0,
"tallnewobj" : 0,
"boxanimatetime" : 200,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"style" : "",
"subpatcher_template" : "",
"assistshowspatchername" : 0,
"boxes" : [ {
"box" : {
"id" : "obj-3",
Expand Down
33 changes: 4 additions & 29 deletions maxdiff/tests/test_files/ParamAbstraction.maxpat
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,16 @@
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 8,
"minor" : 5,
"revision" : 5,
"major" : 9,
"minor" : 0,
"revision" : 10,
"architecture" : "x64",
"modernui" : 1
}
,
"classnamespace" : "box",
"rect" : [ 192.0, 591.0, 640.0, 480.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 1,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 1,
"objectsnaponopen" : 1,
"statusbarvisible" : 2,
"toolbarvisible" : 1,
"lefttoolbarpinned" : 0,
"toptoolbarpinned" : 0,
"righttoolbarpinned" : 0,
"bottomtoolbarpinned" : 0,
"toolbars_unpinned_last_save" : 0,
"tallnewobj" : 0,
"boxanimatetime" : 200,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"style" : "",
"subpatcher_template" : "",
"assistshowspatchername" : 0,
"boxes" : [ {
"box" : {
"id" : "obj-1",
Expand All @@ -50,6 +24,7 @@
"saved_attribute_attributes" : {
"valueof" : {
"parameter_longname" : "InsideBpatcher",
"parameter_modmode" : 0,
"parameter_shortname" : "live.dial",
"parameter_type" : 0,
"parameter_unitstyle" : 0
Expand Down
Binary file modified maxdiff/tests/test_files/Test.amxd
Binary file not shown.
32 changes: 3 additions & 29 deletions maxdiff/tests/test_files/Test.maxpat
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,16 @@
"patcher" : {
"fileversion" : 1,
"appversion" : {
"major" : 8,
"minor" : 5,
"revision" : 5,
"major" : 9,
"minor" : 0,
"revision" : 10,
"architecture" : "x64",
"modernui" : 1
}
,
"classnamespace" : "box",
"rect" : [ 59.0, 106.0, 325.0, 253.0 ],
"bglocked" : 0,
"openinpresentation" : 0,
"default_fontsize" : 12.0,
"default_fontface" : 0,
"default_fontname" : "Arial",
"gridonopen" : 1,
"gridsize" : [ 15.0, 15.0 ],
"gridsnaponopen" : 1,
"objectsnaponopen" : 1,
"statusbarvisible" : 2,
"toolbarvisible" : 1,
"lefttoolbarpinned" : 0,
"toptoolbarpinned" : 0,
"righttoolbarpinned" : 0,
"bottomtoolbarpinned" : 0,
"toolbars_unpinned_last_save" : 0,
"tallnewobj" : 0,
"boxanimatetime" : 200,
"enablehscroll" : 1,
"enablevscroll" : 1,
"devicewidth" : 0.0,
"description" : "",
"digest" : "",
"tags" : "",
"style" : "",
"subpatcher_template" : "",
"assistshowspatchername" : 0,
"boxes" : [ {
"box" : {
"id" : "obj-3",
Expand Down