예제 #1
0
    def test_template_parse(self):
        data = """
            {
                "templates": {
                    "android": {
                        "slaves": [
                            {
                                "path": "res/drawable-ldpi/$name",
                                "width": "$basewidth * 0.75",
                                "height": "$baseheight * 0.75"
                            },
                            {
                                "path": "res/drawable-mdpi/$name",
                                "width": "$basewidth",
                                "height": "$baseheight"
                            },
                            {
                                "path": "res/drawable-hdpi/$name",
                                "width": "$basewidth * 1.5",
                                "height": "$baseheight * 1.5"
                            },
                            {
                                "path": "res/drawable-xhdpi/$name",
                                "width": "$basewidth * 2",
                                "height": "$baseheight * 2"
                            }
                        ]
                    },
                    "ios": {
                        "slaves": [
                            {
                                "path": "Images/$name",
                                "width": "$basewidth",
                                "height": "$baseheight"
                            },
                            {
                                "path": "Images/$name@2x",
                                "width": "$basewidth",
                                "height": "$baseheight"
                            }
                        ]
                    }
                },
                "conversions": []
            }
        """
        parsed_data = json.loads(data)
        templates = commands.parse_templates(parsed_data['templates'])
        self.assertEqual(2, len(templates))
        
        android_template = templates['android']
        self.assertEqual(4, len(android_template.slave_conversions))

        ios_template = templates['ios']
        self.assertEqual(2, len(ios_template.slave_conversions))
예제 #2
0
    def test_conversion_parse(self):
        data = """
            {
                "templates": {
                    "android": {
                        "slaves": [
                            {
                                "path": "res/drawable-ldpi/{name}",
                                "width": "{basewidth} * 0.75",
                                "height": "{baseheight} * 0.75"
                            },
                            {
                                "path": "res/drawable-mdpi/{name}",
                                "width": "{basewidth}",
                                "height": "{baseheight}"
                            },
                            {
                                "path": "res/drawable-hdpi/{name}",
                                "width": "{basewidth} * 1.5",
                                "height": "{baseheight} * 1.5"
                            },
                            {
                                "path": "res/drawable-xhdpi/{name}",
                                "width": "{basewidth} * 2",
                                "height": "{baseheight} * 2"
                            }
                        ]
                    }
                },
               "conversions": [
                  {
                     "master":"file.png",
                     "template": "android",
                     "name": "image.png",
                     "basewidth": 100,
                     "baseheight": 200
                  },
                  {
                     "master":"file2.png",
                     "slaves":[
                        {
                           "path":"res/layout-ldpi/image.png",
                           "width":75,
                           "height":75
                        },
                        {
                           "path":"res/layout-mdpi/image.png",
                           "width":100,
                           "height":100
                        },
                        {
                           "path":"res/layout-hdpi/image.png",
                           "width":150,
                           "height":150
                        },
                        {
                           "path":"res/layout-xhdpi/image.png",
                           "width":200,
                           "height":200
                        }
                     ]
                  }
               ]
            }
        """
        parsed_data = json.loads(data)
        templates = commands.parse_templates(parsed_data['templates'])
        conversions = commands.parse_conversions(parsed_data['conversions'], templates)

        self.assertEqual(2, len(conversions))
        self.assertEqual('image.png', conversions['file.png'].args['name'])
        self.assertEqual(100, conversions['file.png'].args['basewidth'])
        self.assertEqual(200, conversions['file.png'].args['baseheight'])
예제 #3
0
 def test_conversion_parse_master_missing(self):
     data = """
         {
             "templates": {
                 "android": {
                     "slaves": [
                         {
                             "path": "res/drawable-ldpi/@name",
                             "width": "@basewidth * 0.75",
                             "height": "@baseheight * 0.75"
                         },
                         {
                             "path": "res/drawable-mdpi/@name",
                             "width": "@basewidth",
                             "height": "@baseheight"
                         },
                         {
                             "path": "res/drawable-hdpi/@name",
                             "width": "@basewidth * 1.5",
                             "height": "@baseheight * 1.5"
                         },
                         {
                             "path": "res/drawable-xhdpi/@name",
                             "width": "@basewidth * 2",
                             "height": "@baseheight * 2"
                         }
                     ]
                 }
             },
            "conversions": [
               {
                  "template": "android",
                  "name": "image.png",
                  "basewidth": 100,
                  "baseheight": 200
               },
               {
                  "master":"file2.png",
                  "slaves":[
                     {
                        "path":"res/layout-ldpi/image.png",
                        "width":75,
                        "height":75
                     },
                     {
                        "path":"res/layout-mdpi/image.png",
                        "width":100,
                        "height":100
                     },
                     {
                        "path":"res/layout-hdpi/image.png",
                        "width":150,
                        "height":150
                     },
                     {
                        "path":"res/layout-xhdpi/image.png",
                        "width":200,
                        "height":200
                     }
                  ]
               }
            ]
         }
     """
     parsed_data = json.loads(data)
     templates = commands.parse_templates(parsed_data['templates'])
     self.assertRaises(commands.InvalidConversionException, commands.parse_conversions, parsed_data['conversions'], templates)