Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 16 | import unittest |
| 17 | import os |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 18 | from helpers import OUTPUT_DIR |
| 19 | from xosgenx.generator import XOSProcessor, XOSProcessorArgs |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 20 | |
| 21 | TEST_EXPECTED_OUTPUT = """ |
| 22 | name: XOSModel |
| 23 | fields: |
| 24 | name: |
| 25 | type: string |
| 26 | description: "Help Name" |
| 27 | files: |
| 28 | type: string |
| 29 | description: "Help Files" |
| 30 | """ |
| 31 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 32 | BASE_XPROTO = os.path.abspath( |
| 33 | os.path.dirname(os.path.realpath(__file__)) + "/xproto/base.xproto" |
| 34 | ) |
| 35 | TEST_XPROTO = os.path.abspath( |
| 36 | os.path.dirname(os.path.realpath(__file__)) + "/xproto/test.xproto" |
| 37 | ) |
| 38 | FIELDTEST_XPROTO = os.path.abspath( |
| 39 | os.path.dirname(os.path.realpath(__file__)) + "/xproto/fieldtest.xproto" |
| 40 | ) |
| 41 | REVERSEFIELDTEST_XPROTO = os.path.abspath( |
| 42 | os.path.dirname(os.path.realpath(__file__)) + "/xproto/reversefieldtest.xproto" |
| 43 | ) |
| 44 | FILTERTEST_XPROTO = os.path.abspath( |
| 45 | os.path.dirname(os.path.realpath(__file__)) + "/xproto/filtertest.xproto" |
| 46 | ) |
| 47 | SKIP_DJANGO_XPROTO = os.path.abspath( |
| 48 | os.path.dirname(os.path.realpath(__file__)) + "/xproto/skip_django.xproto" |
| 49 | ) |
| 50 | VROUTER_XPROTO = os.path.abspath( |
| 51 | os.path.dirname(os.path.realpath(__file__)) + "/xproto/vrouterport.xproto" |
| 52 | ) |
| 53 | TEST_TARGET = os.path.abspath( |
| 54 | os.path.dirname(os.path.realpath(__file__)) + "/xtarget/test.xtarget" |
| 55 | ) |
| 56 | FIELDTEST_TARGET = os.path.abspath( |
| 57 | os.path.dirname(os.path.realpath(__file__)) + "/xtarget/fieldtest.xtarget" |
| 58 | ) |
| 59 | FILTERTEST_TARGET = os.path.abspath( |
| 60 | os.path.dirname(os.path.realpath(__file__)) + "/xtarget/filtertest.xtarget" |
| 61 | ) |
| 62 | SPLIT_TARGET = os.path.abspath( |
| 63 | os.path.dirname(os.path.realpath(__file__)) + "/xtarget/split.xtarget" |
| 64 | ) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 65 | |
| 66 | TEST_ATTICS = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/attics/") |
| 67 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 68 | |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 69 | class XOSProcessorTest(unittest.TestCase): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 70 | """ |
| 71 | Testing the XOS Generative Toolchain |
| 72 | """ |
| 73 | |
| 74 | def setUp(self): |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 75 | os.chdir( |
| 76 | os.path.join( |
| 77 | os.path.abspath(os.path.dirname(os.path.realpath(__file__))), ".." |
| 78 | ) |
| 79 | ) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 80 | filesToRemove = [f for f in os.listdir(OUTPUT_DIR)] |
| 81 | for f in filesToRemove: |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 82 | if not f.startswith("."): |
| 83 | os.remove(OUTPUT_DIR + "/" + f) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 84 | |
Sapan Bhatia | 4c83560 | 2017-07-14 01:13:17 -0400 | [diff] [blame] | 85 | def test_generator_custom_target_from_file(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 86 | """ |
| 87 | [XOS-GenX] Generate output from base.xproto |
| 88 | """ |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 89 | args = XOSProcessorArgs(files=[TEST_XPROTO], target=TEST_TARGET) |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 90 | output = XOSProcessor.process(args) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 91 | self.assertEqual(output, TEST_EXPECTED_OUTPUT) |
| 92 | |
Sapan Bhatia | 4c83560 | 2017-07-14 01:13:17 -0400 | [diff] [blame] | 93 | def test_generator_custom_target_from_inputs(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 94 | """ |
| 95 | [XOS-GenX] Generate output from base.xproto |
| 96 | """ |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 97 | args = XOSProcessorArgs(inputs=open(TEST_XPROTO).read(), target=TEST_TARGET) |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 98 | output = XOSProcessor.process(args) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 99 | self.assertEqual(output, TEST_EXPECTED_OUTPUT) |
| 100 | |
Sapan Bhatia | 4c83560 | 2017-07-14 01:13:17 -0400 | [diff] [blame] | 101 | def test_django_with_attic(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 102 | """ |
| 103 | [XOS-GenX] Generate django output from test.xproto |
| 104 | """ |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 105 | args = XOSProcessorArgs( |
| 106 | files=[TEST_XPROTO, VROUTER_XPROTO], |
| 107 | target="django.xtarget", |
| 108 | attic=TEST_ATTICS, |
| 109 | output=OUTPUT_DIR, |
| 110 | dest_extension="py", |
| 111 | write_to_file="model", |
| 112 | ) |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 113 | output = XOSProcessor.process(args) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 114 | |
| 115 | # xosmodel has custom header attic |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 116 | self.assertIn("from xosmodel_header import *", output["XOSModel"]) |
| 117 | self.assertIn("class XOSModel(XOSBase):", output["XOSModel"]) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 118 | |
| 119 | # vrouter port use the default header |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 120 | self.assertIn("header import *", output["VRouterPort"]) |
| 121 | self.assertIn("class VRouterPort(XOSBase):", output["VRouterPort"]) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 122 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 123 | # verify files |
| 124 | xosmodel = OUTPUT_DIR + "/xosmodel.py" |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 125 | self.assertTrue(os.path.isfile(xosmodel)) |
| 126 | xmf = open(xosmodel).read() |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 127 | self.assertIn("from xosmodel_header import *", xmf) |
| 128 | self.assertIn("class XOSModel(XOSBase):", xmf) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 129 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 130 | vrouterport = OUTPUT_DIR + "/vrouterport.py" |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 131 | self.assertTrue(os.path.isfile(vrouterport)) |
| 132 | vrpf = open(vrouterport).read() |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 133 | self.assertIn("header import *", vrpf) |
| 134 | self.assertIn("class VRouterPort(XOSBase):", vrpf) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 135 | |
Sapan Bhatia | 4c83560 | 2017-07-14 01:13:17 -0400 | [diff] [blame] | 136 | def test_django_with_base(self): |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 137 | args = XOSProcessorArgs( |
| 138 | files=[TEST_XPROTO, BASE_XPROTO], |
| 139 | target="django.xtarget", |
| 140 | attic=TEST_ATTICS, |
| 141 | output=OUTPUT_DIR, |
| 142 | dest_extension="py", |
| 143 | write_to_file="model", |
| 144 | ) |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 145 | output = XOSProcessor.process(args) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 146 | |
| 147 | # verify files |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 148 | xosmodel = OUTPUT_DIR + "/xosmodel.py" |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 149 | self.assertTrue(os.path.isfile(xosmodel)) |
| 150 | xmf = open(xosmodel).read() |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 151 | self.assertIn("from xosmodel_header import *", xmf) |
| 152 | self.assertIn("class XOSModel(XOSBase):", xmf) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 153 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 154 | xosbase = OUTPUT_DIR + "/xosbase.py" |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 155 | self.assertTrue(os.path.isfile(xosbase)) |
| 156 | xbf = open(xosbase).read() |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 157 | self.assertIn("header import *", xbf) |
| 158 | self.assertIn("class XOSBase(models.Model, PlModelMixIn):", xbf) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 159 | |
Sapan Bhatia | 4c83560 | 2017-07-14 01:13:17 -0400 | [diff] [blame] | 160 | def test_write_multiple_files(self): |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 161 | """ |
| 162 | [XOS-GenX] read multiple models as input, print one file per model |
| 163 | """ |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 164 | args = XOSProcessorArgs( |
| 165 | files=[TEST_XPROTO, VROUTER_XPROTO], |
| 166 | target=TEST_TARGET, |
| 167 | output=OUTPUT_DIR, |
| 168 | dest_extension="txt", |
| 169 | write_to_file="model", |
| 170 | ) |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 171 | XOSProcessor.process(args) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 172 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 173 | generated_files = [f for f in os.listdir(OUTPUT_DIR) if not f.startswith(".")] |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 174 | self.assertEqual(len(generated_files), 2) |
| 175 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 176 | xosmodel = open(os.path.join(OUTPUT_DIR, "xosmodel.txt"), "r").read() |
| 177 | vrouterport = open(os.path.join(OUTPUT_DIR, "vrouterport.txt"), "r").read() |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 178 | |
| 179 | self.assertIn("name: XOSModel", xosmodel) |
| 180 | self.assertIn("name: VRouterPort", vrouterport) |
| 181 | |
| 182 | def test_write_multiple_files_from_xtarget(self): |
| 183 | """ |
| 184 | [XOS-GenX] read multiple models as input, print separate files based on +++ |
| 185 | """ |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 186 | args = XOSProcessorArgs( |
| 187 | files=[TEST_XPROTO, VROUTER_XPROTO], |
| 188 | target=SPLIT_TARGET, |
| 189 | output=OUTPUT_DIR, |
| 190 | write_to_file="target", |
| 191 | ) |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 192 | XOSProcessor.process(args) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 193 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 194 | generated_files = [f for f in os.listdir(OUTPUT_DIR) if not f.startswith(".")] |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 195 | self.assertEqual(len(generated_files), 2) |
| 196 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 197 | xosmodel = open(os.path.join(OUTPUT_DIR, "xosmodel.txt"), "r").read() |
| 198 | vrouterport = open(os.path.join(OUTPUT_DIR, "vrouterport.txt"), "r").read() |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 199 | |
| 200 | self.assertIn("name: XOSModel", xosmodel) |
| 201 | self.assertIn("name: VRouterPort", vrouterport) |
| 202 | |
Sapan Bhatia | 4c83560 | 2017-07-14 01:13:17 -0400 | [diff] [blame] | 203 | def test_skip_django(self): |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 204 | args = XOSProcessorArgs( |
| 205 | files=[SKIP_DJANGO_XPROTO], |
| 206 | target="django.xtarget", |
| 207 | output=OUTPUT_DIR, |
| 208 | dest_extension="py", |
| 209 | write_to_file="model", |
| 210 | ) |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 211 | output = XOSProcessor.process(args) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 212 | |
| 213 | # should not print a file if options.skip_django = True |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 214 | file = OUTPUT_DIR + "/user.py" |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 215 | self.assertFalse(os.path.isfile(file)) |
| 216 | |
| 217 | def test_service_order(self): |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 218 | args = XOSProcessorArgs( |
| 219 | files=[BASE_XPROTO, TEST_XPROTO, VROUTER_XPROTO], |
| 220 | target="service.xtarget", |
| 221 | output=OUTPUT_DIR, |
| 222 | write_to_file="target", |
| 223 | ) |
Sapan Bhatia | bfb233a | 2018-02-09 14:53:09 -0800 | [diff] [blame] | 224 | output = XOSProcessor.process(args) |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 225 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 226 | model = OUTPUT_DIR + "/models.py" |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 227 | self.assertTrue(os.path.isfile(model)) |
| 228 | line_num = 0 |
| 229 | |
| 230 | for line in open(model).readlines(): |
| 231 | line_num += 1 |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 232 | if line.find("class XOSBase(models.Model, PlModelMixIn):") >= 0: |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 233 | base_line = line_num |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 234 | if line.find("XOSModel(XOSBase):") >= 0: |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 235 | xosmodel_line = line_num |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 236 | if line.find("class VRouterPort(XOSBase):") >= 0: |
Matteo Scandolo | 67654fa | 2017-06-09 09:33:17 -0700 | [diff] [blame] | 237 | vrouter_line = line_num |
| 238 | self.assertLess(base_line, xosmodel_line) |
| 239 | self.assertLess(xosmodel_line, vrouter_line) |
| 240 | |
Scott Baker | 34dc67e | 2018-10-02 15:57:50 -0700 | [diff] [blame] | 241 | def test_field_numbers(self): |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 242 | args = XOSProcessorArgs(files=[FIELDTEST_XPROTO], target=FIELDTEST_TARGET) |
Scott Baker | 34dc67e | 2018-10-02 15:57:50 -0700 | [diff] [blame] | 243 | output = XOSProcessor.process(args) |
| 244 | |
| 245 | def _assert_field(modelname, fieldname, id): |
| 246 | self.assertIn("%s,%s,%s" % (modelname, fieldname, id), output) |
| 247 | |
| 248 | _assert_field("Site", "id", 1) |
| 249 | _assert_field("Site", "base_field", 2) |
| 250 | _assert_field("Site", "base_field2", 3) |
| 251 | _assert_field("Site", "otherstuff_field", 102) |
| 252 | _assert_field("Site", "slice_field", 201) |
| 253 | _assert_field("Site", "slices_ids", 1002) |
| 254 | |
| 255 | _assert_field("Slice", "id", 1) |
| 256 | _assert_field("Slice", "base_field", 2) |
| 257 | _assert_field("Slice", "base_field2", 3) |
| 258 | _assert_field("Slice", "slice_field", 101) |
| 259 | _assert_field("Slice", "site", 102) |
| 260 | |
Scott Baker | d87c02a | 2018-10-29 16:24:29 -0700 | [diff] [blame] | 261 | def test_field_numbers(self): |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 262 | args = XOSProcessorArgs( |
| 263 | files=[REVERSEFIELDTEST_XPROTO], target=FIELDTEST_TARGET |
| 264 | ) |
Scott Baker | d87c02a | 2018-10-29 16:24:29 -0700 | [diff] [blame] | 265 | output = XOSProcessor.process(args) |
| 266 | |
| 267 | def _assert_field(modelname, fieldname, id): |
| 268 | self.assertIn("%s,%s,%s" % (modelname, fieldname, id), output) |
| 269 | |
| 270 | # rel_int1s_ids is the reverse link from RelatedToIntermediate1. It gets the related id with no offset, so it |
| 271 | # will be assigned 1001. rel_leaf1as_ids inherits from Intermediate1, so its reverse links will all be offset |
| 272 | # by 100 |
| 273 | _assert_field("Leaf1a", "rel_int1s_ids", 1001) |
| 274 | _assert_field("Leaf1a", "rel_leaf1as_ids", 1101) |
| 275 | |
| 276 | # rel_int2s_ids is the reverse link from RelatedToIntermediate1. It gets the related id with no offset, so it |
| 277 | # will be assigned 1001. rel_leaf1bs_ids inherits from Intermediate1, so its reverse links will all be offset |
| 278 | # by 100 |
| 279 | _assert_field("Leaf1b", "rel_int1s_ids", 1001) |
| 280 | _assert_field("Leaf1b", "rel_leaf1bs_ids", 1101) |
| 281 | |
| 282 | # There are no reverse numbers specified for Intermediate2 or Leaf2, so xproto will fall back to automatic |
| 283 | # numbering starting at 1900. |
| 284 | _assert_field("Leaf2", "rel_int2s_ids", 1900) |
| 285 | _assert_field("Leaf2", "rel_leaf2s_ids", 1901) |
| 286 | |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 287 | def test_unfiltered(self): |
| 288 | """ With no include_* args, should get all models """ |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 289 | args = XOSProcessorArgs(files=[FILTERTEST_XPROTO], target=FILTERTEST_TARGET) |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 290 | output = XOSProcessor.process(args) |
| 291 | |
| 292 | self.assertEqual(output, "Model1,Model2,Model3,") |
| 293 | |
| 294 | def test_filter_models(self): |
| 295 | """ Should only get models specified by include_models """ |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 296 | args = XOSProcessorArgs( |
| 297 | files=[FILTERTEST_XPROTO], |
| 298 | target=FILTERTEST_TARGET, |
| 299 | include_models=["Model1", "Model3"], |
| 300 | ) |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 301 | output = XOSProcessor.process(args) |
| 302 | |
| 303 | self.assertEqual(output, "Model1,Model3,") |
| 304 | |
| 305 | def test_filter_apps(self): |
| 306 | """ Should only get models whose apps are specified by include_apps """ |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 307 | args = XOSProcessorArgs( |
| 308 | files=[FILTERTEST_XPROTO], target=FILTERTEST_TARGET, include_apps=["core"] |
| 309 | ) |
Scott Baker | 1f7791d | 2018-10-04 13:21:20 -0700 | [diff] [blame] | 310 | output = XOSProcessor.process(args) |
| 311 | |
| 312 | self.assertEqual(output, "Model1,Model2,") |
| 313 | |
| 314 | |
Zack Williams | 045b63d | 2019-01-22 16:30:57 -0700 | [diff] [blame] | 315 | if __name__ == "__main__": |
Sapan Bhatia | 4c83560 | 2017-07-14 01:13:17 -0400 | [diff] [blame] | 316 | unittest.main() |