Ejemplo n.º 1
0
 def setUp(self):
     config = Config()
     config.guipkg = 'test/data/res/packages/gui.pkg'
     config.scriptspkg = 'test/data/res/packages/scripts.pkg'
     config.schema = 'res/itemschema.json'
     config.localedir = 'test/data/res'
     app = Application()
     app.setup(config)
     self.factory = MapFactory(app)
 def setUp(self):
     config = Config()
     config.guipkg = 'test/data/res/packages/gui.pkg'
     config.scriptspkg = 'test/data/res/packages/scripts.pkg'
     config.schema = 'res/itemschema.json'
     config.localedir = 'test/data/res'
     config.outputjson = True
     app = Application()
     app.setup(config)
     self.dropdownlist = DropdownList(app)
class ApplicationTranslateTestCase(unittest.TestCase):
    def setUp(self):
        config = Config()
        config.localedir = 'test/data/res'
        config.pkgdir = 'test/data/res/packages'
        self.app = Application()
        self.app.setup(config)

    def test_transalte(self):
        self.assertEqual('T-34',
                         self.app.gettext.translate('#ussr_vehicles:T-34'))
class ApplicationVPathTestCase(unittest.TestCase):
    def setUp(self):
        from lib.config import Config
        from lib.application import Application
        config = Config()
        config.guipkg = 'test/data/res/packages/gui.pkg'
        config.scriptspkg = 'test/data/res/packages/scripts.pkg'
        config.localedir = 'test/data/res'
        self.app = Application()
        self.app.setup(config)

    def test_vpath(self):
        vpath = VPath(pkgdir='c:/Games/World_of_Tanks_ASIA/res/packages',
                      guidir='./test')
        self.assertEqual('T-34',
                         self.app.gettext.translate('#ussr_vehicles:T-34'))
Ejemplo n.º 5
0
 def setUp(self):
     config = Config()
     config.guipkg = 'test/data/res/packages/gui.pkg'
     config.scriptspkg = 'test/data/res/packages/scripts.pkg'
     config.schema = 'res/itemschema.json'
     config.localedir = 'test/data/res'
     app = Application()
     app.setup(config)
     self.resource = app.resource
     self.ctx = {
         'nation': 'ussr',
         'vehicle': 'R04_T-34',
         'vehicle_siege': 'R04_T-34',
         'chassis': 'T-34_mod_1943',
         'turret': 'T-34_mod_1942',
         'engine': 'V-2-34',
         'radio': '_9RM',
         'gun': '_76mm_S-54'
     }
class ResourceFactoryTestCase_1(unittest.TestCase):
    def setUp(self):
        config = Config()
        config.pkgdir = 'test/data/res/packages'
        config.schema = 'res/itemschema.json'
        config.localedir = 'test/data/res'
        self.app = Application()
        self.app.setup(config)

    def test_0_appenv(self):
        result = self.app.resource.vpath.getPathInfo('gui')
        self.assertEqual('test/data/res/packages/gui.pkg', result.pkg)

    def test_ResourceXml_1(self):
        desc = {
            "file": "gui/gui_settings.xml",
            "xpath": "setting/[name='nations_order']/value/item"
        }
        expect = [
            'germany', 'ussr', 'usa', 'japan', 'china', 'uk', 'france',
            'czech', 'poland', 'italy', 'sweden'
        ]
        resource = ResourceFactory(self.app).create(desc)
        self.assertEqual(expect, resource.getValue())
