Skip to content

Commit

Permalink
Add test for combine_files()
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Aug 11, 2021
1 parent 1149989 commit 536a581
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
3 changes: 3 additions & 0 deletions reprozip/reprozip/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def __ne__(self, other):
def __hash__(self):
return hash(self.path)

def __repr__(self):
return '<File %r>' % self.path


class Package(object):
"""A distribution package, containing a set of files.
Expand Down
56 changes: 51 additions & 5 deletions tests/test_reprozip.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
from __future__ import print_function, unicode_literals

import os

import sqlite3
from rpaths import AbstractPath, Path
import sqlite3
import sys
import unittest
from unittest import mock

from reprozip.common import FILE_READ, FILE_WRITE, FILE_WDIR, InputOutputFile
from reprozip.tracer.trace import get_files, compile_inputs_outputs
from reprozip.common import FILE_READ, FILE_WRITE, FILE_WDIR, File, \
Package, InputOutputFile
from reprozip.tracer.trace import TracedFile, get_files, compile_inputs_outputs
from reprozip import traceutils
from reprozip.utils import PY3, unicode_, UniqueNames, make_dir_writable

Expand Down Expand Up @@ -229,7 +230,7 @@ def setUp(self):
def tearDown(self):
self.tmpdir.rmtree()

def test_combine(self):
def test_combine_traces(self):
traces = []
schema = '''
PRAGMA foreign_keys=OFF;
Expand Down Expand Up @@ -348,3 +349,48 @@ def test_combine(self):
(3, '/bin/false', 4, 12345678903002, 6, 'false',
'RUN=fourth', '/home')],
])

def test_combine_files(self):
# Patch TracedObject constructor to not go to disk to read size etc
def _mock_TracedObject_init(self, path):
super(TracedFile, self).__init__(path, None)

with mock.patch.object(
TracedFile, '__init__',
_mock_TracedObject_init,
):
# Call combine_files()
files, packages = traceutils.combine_files(
[File('/tmp/a'), File('/tmp/c')],
[
Package('pkg1', '1.0.0', [File('/usr/a'), File('/usr/c')]),
Package('pkg2', '2.0.0', [File('/usr/d'), File('/usr/e')]),
],
[File('/tmp/a'), File('/tmp/b')],
[
Package('pkg1', '1.0.0', [File('/usr/a'), File('/usr/b')]),
Package('pkg3', '3.0.0', [File('/usr/f'), File('/usr/g')]),
],
)
self.assertEqual(
files,
{File('/tmp/a'), File('/tmp/b'), File('/tmp/c')},
)
self.assertEqual(
packages,
[
Package('pkg1', '1.0.0'),
Package('pkg2', '2.0.0'),
Package('pkg3', '3.0.0'),
],
)
packages = {pkg.name: pkg for pkg in packages}
self.assertEqual(set(packages['pkg1'].files), {
File('/usr/a'), File('/usr/b'), File('/usr/c'),
})
self.assertEqual(set(packages['pkg2'].files), {
File('/usr/d'), File('/usr/e'),
})
self.assertEqual(set(packages['pkg3'].files), {
File('/usr/f'), File('/usr/g'),
})

0 comments on commit 536a581

Please sign in to comment.