예제 #1
0
def main():
    processor = Processor()
    try:
        processor.import_string("hello.fidl", """
            package Example
            interface Interface {
                method Hello {}
            }
        """)
        assert processor.packages["Example"].interfaces["Interface"].\
            methods["Hello"].name == "Hello"
    except (LexerException, ParserException, ProcessorException) as e:
        print("ERROR: {}".format(e))
예제 #2
0
 def setUp(self):
     # Create temporary file directory.
     tmp_dir = self.get_spec()
     try:
         os.makedirs(tmp_dir)
     except OSError as e:
         if e.errno != errno.EEXIST:
             raise
         # Delete and try again
         shutil.rmtree(tmp_dir)
         os.makedirs(tmp_dir)
     # Create FIDL processor.
     self.processor = Processor()
     self.processor.package_paths.append(tmp_dir)
예제 #3
0
def main():
    processor = Processor()
    try:
        processor.import_string(
            "hello.fidl", """
            package Example
            interface Interface {
                method Hello {}
            }
        """)
        assert processor.packages["Example"].interfaces["Interface"].\
            methods["Hello"].name == "Hello"
    except (LexerException, ParserException, ProcessorException) as e:
        print("ERROR: {}".format(e))
예제 #4
0
def main():
    args = parse_command_line()

    processor = Processor()
    if args.import_dirs:
        processor.package_paths.extend(args.import_dirs)

    try:
        for fidl in args.fidl:
            processor.import_file(fidl)
    except (LexerException, ParserException, ProcessorException) as e:
        print("ERROR: {}".format(e))
        exit(1)

    print("Valid Franca model.")
예제 #5
0
class BaseTestCase(unittest.TestCase):

    def setUp(self):
        # Create temporary file directory.
        tmp_dir = self.get_spec()
        try:
            os.makedirs(tmp_dir)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
            # Delete and try again
            shutil.rmtree(tmp_dir)
            os.makedirs(tmp_dir)
        # Create FIDL processor.
        self.processor = Processor()
        self.processor.package_paths.append(tmp_dir)

    def tearDown(self):
        self.processor = None
        # Remove temporary file directory.
        tmp_dir = self.get_spec()
        shutil.rmtree(tmp_dir)

    @staticmethod
    def get_spec(basedir="tmp", filename=None):
        """
        Get absolute specification a directory or a file under pyfranca/tests/fidl/ .
        :param basedir: Target subdirectory.
        :param filename: File name or None to get a directory specification
        :return: Absolute specification.
        """
        script_dir = os.path.dirname(os.path.realpath(__file__))
        spec = os.path.join(script_dir, "fidl", basedir)
        if filename:
            spec = os.path.join(spec, filename)
        return spec

    def tmp_fidl(self, filename, content):
        fspec = self.get_spec(filename=filename)
        with open(fspec, "w") as f:
            f.write(content)
        return fspec

    def import_tmp_fidl(self, filename, content):
        fspec = self.tmp_fidl(filename, content)
        self.processor.import_file(fspec)
예제 #6
0
def main():
    args = parse_command_line()

    processor = Processor()
    if args.import_dirs:
        processor.package_paths.extend(args.import_dirs)

    try:
        for fidl in args.fidl:
            processor.import_file(fidl)
    except (LexerException, ParserException, ProcessorException) as e:
        print("ERROR: {}".format(e))
        exit(1)

    if args.plot is None:
        dump_packages(processor.packages)
    elif args.plot == "p":
        plot_packages_dependencies(processor.packages)
    elif args.plot == "n":
        plot_namespaces_dependencies(processor.packages)
예제 #7
0
 def test_split_fqn(self):
     self.assertEqual(Processor.split_fqn("P.P.I.A"), ("P.P", "I", "A"))
     self.assertEqual(Processor.split_fqn("P.I.A"), ("P", "I", "A"))
     self.assertEqual(Processor.split_fqn("I.A"), (None, "I", "A"))
     self.assertEqual(Processor.split_fqn("A"), (None, None, "A"))
예제 #8
0
 def test_is_fqn(self):
     self.assertTrue(Processor.is_fqn("P.P.I.A"))
     self.assertTrue(Processor.is_fqn("P.I.A"))
     self.assertFalse(Processor.is_fqn("I.A"))
     self.assertFalse(Processor.is_fqn("A"))
예제 #9
0
 def test_packagename(self):
     self.assertEqual(Processor.packagename("P.I.A"), "P.I")
     self.assertIsNone(Processor.packagename("A"))
예제 #10
0
 def test_basename(self):
     self.assertEqual(Processor.basename("P.I.A"), "A")
     self.assertEqual(Processor.basename("A"), "A")