Example #1
0
 def test_json(self):
     with tempfile.TemporaryDirectory() as tempdir, self.assertWarnsRegex(
             DeprecationWarning, r"Compiling to JSON is deprecated"):
         temp_filepath = os.path.join(tempdir, 'output.json')
         ir_utils._write_ir_to_file(json_dict, temp_filepath)
         actual = load_from_file(temp_filepath)
     self.assertEqual(actual, json_dict)
Example #2
0
    def save_to_component_yaml(self, output_file: str) -> None:
        """Saves ComponentSpec into yaml file.

        Args:
            output_file: File path to store the component yaml.
        """
        ir_utils._write_ir_to_file(self.dict(), output_file)
Example #3
0
    def save_to_component_yaml(self, output_file: str) -> None:
        """Saves ComponentSpec into YAML file.

        Args:
            output_file: File path to store the component yaml.
        """
        ir_utils._write_ir_to_file(self.to_dict(by_alias=True), output_file)
Example #4
0
    def _write_pipeline_spec_file(
        self,
        pipeline_spec: pipeline_spec_pb2.PipelineSpec,
        package_path: str,
    ) -> None:
        """Writes pipeline spec into a YAML or JSON (deprecated) file.

        Args:
            pipeline_spec: IR pipeline spec.
            package_path: The file path to be written.
        """

        json_dict = json_format.MessageToDict(pipeline_spec)
        ir_utils._write_ir_to_file(json_dict, package_path)
Example #5
0
    def test_json(self):
        with tempfile.TemporaryDirectory() as tempdir, self.assertWarnsRegex(
                DeprecationWarning, r'Compiling to JSON is deprecated'):
            temp_filepath = os.path.join(tempdir, 'output.json')
            ir_utils._write_ir_to_file(json_dict, temp_filepath)

            with open(temp_filepath) as f:
                actual_contents = f.read()

            actual_dict = load_from_file(temp_filepath)

        expected_contents = textwrap.dedent("""\
                        {
                          "key": "val",
                          "list": [
                            "1",
                            2,
                            3.0
                          ]
                        }""")
        self.assertEqual(actual_contents, expected_contents)
        self.assertEqual(actual_dict, json_dict)
Example #6
0
 def test_incorrect_extension(self):
     with tempfile.TemporaryDirectory() as tempdir, self.assertRaisesRegex(
             ValueError, r'should end with "\.yaml"\.'):
         temp_filepath = os.path.join(tempdir, 'output.txt')
         ir_utils._write_ir_to_file(json_dict, temp_filepath)
Example #7
0
 def test_yml(self):
     with tempfile.TemporaryDirectory() as tempdir:
         temp_filepath = os.path.join(tempdir, 'output.yml')
         ir_utils._write_ir_to_file(json_dict, temp_filepath)
         actual = load_from_file(temp_filepath)
     self.assertEqual(actual, json_dict)