Ejemplo n.º 7
0
class VehicleInfoTestCase(unittest.TestCase):
    def setUp(self):
        config = Config()
        config.guipkg = 'test/data/res/packages/gui.pkg'
        config.scriptspkg = 'test/data/res/packages/scripts.pkg'
        config.localedir = 'test/data/res'
        config.schema = 'res/itemschema.json'
        self.app = Application()
        self.app.setup(config)

    def test_queryVehicleModule(self):
        result = queryVehicleModule(self.app, 'germany::lt,mt,ht,td', 'shell',
                                    'shell:gravity')
        result = result.asPrimitive()
        self.assertEqual([{'shell:gravity': '9.81'}], result)
        result = queryVehicleModule(self.app,
                                    '::',
                                    'shell',
                                    'shell:gravity',
                                    sort='shell:gravity')
        result = result.asPrimitive()
        self.assertEqual(26, len(result))
        self.assertEqual({'shell:gravity': '9.81'}, result[0])
        self.assertEqual({'shell:gravity': '190'}, result[-1])

    def test_queryVehicleModule_secret(self):
        result = queryVehicleModule(self.app,
                                    'germany:10:td:secret',
                                    None,
                                    'vehicle:index',
                                    sort='vehicle:id')
        result = result.asPrimitive()
        expect = [{
            'vehicle:id': '66',
            'vehicle:index': 'G98_Waffentrager_E100'
        }, {
            'vehicle:id': '190',
            'vehicle:index': 'G98_Waffentrager_E100_P'
        }]
        self.assertEqual(2, len(result))
        self.assertEqual(expect, result)
        result = queryVehicleModule(self.app,
                                    'germany::lt:secret',
                                    None,
                                    'vehicle:index',
                                    sort='vehicle:id')
        result = result.asPrimitive()
        self.assertEqual(7, len(result))
        result = queryVehicleModule(self.app,
                                    'germany:10:lt:secret',
                                    None,
                                    'vehicle:index',
                                    sort='vehicle:id')
        result = result.asPrimitive()
        self.assertEqual(0, len(result))
        self.assertEqual([], result)

    def test_queryVehicleModule_sort(self):
        result = queryVehicleModule(self.app,
                                    'china:2:lt',
                                    'gun',
                                    'turret:index,gun:index',
                                    sort='turret:index,gun:index')
        result = result.asPrimitive()
        expect = [['Turret_1_Ch07_Vickers_MkE_Type_BT26', '_47mm_QFSA'],
                  ['Turret_2_Ch07_Vickers_MkE_Type_BT26', '_40mm_Pom_Pom'],
                  ['Turret_2_Ch07_Vickers_MkE_Type_BT26', '_45mm_20K'],
                  ['Turret_2_Ch07_Vickers_MkE_Type_BT26', '_47mm_QFSA']]
        self.assertEqual(expect,
                         [[v[k] for k in ('turret:index', 'gun:index')]
                          for v in result])
        result = queryVehicleModule(self.app,
                                    'china:2:lt',
                                    'gun',
                                    'gun:index',
                                    sort='turret:index,gun:index')
        result = result.asPrimitive()
        expect = ['_47mm_QFSA', '_40mm_Pom_Pom', '_45mm_20K']
        self.assertEqual(expect, [v['gun:index'] for v in result])
        result = queryVehicleModule(self.app,
                                    'ussr:4:lt',
                                    None,
                                    'vehicle:userString',
                                    sort='vehicle:userString')
        result = result.asPrimitive()
        expect = ['A-20', 'T-80', 'Valentine II']
        self.assertEqual(expect, [v['vehicle:userString'] for v in result])
        result = queryVehicleModule(self.app,
                                    'ussr:4:lt',
                                    None,
                                    'vehicle:userString',
                                    sort=',-vehicle:userString')
        result = result.asPrimitive()
        self.assertEqual(list(reversed(expect)),
                         [v['vehicle:userString'] for v in result])
Ejemplo n.º 8
0
import sys
import io

from lib.config import parseArgument
from lib.application import Application
from lib.widgets import GuiApplication
from lib.dropdownlist import DropdownList

if __name__ == '__main__':
    sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
    sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')

    config = parseArgument(mode='gui')

    app = Application()
    app.setup(config)
    app.dropdownlist = DropdownList(app)

    gui = GuiApplication(app)
    gui.mainloop()
