def test_template_cache_dir(self): os.mkdir(self.join('tmp')) main(args=['-t', self.join('taxonomy.xml'), '-d', self.join('destinations.xml'), '--tmp', self.join('tmp'), '-o', self.join('output')]) self.assertEqual(len(os.listdir(self.join('output'))), 2, msg="Invalid number of generated files")
def test_with_builtin_template(self): main(args=[self.join('config.ini')]) self.assertTrue(os.path.isfile(self.join('output', 'africa.html')), msg="Missing file for destination") self.assertTrue(os.path.isfile(self.join('output', 'south_africa.html')), msg="Missing file for destination") self.assertTrue(os.path.getsize(self.join('output', 'africa.html')) > 1000, msg="File is too small for default template") self.assertTrue(os.path.getsize(self.join('output', 'south_africa.html')) > 1000, msg="File is too small for default template")
def test_generic_debugging(self): with open(self.join('destinations.xml'), 'wb') as fh: fh.write('error>') with self.assertRaises(Exception): main(args=['-t', self.join('taxonomy.xml'), '-d', self.join('destinations.xml'), '--debug', '-o', self.join('output')]) self.assertEqual(len(os.listdir(self.join('output'))), 0)
def test_template_error(self): with open(self.join('template.html'), 'wb') as fh: fh.write('${mem') with self.assertRaises(SystemExit): main(args=['-t', self.join('taxonomy.xml'), '-d', self.join('destinations.xml'), '-r', self.join('template.html'), '-o', self.join('output')]) self.assertEqual(len(os.listdir(self.join('output'))), 0)
def test_with_builtin_template(self): main(args=['-t', self.join('taxonomy.xml'), '-d', self.join('destinations.xml'), '-o', self.join('output')]) self.assertTrue(os.path.isfile(self.join('output', 'africa.html')), msg="Missing file for destination") self.assertTrue(os.path.isfile(self.join('output', 'south_africa.html')), msg="Missing file for destination") self.assertTrue(os.path.getsize(self.join('output', 'africa.html')) > 1000, msg="File is too small for default template") self.assertTrue(os.path.getsize(self.join('output', 'south_africa.html')) > 1000, msg="File is too small for default template")
def test_with_override_template(self): """Check that the override template is adhered to""" with open(self.join('template.html'), 'wb') as fh: fh.write(TEST_TEMPLATE) main(args=[self.join('config.ini'), '-r', self.join('template.html')]) self.assertTrue(os.path.isfile(self.join('output', 'africa.html')), msg="Missing file for destination") self.assertTrue(os.path.isfile(self.join('output', 'south_africa.html')), msg="Missing file for destination") with open(self.join('output', 'africa.html'), 'r') as fh: self.assertEqual(fh.read(), 'DESTINATION: Africa') with open(self.join('output', 'south_africa.html'), 'r') as fh: self.assertEqual(fh.read(), 'DESTINATION: South Africa')
def test_file_per_destination(self): main(args=['-t', self.join('taxonomy.xml'), '-d', self.join('destinations.xml'), '-o', self.join('output')]) self.assertEqual(len(os.listdir(self.join('output'))), 2, msg="Invalid number of generated files")
def test_missing_taxonomy_file(self): with self.assertRaises(SystemExit): main(args=['-t', self.join('taxonomy.xml'), '-d', self.join('wrong.xml'), '-o', self.join('output')])
def test_missing_destinations_file(self): with self.assertRaises(SystemExit): main(args=['-t', self.join('wrong.xml'), '-d', self.join('destinations.xml'), '-o', self.join('output')])
def test_missing_template_file(self): with self.assertRaises(SystemExit): main(args=['-t', self.join('taxonomy.xml'), '-d', self.join('destinations.xml'), '-r', self.join('template.html'), '-o', self.join('output')])
def test_file_per_destination(self): main(args=[self.join('config.ini')]) self.assertEqual(len(os.listdir(self.join('output'))), 2, msg="Invalid number of generated files")
def test_with_invalid_output_dir(self): with self.assertRaises(SystemExit): main(args=[ '-t', 'taxonomy.xml', '-d', 'destinations.xml', '-o', 'output_dir' ])
def test_with_no_taxonomy(self): with self.assertRaises(SystemExit): main(args=['-d', 'destinations.xml', '-o', 'output_dir'])
def test_with_empty_args(self): """User passes no args, should fail with SystemExit""" with self.assertRaises(SystemExit): main(args=[])