Exemplo n.º 1
0
 def test_parse(self):
     dic, war = pl.Parser(self.dir, "full.pl").parse()
     # warning
     self.assertIn("Key 'e.f.h' overwritten at line", str(war))
     # = += +
     self.assertEqual(dic['title'], 'testtesttest')
     # = -= -
     self.assertEqual(dic['title2'], 'AABBCC.')
     # ==
     self.assertEqual(dic['text'], 'tests')
     # extends
     self.assertIn(
         {
             'directory_name': 'dir1',
             'lineno': 18,
             'line': 'extends=working.pl\n',
             'path': 'working.pl'
         }, dic["__extends"])
     # =@ +=@ -=@
     with open(os.path.join(FAKE_FB_ROOT, "dir1/working.pl")) as f:
         self.assertEqual(len(dic['test']), 3 * len(f.read()))
     # sub keys
     self.assertEqual('12', dic['e']['f']['g'])
     # % %=
     self.assertEqual({'a': 1, 'b': 2}, dic['e']['f']['i'])
     self.assertEqual({'a': 1, 'b': 2}, dic['b'])
     # Override % with a.a
     self.assertEqual({'a': '3', 'b': 2}, dic['a'])
Exemplo n.º 2
0
 def test_parse_errors(self):
     with self.assertRaises(SyntaxErrorPL):
         pl.Parser(self.dir, "no_string_in_sub_key.pl").parse()
     with self.assertRaises(SyntaxErrorPL):
         pl.Parser(self.dir, "syntax_extends.pl").parse()
     with self.assertRaises(SyntaxErrorPL):
         pl.Parser(self.dir, "syntax_file.pl").parse()
     with self.assertRaises(SyntaxErrorPL):
         pl.Parser(self.dir, "syntax_error.pl").parse()
     with self.assertRaises(FileNotFound):
         pl.Parser(self.dir, "extends_no_lib.pl").parse()
     with self.assertRaises(SyntaxErrorPL):
         pl.Parser(self.dir, "open_multiline.pl").parse()
     with self.assertRaises(SemanticError):
         pl.Parser(self.dir, "append_no_key.pl").parse()
     with self.assertRaises(FileNotFound):
         pl.Parser(self.dir, "no_file_from.pl").parse()
     with self.assertRaises(SyntaxErrorPL):
         pl.Parser(self.dir, "invalid_one_line_json.pl").parse()
     with self.assertRaises(SyntaxErrorPL):
         pl.Parser(self.dir, "invalid_multiline_json.pl").parse()
     with self.assertRaises(FileNotFound):
         pl.Parser(self.dir, "no_file_sandbox.pl").parse()
     with self.assertRaises(SyntaxErrorPL):
         pl.Parser(self.dir, "syntax_sandbox.pl").parse()
     with self.assertRaises(SyntaxErrorPL):
         pl.Parser(self.dir, "reference_binary.pl").parse()
     with self.assertRaises(FileNotFound):
         pl.Parser(self.dir, "no_image.pl").parse()
     with self.assertRaises(SemanticError):
         pl.Parser(self.dir, "prepend_no_key.pl").parse()
Exemplo n.º 3
0
 def test_parse_url(self):
     dic, war = pl.Parser(self.dir, "image.pl").parse()
     self.assertEqual(to_download_url('dir1/image.png'), dic['img'])
Exemplo n.º 4
0
 def test_init_parser(self):
     pl.Parser(self.dir, "working.pl")
     with self.assertRaises(FileNotFoundError):
         pl.Parser(self.dir, "unknown.pl").parse()