Exemplo n.º 1
0
    def test_FuturesResolve(self):
        # This test makes sure that when using futures as part of the parameters
        # for a subrespire build, the futures resolve when determining which
        # subrespire to run, so that multiples calls with different futures that
        # resolve into the same parameters will all call into the same subrespire.
        script_filepath = os.path.join(self.temp_dirs.source_dir,
                                       'futures_resolve.respire.py')
        out_file = os.path.join(self.temp_dirs.out_dir, 'out.txt')

        result = self.RunRespire(script_filepath, out_file)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(out_file),
                         'TheBottomTheBottom')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'futures_resolve.TestBuild.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'GenerateBottom.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'CatFiles.count')))
Exemplo n.º 2
0
    def test_Diamond(self):
        script_filepath = os.path.join(self.temp_dirs.source_dir,
                                       'diamond.respire.py')
        top_file = os.path.join(self.temp_dirs.out_dir, 'top.txt')

        result = self.RunRespire(script_filepath, top_file)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(top_file),
                         'TheBottomfooTheBottombarTheBottomTheBottom')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'diamond.TestBuild.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'GenerateBottom.count')))
        self.assertEqual(
            2,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'CatBottomWith.count')))
        self.assertEqual(
            4,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'CatFiles.count')))
Exemplo n.º 3
0
    def test_StdOutErrInFunction(self):
        output_filepath = os.path.join(self.temp_dirs.out_dir, 'final.txt')
        script_filepath = os.path.join(self.temp_dirs.source_dir,
                                       'stdouterrin_function.respire.py')

        result = self.RunRespire(script_filepath, output_filepath)
        self.assertTrue(result)

        self.assertEqual(test_utils.ContentsForFilePath(output_filepath),
                         'outerrin')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'stdouterrin_function.count')))

        result = self.RunRespire(script_filepath, output_filepath)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(output_filepath),
                         'outerrin')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'stdouterrin_function.count')))
Exemplo n.º 4
0
    def test_StandardSingleFunction(self):
        output_filepath = os.path.join(self.temp_dirs.out_dir,
                                       'foofoobarbar.txt')
        script_filepath = os.path.join(self.temp_dirs.source_dir,
                                       'single_function.respire.py')
        foo_path = os.path.join(self.temp_dirs.source_dir, 'foo.txt')

        result = self.RunRespire(script_filepath, output_filepath)
        self.assertTrue(result)

        self.assertEqual(test_utils.ContentsForFilePath(output_filepath),
                         'foofoobarbar')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'single_function.count')))

        # Check that a modification to one of the source files is properly
        # propagated to the output files, and that the python build file does not
        # get re-evaluated.
        with open(foo_path, 'w') as f:
            f.write('fooey')
        result = self.RunRespire(script_filepath, output_filepath)
        self.assertTrue(result)
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'single_function.count')))
        self.assertEqual(test_utils.ContentsForFilePath(output_filepath),
                         'fooeyfooeybarbar')
        # Make sure that the 'barbar' file was not re-built, since it was not
        # modified.
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'bar_bar.count')))

        # Make sure that directly running it again does *not* result in the
        # python respire script being executed again.
        result = self.RunRespire(script_filepath, output_filepath)
        self.assertTrue(result)

        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'single_function.count')))

        # But if the respire script file is touched, then it should be executed
        # again.
        test_utils.Touch(script_filepath)
        result = self.RunRespire(script_filepath, output_filepath)
        self.assertTrue(result)
        self.assertEqual(
            2,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'single_function.count')))
Exemplo n.º 5
0
    def test_DirectoryAsInputFunction(self):
        output_filepath = os.path.join(self.temp_dirs.out_dir, 'final.txt')
        script_filepath = os.path.join(
            self.temp_dirs.source_dir,
            'directory_as_input_function.respire.py')

        test_directory = os.path.join(self.temp_dirs.source_dir, 'test_dir')
        os.mkdir(test_directory)
        test_file1 = os.path.join(test_directory, 'test_file1')
        test_file2 = os.path.join(test_directory, 'test_file2')

        with open(test_file1, 'w') as f:
            f.write('foo')
        with open(test_file2, 'w') as f:
            f.write('bar')

        result = self.RunRespire(script_filepath, output_filepath)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(output_filepath),
                         'foobar')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'cat_directory.count')))

        # Doing nothing should not result in a rebuild.
        result = self.RunRespire(script_filepath, output_filepath)
        self.assertTrue(result)
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'cat_directory.count')))

        # Removing a file from the directory should result in a rebuild.
        os.remove(test_file2)
        result = self.RunRespire(script_filepath, output_filepath)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(output_filepath),
                         'foo')
        self.assertEqual(
            2,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'cat_directory.count')))

        # Adding a file should result in a rebuild.
        with open(test_file2, 'w') as f:
            f.write('blue')
        result = self.RunRespire(script_filepath, output_filepath)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(output_filepath),
                         'fooblue')
        self.assertEqual(
            3,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'cat_directory.count')))
