Ejemplo n.º 1
0
    def test_basic(self, testdir, a_py):
        code, checksum = read_file_with_checksum('a.py')
        assert checksum == 'ea4739bb5b0069cafb92af3874891898617ef590'

        fs_data = SourceTree(rootdir=testdir.tmpdir.strpath, mtimes={'a.py': a_py.mtime()}, checksums={'a.py': checksum})
        changed_files = fs_data.get_changed_files()
        assert changed_files == {}
Ejemplo n.º 2
0
 def get_file(self, filename):
     if filename not in self.changed_files:
         code, checksum = read_file_with_checksum(
             os.path.join(self.rootdir, filename))
         self.mtimes[filename] = os.path.getmtime(
             os.path.join(self.rootdir, filename))
         self.checksums[filename] = checksum
         self.changed_files[filename] = parse_file(filename=filename,
                                                   rootdir=self.rootdir,
                                                   source_code=code)
     return self.changed_files[filename]
Ejemplo n.º 3
0
 def get_file(self, filename):
     if filename not in self.cache:
         code, checksum = read_file_with_checksum(
             os.path.join(self.rootdir, filename)
         )
         if checksum:
             fs_mtime = os.path.getmtime(os.path.join(self.rootdir, filename))
             self.cache[filename] = Module(
                 source_code=code,
                 file_name=filename,
                 rootdir=self.rootdir,
                 mtime=fs_mtime,
                 checksum=checksum,
             )
         else:
             self.cache[filename] = None
     return self.cache[filename]
Ejemplo n.º 4
0
    def test_basic_checksum(self, testdir, a_py):
        code, checksum = read_file_with_checksum('a.py')
        fs_data = SourceTree(rootdir=testdir.tmpdir.strpath, mtimes={'a.py': a_py.mtime()}, checksums={'a.py': checksum})

        a_py.setmtime(1424880936)
        changed_files = fs_data.get_changed_files()
        assert changed_files == {}
        assert fs_data.mtimes['a.py'] == 1424880936

        testdir.makepyfile(a="""
        def test_a():
            return 0 # comment
        """)
        fs_data = SourceTree(rootdir=testdir.tmpdir.strpath, mtimes={'a.py': -100}, checksums={'a.py': checksum})
        changed_files = fs_data.get_changed_files()
        assert 'a.py' in changed_files
        assert [type(c) for c in changed_files['a.py'].checksums] == [int, int]
        assert fs_data.checksums['a.py'] == 'ec1fd361d4d73353c3f65cb10b86fcea4e0d0e42'
Ejemplo n.º 5
0
    def get_changed_files(self):

        for filename in self.mtimes:
            try:
                absfilename = os.path.join(self.rootdir, filename)
                fs_mtime = os.path.getmtime(absfilename)
                if self.mtimes[filename] != fs_mtime:
                    self.mtimes[filename] = fs_mtime
                    code, fs_checksum = read_file_with_checksum(absfilename)
                    if self.checksums.get(filename) != fs_checksum:
                        self.checksums[filename] = fs_checksum
                        self.changed_files[filename] = parse_file(
                            filename=filename,
                            rootdir=self.rootdir,
                            source_code=code)

            except OSError:
                pass
                # self.changed_files[filename] = DISAPPEARED_FILE

        return self.changed_files
Ejemplo n.º 6
0
 def test_read_2lines_file_with_checksum(self):
     assert (read_file_with_checksum(self.prepend_samples_dir("2lines.py"))
             [0] == "# -*- coding: cp1250 -*-\n# 2ndline\n")
Ejemplo n.º 7
0
 def test_read_nonexistent_file_with_checksum(self):
     assert read_file_with_checksum(
         self.prepend_samples_dir("notexist.py")) == (
             None,
             None,
         )
Ejemplo n.º 8
0
 def test_read_empty_file_with_checksum(self):
     code, checksum = read_file_with_checksum(
         self.prepend_samples_dir("empty.py"))
     assert code == ""
     assert checksum == "da39a3ee5e6b4b0d3255bfef95601890afd80709"
Ejemplo n.º 9
0
 def test_read_file_with_checksum(self):
     assert (u"š" in read_file_with_checksum(
         self.prepend_samples_dir("print1250r.py"))[0])
Ejemplo n.º 10
0
def test_read_2lines_file_with_checksum():
    assert read_file_with_checksum('test/samples/2lines.py')[0] == '#2ndline'
Ejemplo n.º 11
0
def test_read_empty_file_with_checksum():
    assert read_file_with_checksum('test/samples/empty.py')[0] == ''
Ejemplo n.º 12
0
def test_read_file_with_checksum():
    assert u'š' in read_file_with_checksum('test/samples/print1250r.py')[0]