|
| 1 | +% These tests are to ensure graceful degradation with missing (or no) |
| 2 | +% available backends. Ideally, run this test with all these disabled |
| 3 | +% * Java: matlab -nojvm |
| 4 | +% * dotnet: setenv('DOTNET_ROOT') right upon starting Matlab on non-Windows system |
| 5 | +% * python: seems one needs a Matlab install that never had Python setup. |
| 6 | +% * Alternative: install a temporary Python environment, set pyenv to that, then delete that Python install |
| 7 | + |
| 8 | +classdef (SharedTestFixtures={ matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))))}, ... |
| 9 | + TestTags = {'impure'}) ... |
| 10 | + TestBackend < matlab.unittest.TestCase |
| 11 | + |
| 12 | +properties |
| 13 | +root = fileparts(fileparts(mfilename('fullpath'))) |
| 14 | +end |
| 15 | + |
| 16 | +methods(TestClassSetup) |
| 17 | +function test_dirs(tc) |
| 18 | + tc.applyFixture(matlab.unittest.fixtures.WorkingFolderFixture()) |
| 19 | +end |
| 20 | +end |
| 21 | + |
| 22 | +methods (Test) |
| 23 | +function test_backend(tc) |
| 24 | +import matlab.unittest.constraints.IsSubsetOf |
| 25 | +import matlab.unittest.constraints.IsFile |
| 26 | + |
| 27 | +readme = tc.root + "/Readme.md"; |
| 28 | +tc.assertThat(readme, IsFile) |
| 29 | + |
| 30 | +[i, b] = stdlib.cpu_load(); |
| 31 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('cpu_load').backends)) |
| 32 | +tc.verifyGreaterThanOrEqual(i, 0) |
| 33 | +% some CI systems report 0 |
| 34 | + |
| 35 | +[i, b] = stdlib.create_symlink(readme, "Readme.lnk"); |
| 36 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('create_symlink').backends)) |
| 37 | +tc.verifyTrue(i) |
| 38 | + |
| 39 | +[i, b] = stdlib.device('.'); |
| 40 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('device').backends)) |
| 41 | +tc.verifyGreaterThan(i, 0) |
| 42 | + |
| 43 | +[i, b] = stdlib.disk_available('.'); |
| 44 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('disk_available').backends)) |
| 45 | +tc.verifyGreaterThan(i, 0) |
| 46 | + |
| 47 | +[i, b] = stdlib.disk_capacity('.'); |
| 48 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('disk_capacity').backends)) |
| 49 | +tc.verifyGreaterThan(i, 0) |
| 50 | + |
| 51 | +[i, b] = stdlib.file_checksum(readme, 'sha256'); |
| 52 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('file_checksum').backends)) |
| 53 | +tc.verifyEqual(strlength(i), 64) |
| 54 | + |
| 55 | +[i, b] = stdlib.filesystem_type('.'); |
| 56 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('filesystem_type').backends)) |
| 57 | +tc.verifyGreaterThan(strlength(i), 0) |
| 58 | + |
| 59 | +[i, b] = stdlib.get_owner('.'); |
| 60 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('get_owner').backends)) |
| 61 | +tc.verifyGreaterThan(strlength(i), 0) |
| 62 | + |
| 63 | +[i, b] = stdlib.get_process_priority(); |
| 64 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('get_process_priority').backends)) |
| 65 | +tc.verifyNotEmpty(i) |
| 66 | + |
| 67 | +[i, b] = stdlib.get_uid(); |
| 68 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('get_uid').backends)) |
| 69 | +tc.verifyGreaterThanOrEqual(i, 0) |
| 70 | + |
| 71 | +[i, b] = stdlib.get_username(); |
| 72 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('get_username').backends)) |
| 73 | +tc.verifyNotEmpty(i) |
| 74 | + |
| 75 | +[i, b] = stdlib.hard_link_count('.'); |
| 76 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('hard_link_count').backends)) |
| 77 | +tc.verifyGreaterThan(i, 0) |
| 78 | + |
| 79 | +[i, b] = stdlib.hostname(); |
| 80 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('hostname').backends)) |
| 81 | +tc.verifyNotEmpty(i) |
| 82 | + |
| 83 | +[i, b] = stdlib.inode(readme); |
| 84 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('inode').backends)) |
| 85 | +tc.verifyGreaterThan(i, 0) |
| 86 | + |
| 87 | +[i,b] = stdlib.is_admin(); |
| 88 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('is_admin').backends)) |
| 89 | +tc.verifyNotEmpty(i) |
| 90 | + |
| 91 | +[i,b] = stdlib.is_char_device('.'); |
| 92 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('is_char_device').backends)); |
| 93 | +tc.verifyNotEmpty(i); |
| 94 | + |
| 95 | +[i, b] = stdlib.is_dev_drive('.'); |
| 96 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('is_dev_drive').backends)) |
| 97 | +tc.verifyNotEmpty(i) |
| 98 | + |
| 99 | +[i, b] = stdlib.is_mount('.'); |
| 100 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('is_mount').backends)) |
| 101 | +tc.verifyNotEmpty(i) |
| 102 | + |
| 103 | +[i, b] = stdlib.is_removable('.'); |
| 104 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('is_removable').backends)) |
| 105 | +tc.verifyNotEmpty(i) |
| 106 | + |
| 107 | +[i, b] = stdlib.is_symlink(readme); |
| 108 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('is_symlink').backends)) |
| 109 | +tc.verifyClass(i, 'logical') |
| 110 | +tc.verifyNotEmpty(i) |
| 111 | + |
| 112 | +[os, version, b] = stdlib.os_version(); |
| 113 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('os_version').backends)) |
| 114 | +tc.verifyNotEmpty(os) |
| 115 | +tc.verifyNotEmpty(version) |
| 116 | + |
| 117 | +[i, b] = stdlib.ram_free(); |
| 118 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('ram_free').backends)) |
| 119 | +tc.verifyGreaterThan(i, 0) |
| 120 | + |
| 121 | +[i, b] = stdlib.ram_total(); |
| 122 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('ram_total').backends)) |
| 123 | +tc.verifyGreaterThan(i, 0) |
| 124 | + |
| 125 | +[i, b] = stdlib.read_symlink('Readme.lnk'); |
| 126 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('read_symlink').backends)) |
| 127 | +tc.verifyThat(i, IsFile) |
| 128 | + |
| 129 | +[i, b] = stdlib.samepath(readme, readme); |
| 130 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('samepath').backends)) |
| 131 | +tc.verifyTrue(i) |
| 132 | + |
| 133 | +[i, b] = stdlib.set_modtime("nobody", datetime()); |
| 134 | +tc.assertThat(b, IsSubsetOf(stdlib.Backend('set_modtime').backends)) |
| 135 | +tc.verifyNotEmpty(i) |
| 136 | + |
| 137 | + |
| 138 | +end |
| 139 | + |
| 140 | +end |
| 141 | + |
| 142 | + |
| 143 | +end |
0 commit comments