Exemplo n.º 6
0
    def test_Chain(self):
        script_filepath = os.path.join(self.temp_dirs.source_dir,
                                       'chain.respire.py')
        chain_results_1_path = os.path.join(self.temp_dirs.out_dir,
                                            'chain_results_1.txt')
        chain_results_2_path = os.path.join(self.temp_dirs.out_dir,
                                            'chain_results_2.txt')
        chain_results_1_1_path = os.path.join(self.temp_dirs.out_dir,
                                              'chain_output_11.txt')

        result = self.RunRespire(script_filepath, chain_results_1_path)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(chain_results_1_path),
                         '1')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'chain.TestBuild.count')))
        self.assertEqual(
            7,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'Chain.count')))
        self.assertEqual(
            2,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'WriteResults.count')))

        result = self.RunRespire(script_filepath, chain_results_2_path)
        self.assertTrue(result)
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'chain.TestBuild.count')))
        self.assertEqual(
            7,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'Chain.count')))
        self.assertEqual(
            2,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'WriteResults.count')))
        self.assertEqual(test_utils.ContentsForFilePath(chain_results_2_path),
                         '2')

        result = self.RunRespire(script_filepath, chain_results_2_path)
        self.assertTrue(result)
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'chain.TestBuild.count')))
        self.assertEqual(
            7,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'Chain.count')))
        self.assertEqual(
            2,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'WriteResults.count')))
Exemplo n.º 7
0
    def test_ExtraPythonDepsTest(self):
        # Test to ensure that respire can correctly compute the python dependencies
        # of a module and properly re-build if those dependencies change.
        script_filepath = os.path.join(self.temp_dirs.source_dir,
                                       'simple_test_entry_point.respire.py')
        get_foo_value_filepath = (os.path.join(self.temp_dirs.source_dir,
                                               'get_foo_value.py'))
        foobar_filepath = os.path.join(self.temp_dirs.out_dir, 'foobar.txt')

        result = self.RunRespire(script_filepath, foobar_filepath)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(foobar_filepath),
                         'foobar')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'simple_test_entry_point.TestBuild.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'GenerateBar.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'GenerateFoo.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'CatFiles.count')))

        # Modify an import of the generate_foo.respire.py module, and then make
        # sure that it results in a rebuild.
        with open(get_foo_value_filepath, 'w') as f:
            f.write('foo_value = "foov2"')

        result = self.RunRespire(script_filepath, foobar_filepath)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(foobar_filepath),
                         'foov2bar')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'simple_test_entry_point.TestBuild.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'GenerateBar.count')))
        self.assertEqual(
            2,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'GenerateFoo.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'CatFiles.count')))
Exemplo n.º 8
0
    def test_SimpleTest(self):
        script_filepath = os.path.join(self.temp_dirs.source_dir,
                                       'simple_test_entry_point.respire.py')
        generate_foo_script_filepath = (os.path.join(
            self.temp_dirs.source_dir, 'generate_foo.respire.py'))
        foobar_filepath = os.path.join(self.temp_dirs.out_dir, 'foobar.txt')

        result = self.RunRespire(script_filepath, foobar_filepath)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(foobar_filepath),
                         'foobar')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'simple_test_entry_point.TestBuild.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'GenerateBar.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'GenerateFoo.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'CatFiles.count')))

        test_utils.Touch(generate_foo_script_filepath)
        result = self.RunRespire(script_filepath, foobar_filepath)
        self.assertTrue(result)
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'simple_test_entry_point.TestBuild.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'GenerateBar.count')))
        self.assertEqual(
            2,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'GenerateFoo.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'CatFiles.count')))
Exemplo n.º 9
0
    def test_AddNumbers(self):
        script_filepath = os.path.join(self.temp_dirs.source_dir,
                                       'add_numbers.respire.py')
        two_file = os.path.join(self.temp_dirs.out_dir, 'two_file.txt')
        three_file = os.path.join(self.temp_dirs.out_dir, 'three_file.txt')
        three_again_file = os.path.join(self.temp_dirs.out_dir,
                                        'three_again_file.txt')
        four_file = os.path.join(self.temp_dirs.out_dir, 'four_file.txt')

        result = self.RunRespire(script_filepath, four_file)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(four_file), '4')

        result = self.RunRespire(script_filepath, two_file)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(two_file), '2')

        result = self.RunRespire(script_filepath, three_file)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(three_file), '3')

        result = self.RunRespire(script_filepath, three_again_file)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(three_again_file), '3')

        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'add_numbers.TestBuild.count')))
        self.assertEqual(
            4,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'WriteAsString.count')))
        self.assertEqual(
            4,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir, 'AddNumbers.count')))
