def test_config_read_from_file(self): ini = """ [sna2skool] Base=16 Case=1 DefbSize=12 DefmSize=92 LineWidth=119 ListRefs=2 Text=1 Title-b=Data at {address} Title-c=Code at {address} """ self.write_text_file(dedent(ini).strip(), 'skoolkit.ini') sna = '{}/test.sna'.format(self.make_directory()) sna2skool.main((sna, )) snafile, options, config = run_args self.assertEqual(snafile, sna) self.assertEqual([], options.ctls) self.assertEqual(options.base, 16) self.assertEqual(options.case, 1) self.assertIsNone(options.start) self.assertEqual(options.end, 65536) self.assertIsNone(options.org) self.assertIsNone(options.page) self.assertEqual(config.get('Text'), 1) self.assertEqual(config.get('ListRefs'), 2) self.assertEqual(config.get('DefbSize'), 12) self.assertEqual(options.line_width, 119) self.assertEqual(config.get('DefmSize'), 92) self.assertEqual(config.get('Title-b'), 'Data at {address}') self.assertEqual(config.get('Title-c'), 'Code at {address}')
def test_default_sft_for_unrecognised_snapshot_format(self): self.mock(sna2skool, 'run', mock_run) binfile = 'snapshot.foo' sftfile = self.write_text_file(path='{}.sft'.format(binfile)) sna2skool.main((binfile,)) snafile, options = run_args self.assertEqual(options.sftfile, sftfile)
def test_default_ctl_for_unrecognised_snapshot_format(self): self.mock(sna2skool, 'run', mock_run) binfile = 'input.bar' ctlfile = self.write_text_file(path='{}.ctl'.format(binfile)) sna2skool.main((binfile,)) snafile, options = run_args self.assertEqual(options.ctlfile, ctlfile)
def test_config_read_from_file(self): ini = '\n'.join( ('[sna2skool]', 'Base=16', 'Case=1', 'CtlHex=1', 'DefbMod=8', 'DefbSize=12', 'DefbZfill=1', 'DefmSize=92', 'LineWidth=119', 'ListRefs=2', 'Text=1', 'Title-b=Data at {address}', 'Title-c=Code at {address}')) self.write_text_file(ini, 'skoolkit.ini') sna2skool.main(('test.sna', )) snafile, options, config = run_args self.assertEqual(snafile, 'test.sna') self.assertIsNone(options.ctlfile) self.assertIsNone(options.sftfile) self.assertIsNone(options.genctlfile) self.assertEqual(options.ctl_hex, 1) self.assertEqual(options.base, 16) self.assertEqual(options.case, 1) self.assertEqual(options.start, 0) self.assertEqual(options.end, 65536) self.assertIsNone(options.org) self.assertIsNone(options.page) self.assertTrue(options.text) self.assertEqual(options.write_refs, 2) self.assertEqual(options.defb_size, 12) self.assertEqual(options.defb_mod, 8) self.assertEqual(options.line_width, 119) self.assertTrue(options.zfill) self.assertEqual(config.get('Title-b'), 'Data at {address}') self.assertEqual(config.get('Title-c'), 'Code at {address}')
def run(subcommand): func = functions[subcommand][0] if not os.path.isdir(BUILD_DIR): os.mkdir(BUILD_DIR) if not os.path.isfile(MM_Z80): tap2sna.main(('-d', BUILD_DIR, '@{}/manic_miner.t2s'.format(MANICMINER_HOME))) ctlfile = '{}/{}.ctl'.format(BUILD_DIR, subcommand) with open(ctlfile, 'wt') as f: f.write(func(get_snapshot(MM_Z80))) sna2skool.main(('-c', ctlfile, MM_Z80))
def test_invalid_option_values_read_from_file(self): ini = '\n'.join( ('[sna2skool]', 'CtlHex=?', 'DefbMod=16', 'DefbSize=x')) self.write_text_file(ini, 'skoolkit.ini') sna2skool.main(('test.sna', )) snafile, options = run_args[:2] self.assertEqual(snafile, 'test.sna') self.assertEqual(options.ctl_hex, 0) self.assertEqual(options.defb_mod, 16) self.assertEqual(options.defb_size, 8)
def run(subcommand): func = functions[subcommand][0] if not os.path.isdir(BUILD_DIR): os.mkdir(BUILD_DIR) if not os.path.isfile(MM_Z80): tap2sna.main( ('-d', BUILD_DIR, '@{}/manic_miner.t2s'.format(MANICMINER_HOME))) ctlfile = '{}/{}.ctl'.format(BUILD_DIR, subcommand) with open(ctlfile, 'wt') as f: f.write(func(get_snapshot(MM_Z80))) sna2skool.main(('-c', ctlfile, MM_Z80))
def test_default_option_values(self): sna2skool.main(('test.sna', )) snafile, options = run_args[:2] self.assertEqual(snafile, 'test.sna') self.assertEqual([], options.ctlfiles) self.assertEqual(options.base, 10) self.assertEqual(options.case, 2) self.assertEqual(options.start, 0) self.assertEqual(options.end, 65536) self.assertIsNone(options.org) self.assertIsNone(options.page) self.assertEqual(options.line_width, 79) self.assertEqual(options.params, [])
def test_default_option_values(self): sna = '{}/test.sna'.format(self.make_directory()) sna2skool.main((sna, )) snafile, options = run_args[:2] self.assertEqual(snafile, sna) self.assertEqual([], options.ctls) self.assertEqual(options.base, 10) self.assertEqual(options.case, 2) self.assertIsNone(options.start) self.assertEqual(options.end, 65536) self.assertIsNone(options.org) self.assertIsNone(options.page) self.assertEqual(options.line_width, 79) self.assertEqual(options.params, [])
def test_invalid_option_values_read_from_file(self): ini = """ [sna2skool] Base=? Case=2 DefbSize=x """ self.write_text_file(dedent(ini).strip(), 'skoolkit.ini') sna2skool.main(('test.sna', )) snafile, options, config = run_args self.assertEqual(snafile, 'test.sna') self.assertEqual(options.base, 10) self.assertEqual(config.get('Case'), 2) self.assertEqual(config.get('DefbSize'), 8)
def run(subcommand): func = functions[subcommand][0] if not os.path.isdir(BUILD_DIR): os.mkdir(BUILD_DIR) if not os.path.isfile(MM_Z80): tap2sna.main(("-d", BUILD_DIR, "@{}/manic_miner.t2s".format(MANICMINER_HOME))) ctlfile = "{}/{}.ctl".format(BUILD_DIR, subcommand) with open(ctlfile, "wt") as f: f.write(func(get_snapshot(MM_Z80))) stdout = sys.stdout sys.stdout = StringIO() sna2skool.main(("-c", ctlfile, MM_Z80)) skool = sys.stdout.getvalue() sys.stdout = stdout for line in skool.split("\n")[2:-1]: print(line)
def test_default_ctl(self): # Test that the default control file is used if present snafile = 'test-default-ctl.sna' ctlfile = '{}.ctl'.format(snafile[:-4]) self.write_text_file(path=ctlfile) sna2skool.main((snafile,)) options = run_args[1] self.assertEqual(options.ctlfile, ctlfile) # Test that a skool file template specified by the '-T' option takes # precedence over the default control file sftfile = self.write_text_file(suffix='.sft') sna2skool.main(('-T', sftfile, snafile)) options = run_args[1] self.assertIsNone(options.ctlfile) self.assertEqual(options.sftfile, sftfile)
def test_default_ctl(self): # Test that the default control file is used if present snafile = 'test-default-ctl.sna' ctlfile = '{}.ctl'.format(snafile[:-4]) self.write_text_file(path=ctlfile) sna2skool.main((snafile, )) options = run_args[1] self.assertEqual(options.ctlfile, ctlfile) # Test that a skool file template specified by the '-T' option takes # precedence over the default control file sftfile = self.write_text_file(suffix='.sft') sna2skool.main(('-T', sftfile, snafile)) options = run_args[1] self.assertIsNone(options.ctlfile) self.assertEqual(options.sftfile, sftfile)
def run(subcommand): func = functions[subcommand][0] if not os.path.isdir(BUILD_DIR): os.mkdir(BUILD_DIR) if not os.path.isfile(MM_Z80): tap2sna.main( ('-d', BUILD_DIR, '@{}/manic_miner.t2s'.format(MANICMINER_HOME))) ctlfile = '{}/{}.ctl'.format(BUILD_DIR, subcommand) with open(ctlfile, 'wt') as f: f.write(func(get_snapshot(MM_Z80))) stdout = sys.stdout sys.stdout = StringIO() sna2skool.main(('-c', ctlfile, MM_Z80)) skool = sys.stdout.getvalue() sys.stdout = stdout for line in skool.split('\n')[2:-1]: print(line)
def test_default_option_values(self): self.mock(sna2skool, 'run', mock_run) sna2skool.main(('test.sna',)) snafile, options = run_args self.assertEqual(snafile, 'test.sna') self.assertEqual(options.ctlfile, None) self.assertEqual(options.sftfile, None) self.assertEqual(options.genctlfile, None) self.assertFalse(options.ctl_hex) self.assertFalse(options.asm_hex) self.assertFalse(options.asm_lower) self.assertEqual(options.start, 16384) self.assertEqual(options.org, None) self.assertEqual(options.page, None) self.assertFalse(options.text) self.assertEqual(options.write_refs, 0) self.assertEqual(options.defb_size, 8) self.assertEqual(options.defb_mod, 1) self.assertFalse(options.zfill)
def test_default_option_values(self): sna2skool.main(('test.sna',)) snafile, options = run_args self.assertEqual(snafile, 'test.sna') self.assertIsNone(options.ctlfile) self.assertIsNone(options.sftfile) self.assertIsNone(options.genctlfile) self.assertFalse(options.ctl_hex) self.assertFalse(options.asm_hex) self.assertFalse(options.asm_lower) self.assertEqual(options.start, 0) self.assertEqual(options.end, 65536) self.assertIsNone(options.org) self.assertIsNone(options.page) self.assertFalse(options.text) self.assertEqual(options.write_refs, 0) self.assertEqual(options.defb_size, 8) self.assertEqual(options.defb_mod, 1) self.assertEqual(options.line_width, 79) self.assertFalse(options.zfill)
def test_default_option_values(self): sna2skool.main(('test.sna', )) snafile, options = run_args[:2] self.assertEqual(snafile, 'test.sna') self.assertIsNone(options.ctlfile) self.assertIsNone(options.sftfile) self.assertIsNone(options.genctlfile) self.assertEqual(options.ctl_hex, 0) self.assertEqual(options.base, 10) self.assertEqual(options.case, 2) self.assertEqual(options.start, 0) self.assertEqual(options.end, 65536) self.assertIsNone(options.org) self.assertIsNone(options.page) self.assertFalse(options.text) self.assertEqual(options.write_refs, 1) self.assertEqual(options.defb_size, 8) self.assertEqual(options.defb_mod, 1) self.assertEqual(options.line_width, 79) self.assertFalse(options.zfill) self.assertEqual(options.params, [])
#!/usr/bin/env python3 # Copyright 2012-2013, 2017 Richard Dymond ([email protected]) # # This file is part of SkoolKit. # # SkoolKit is free software: you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software # Foundation, either version 3 of the License, or (at your option) any later # version. # # SkoolKit is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # SkoolKit. If not, see <http://www.gnu.org/licenses/>. import sys from skoolkit import sna2skool, error, SkoolKitError try: sna2skool.main(sys.argv[1:]) except SkoolKitError as e: error(e.args[0])
#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright 2012-2013 Richard Dymond ([email protected]) # # This file is part of SkoolKit. # # SkoolKit is free software: you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software # Foundation, either version 3 of the License, or (at your option) any later # version. # # SkoolKit is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # SkoolKit. If not, see <http://www.gnu.org/licenses/>. import sys from skoolkit import sna2skool, error, SkoolKitError try: sna2skool.main(sys.argv[1:]) except SkoolKitError as e: error(e.args[0])
def test_default_sft_for_unrecognised_snapshot_format(self): binfile = 'snapshot.foo' sftfile = self.write_text_file(path='{}.sft'.format(binfile)) sna2skool.main((binfile, )) options = run_args[1] self.assertEqual(options.sftfile, sftfile)
def test_default_ctl_for_unrecognised_snapshot_format(self): binfile = 'input.bar' ctlfile = self.write_text_file(path='{}.ctl'.format(binfile)) sna2skool.main((binfile, )) options = run_args[1] self.assertEqual(options.ctlfile, ctlfile)