Ejemplo n.º 1
0
 def tearDown(self):
     try:
         for p in Path('.').glob('lib*'):
             p.unlink()
         Path('myprogram').unlink()
     except:
         pass
Ejemplo n.º 2
0
 def test_mod_times(self):
     ComputeSum().make()
     file = 'item_5_price.txt'
     mod_time1 = Path(file).stat().st_mtime_ns
     time.sleep(1)
     with open(file, 'w', encoding='UTF-8') as f:
         f.write('150')
     mod_time2 = Path(file).stat().st_mtime_ns
     self.assertGreater(mod_time2, mod_time1)
Ejemplo n.º 3
0
class CreateProgram(Task):
    def __init__(self, prog_file):
        self._prog_file = Path(prog_file)
        self.trigger_exception_if_buit = False

    def target(self):
        return self._prog_file

    def build(self, lib1_obj, lib2_obj, lib3_obj=None):
        if self.trigger_exception_if_buit:
            raise Exception('Sould not be rebuilt')
        # os.system('gcc lib1.o lib2.o -o myprogram')
        assert lib1_obj.exists()
        assert lib2_obj.exists()
        if lib3_obj:
            assert lib3_obj.exists()
        self._prog_file.touch()
Ejemplo n.º 4
0
    def build(self, *tax_files):
        sum_ = 0
        for file in tax_files:
            with file.open(encoding='UTF-8') as f:
                sum_ += int(f.read())

        with Path('total.txt').open('w', encoding='UTF-8') as f:
            f.write('%d' % sum_)
Ejemplo n.º 5
0
class CreateItem(Task):
    def __init__(self, num):
        self._output_path = Path('item_%d_price.txt' % num)

    def target(self):
        return self._output_path

    def build(self):
        with self._output_path.open('w', encoding='UTF-8') as f:
            f.write('100')
Ejemplo n.º 6
0
class CreateItem(Task):
    def __init__(self, num):
        self._output_path = Path('item_%d_price.txt' % num)

    def target(self):
        return self._output_path

    def build(self):
        with self._output_path.open('w', encoding='UTF-8') as f:
            f.write('100')
Ejemplo n.º 7
0
class AddTaxToItem(Task):
    def __init__(self, num):
        self._output_path = Path('item_%d_tax.txt' % num)

    def target(self):
        return self._output_path

    def build(self, input_path):
        with input_path.open(encoding='UTF-8') as f:
            price = int(f.read())
        with self._output_path.open('w', encoding='UTF-8') as f:
            f.write('%d' % int(price * 1.3))
Ejemplo n.º 8
0
class AddTaxToItem(Task):
    def __init__(self, num):
        self._output_path = Path('item_%d_tax.txt' % num)

    def target(self):
        return self._output_path

    def build(self, input_path):
        with input_path.open(encoding='UTF-8') as f:
            price = int(f.read())
        with self._output_path.open('w', encoding='UTF-8') as f:
            f.write('%d' % int(price * 1.3))
Ejemplo n.º 9
0
 def setUp(self):
     Path('lib1.c').touch()
     Path('lib2.c').touch()
     Path('lib3.c').touch()
     create_lib1 = CreateObjFile('lib1') << Path('lib1.c')
     create_lib2 = CreateObjFile('lib1') << Path('lib2.c')
     create_lib3 = CreateObjFile('lib3') << Path('lib3.c')
     self.create_prog1 = CreateProgram('myprogram') << create_lib1 + \
                                                       create_lib2
     self.create_prog2 = CreateProgram('myprogram') << create_lib1 + \
                                                       create_lib2 + \
                                                       create_lib3
Ejemplo n.º 10
0
 def test_compile_with_three_dependencies(self):
     self.create_prog2.make()
     self.assertTrue(Path('myprogram').exists())
Ejemplo n.º 11
0
 def test_recompile_from_scratch(self):
     self.create_prog1.make()
     self.assertTrue(Path('myprogram').exists())
     time.sleep(1.1)
     self.create_prog1.trigger_exception_if_buit = True
     self.create_prog1.make()
Ejemplo n.º 12
0
 def test_compile_from_scratch(self):
     self.create_prog1.make()
     self.assertTrue(Path('myprogram').exists())
Ejemplo n.º 13
0
 def __init__(self, destination):
     self._destination = Path(destination)
Ejemplo n.º 14
0
 def __init__(self, prog_file):
     self._prog_file = Path(prog_file)
     self.trigger_exception_if_buit = False
Ejemplo n.º 15
0
 def target(self):
     return Path(self._decompressed)
Ejemplo n.º 16
0
 def __init__(self, num):
     self._output_path = Path('item_%d_price.txt' % num)
Ejemplo n.º 17
0
 def __init__(self, num):
     self._output_path = Path('item_%d_price.txt' % num)
Ejemplo n.º 18
0
 def tearDown(self):
     for f in Path('.').glob('*.txt'):
         f.unlink()
Ejemplo n.º 19
0
 def target(self):
     return Path('total.txt')
Ejemplo n.º 20
0
 def target(self):
     return Path(self.filename + '.o')
Ejemplo n.º 21
0
 def build(self, c_file):
     # os.system('gcc -c %s.o -o %s.o'%c_file)
     assert c_file.exists()
     Path(self.filename + '.o').touch()
Ejemplo n.º 22
0
 def target(self):
     return Path(self._destination)
Ejemplo n.º 23
0
 def build(self, compressed):
     self.debug('Decompressing %s to %s' % (compressed, self._decompressed))
     with tarfile.open(str(compressed)) as f:
         f.extractall(str(Path(self._decompressed).parent))
     assert Path(self._decompressed).exists()
     Path(self._decompressed).touch()