Exemplo n.º 10
0
    def test_BuildDynamicDependency(self):
        # Make sure that build scripts that register additional dependencies rebuild
        # when those dependencies change.
        script_filepath = os.path.join(self.temp_dirs.source_dir,
                                       'build_dynamic_dependency.respire.py')
        input_file = os.path.join(self.temp_dirs.out_dir, 'input_file.txt')
        output_file = os.path.join(self.temp_dirs.out_dir, 'output_file.txt')

        with open(input_file, 'w') as f:
            f.write('hello')
        result = self.RunRespire(script_filepath, output_file)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(output_file), 'hello')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'build_dynamic_dependency.count')))

        result = self.RunRespire(script_filepath, output_file)
        self.assertTrue(result)
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'build_dynamic_dependency.count')))

        with open(input_file, 'w') as f:
            f.write('there')
        result = self.RunRespire(script_filepath, output_file)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(output_file), 'there')
        self.assertEqual(
            2,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'build_dynamic_dependency.count')))
Exemplo n.º 11
0
    def test_DoubleInput(self):
        script_filepath = os.path.join(self.temp_dirs.source_dir,
                                       'double_input.respire.py')
        foo_path = os.path.join(self.temp_dirs.source_dir, 'foo.txt')
        foofoo_filepath = os.path.join(self.temp_dirs.out_dir, 'foofoo.txt')

        result = self.RunRespire(script_filepath, foofoo_filepath)
        self.assertTrue(result)

        self.assertEqual(test_utils.ContentsForFilePath(foofoo_filepath),
                         'foofoo')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'double_input.TestBuild.count')))
Exemplo n.º 12
0
    def test_CanPassObjectAsParameter(self):
        script_filepath = os.path.join(
            self.temp_dirs.source_dir,
            'can_pass_object_as_parameter.respire.py')
        foo_class_script_filepath = (os.path.join(self.temp_dirs.source_dir,
                                                  'foo_class.py'))

        value1_filepath = os.path.join(self.temp_dirs.out_dir,
                                       'value_with_import.txt')
        value2_filepath = os.path.join(self.temp_dirs.out_dir,
                                       'value_without_import.txt')

        def GenerateFoo(get_value):
            template = ('class Foo(object):\n'
                        '  def __init__(self, p, q):\n'
                        '    self.a = p\n'
                        '    self.b = q\n'
                        '\n'
                        '  def GetValue(self):\n'
                        '    return self.%s\n'
                        '\n')

            with open(foo_class_script_filepath, 'w') as f:
                f.write(template % (get_value))

        GenerateFoo('a')

        result = self.RunRespire(script_filepath, value1_filepath)
        self.assertTrue(result)
        result = self.RunRespire(script_filepath, value2_filepath)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(value1_filepath),
                         'woof')
        self.assertEqual(test_utils.ContentsForFilePath(value2_filepath),
                         'woof')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'can_pass_object_as_parameter.TestBuild.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'get_object_value.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'write_object_value_with_import.count')))
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'write_object_value_without_import.count')))

        GenerateFoo('b')

        result = self.RunRespire(script_filepath, value1_filepath)
        self.assertTrue(result)
        result = self.RunRespire(script_filepath, value2_filepath)
        self.assertTrue(result)
        self.assertEqual(test_utils.ContentsForFilePath(value1_filepath),
                         'bark')
        self.assertEqual(test_utils.ContentsForFilePath(value2_filepath),
                         'bark')
        self.assertEqual(
            1,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'can_pass_object_as_parameter.TestBuild.count')))
        self.assertEqual(
            2,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'get_object_value.count')))
        self.assertEqual(
            2,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'write_object_value_with_import.count')))
        self.assertEqual(
            2,
            test_utils.GetCount(
                os.path.join(self.temp_dirs.out_dir,
                             'write_object_value_without_import.count')))