class ResourceFactoryTestCase_2(unittest.TestCase):
    def setUp(self):
        config = Config()
        config.guipkg = 'test/data/res/packages/gui.pkg'
        config.scriptspkg = 'test/data/res/packages/scripts.pkg'
        config.schema = 'res/itemschema.json'
        config.localedir = 'test/data/res'
        self.app = Application()
        self.app.setup(config)

    def test_0_appenv(self):
        result = self.app.resource.vpath.getPathInfo('vehicles')
        self.assertEqual('test/data/res/packages/scripts.pkg', result.pkg)

    def test_ResourceXml_1(self):
        desc = {
            "file": "gui/gui_settings.xml",
            "xpath": "setting/[name='nations_order']/value/item"
        }
        expect = [
            'germany', 'ussr', 'usa', 'japan', 'china', 'uk', 'france',
            'czech', 'poland', 'italy', 'sweden'
        ]
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceXml)
        self.assertEqual(expect, resource.getValue())

    def test_ResourceXml_2(self):
        desc = {
            "file": "vehicles/{nation}/components/fuelTanks.xml",
            "xpath": "ids/{fueltank}",
            "param": {
                "fueltank": "vehicle:fueltank"
            }
        }
        ctx = {'nation': 'ussr', 'vehicle': 'R04_T-34'}
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceXml)
        self.assertEqual(['203'], resource.getValue(ctx))

    def test_ResourceImmediate(self):
        desc = {"immediate": ["LT", "MT", "HT", "TD", "SPG"]}
        expect = ['LT', 'MT', 'HT', 'TD', 'SPG']
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceImmediate)
        self.assertEqual(expect, resource.getValue())

    def test_ResourceFunction_sum(self):
        desc = {"func": "sum()", "args": ["hull:health", "turret:health"]}
        ctx = {'hull:health': '320', 'turret:health': '130'}
        expect = 450
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))

    def test_ResourceFunction_div(self):
        desc = {
            "func": "div()",
            "args": ["engine:power", "vehicle:totalWeight"]
        }
        ctx = {'engine:power': '500', 'vehicle:totalWeight': '29390.0'}
        expect = 500 / 29390
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))

    def test_ResourceFunction_mul(self):
        desc = {
            "func": "mul()",
            "args": ["vehicle:powerWeightRatio", "physics:hpToWatts"]
        }
        ctx = {
            'vehicle:powerWeightRatio': '0.01701258931609391',
            'physics:hpToWatts': '735.5'
        }
        expect = 0.01701258931609391 * 735.5
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))

    def test_ResourceFunction_join(self):
        desc = {
            "func":
            "join()",
            "args": [
                "vehicle:maxSpeed_hard", "vehicle:maxSpeed_medium",
                "vehicle:maxSpeed_soft"
            ]
        }
        ctx = {
            'vehicle:maxSpeed_hard': '16.6',
            'vehicle:maxSpeed_medium': '14.0',
            'vehicle:maxSpeed_soft': '7.9'
        }
        expect = ['16.6', '14.0', '7.9']
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))

    def test_ResourceFunction_or(self):
        desc = {
            "func": "or()",
            "args": ["vehicle:shortUserString", "vehicle:userString"]
        }
        ctx = {'vehicle:shortUserString': None, 'vehicle:userString': 'T-34'}
        expect = 'T-34'
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))
        ctx = {
            'vehicle:shortUserString': 'missing',
            'vehicle:userString': 'T-34'
        }
        expect = 'missing'
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))

    def test_ResourceFunction_format(self):
        desc = {
            "func": "format('{}: {}')",
            "args": ["shell:kindShort", "shell:userString"]
        }
        ctx = {'shell:kindShort': 'AP', 'shell:userString': 'UBR-354MA'}
        expect = 'AP: UBR-354MA'
        resource = ResourceFactory(self.app).create(desc)
        self.assertIsInstance(resource, ResourceMeta)
        self.assertIsInstance(resource, ResourceFunction)
        self.assertEqual(expect, resource.getValue(ctx))