def test_diff_files(): with swallow_outputs() as outputs: args = ['diff', diff_1_yaml, diff_2_yaml] main(args) assert_equal(outputs.err, '') assert_in('Files:', outputs.out) assert_in('< /etc/a', outputs.out) assert_in('> /etc/c', outputs.out) assert_not_in('< /etc/b', outputs.out) assert_not_in('> /etc/b', outputs.out)
def test_diff_svn(): with swallow_outputs() as outputs: args = ['diff', diff_1_yaml, diff_2_yaml] main(args) assert_equal(outputs.err, '') assert_in('SVN repositories:', outputs.out) assert_in('< c8ed47ab-45c9-818d-5d62-549dcc6d97d4 (/path/to/svn/repo/1/only)', outputs.out) assert_in('> d7192e3a-60de-5caa-ccdc9525dea75aabf (/path/to/svn/repo/2/only)', outputs.out) assert_in('SVN repository 95e4b738-84c7-154c-f082-34d40e21fdd4', outputs.out) assert_in('< 12 (/path/1/to/different/svn/commit)', outputs.out) assert_in('> 14 (/path/2/to/different/svn/commit)', outputs.out) assert_not_in('/path/1/to/common/svn/repo', outputs.out) assert_not_in('/path/2/to/common/svn/repo', outputs.out)
def test_diff_debian_packages(): with swallow_outputs() as outputs: args = ['diff', diff_1_yaml, diff_2_yaml] main(args) assert_equal(outputs.err, '') assert_in('Debian packages:', outputs.out) assert_in('< lib1only x86 2:1.6.4-3', outputs.out) assert_in('> lib2only x86 2:1.6.4-3', outputs.out) assert_in('< libarchdiff x86 2.4.6', outputs.out) assert_in('> libarchdiff amd64 2.4.6', outputs.out) assert_in('Debian package libversdiff x86:', outputs.out) assert_in('< 2.4.6', outputs.out) assert_in('> 2.4.7', outputs.out) assert_not_in('libsame', outputs.out)
def test_diff_git(): with swallow_outputs() as outputs: args = ['diff', diff_1_yaml, diff_2_yaml] main(args) assert_equal(outputs.err, '') assert_in('Git repositories:', outputs.out) assert_in('< 43e8e6577c7bf493ddb01ea7d49bef7dc7a6643b (/path/to/git/repo/1/only)', outputs.out) assert_in('> 64b1865267891fdd1a45251ca6f32df213dc546e (/path/to/git/repo/2/only)', outputs.out) assert_in('Git repository 5b8267181f6cae8dc37aeef21ea54171bd932522', outputs.out) assert_in('< 3e3aaa73a9c0ca061c7679af5fa7318e70f528ac (/path/1/to/different/git/commit)', outputs.out) assert_in('> 9d199f7fa7e6f691719e0860c5cf81193e815ad5 (/path/2/to/different/git/commit)', outputs.out) assert_not_in('/path/1/to/common/git/repo', outputs.out) assert_not_in('/path/2/to/common/git/repo', outputs.out) assert_not_in('99ac7f69a070077038a9eb9eca61c028db97181d', outputs.out) assert_not_in('d057b128759d80a47500adba0c4d3e95092bb87f', outputs.out)
def test_mutliple_targets(dst1=None, dst2=None): ok_(not exists(dst1)) ok_(not exists(dst2)) lgr = LoggerHelper("nicemantest").get_initialized_logger( logtarget="%s,%s" % (dst1, dst2)) ok_(exists(dst1)) ok_(exists(dst2)) msg = "Oh my god, they killed Kenny" lgr.error(msg) for dst in (dst1, dst2): with open(dst) as f: lines = f.readlines() assert_equal(len(lines), 1, "Read more than a single log line: %s" % lines) ok_(msg in lines[0]) # TODO: somehow test is stdout/stderr get their stuff
def test_diff_conda_packages(): with swallow_outputs() as outputs: args = ['diff', diff_1_yaml, diff_2_yaml] main(args) assert_equal(outputs.err, '') assert_in('Conda packages:', outputs.out) assert_in('< c_lib1only py36_0 2:1.6.4-3', outputs.out) assert_in('> c_lib2only py36_0 2:1.6.4-3', outputs.out) assert_in('< c_libbuilddiff py36_0 2.4.6', outputs.out) assert_in('> c_libbuilddiff hdf63c60_3 2.4.6', outputs.out) # TO DO: ensure the version strings (second and third lines below) # come from the conda report -- these could just match the debian # output checked in test_diff_debian_packages() assert_in('Conda package c_libversdiff py36_0:', outputs.out) assert_in('< 2.4.6', outputs.out) assert_in('> 2.4.7', outputs.out) assert_not_in('c_libsame', outputs.out)
def test_diff_no_distributions(): with swallow_outputs() as outputs: args = ['diff', diff_1_yaml, empty_yaml] main(args) assert_equal(outputs.err, '') assert_in('Debian packages:', outputs.out) assert_in('< lib1only x86 2:1.6.4-3', outputs.out) assert_in('< libsame x86 2.4.6', outputs.out) assert_in('< libarchdiff x86 2.4.6', outputs.out) assert_in('< libversdiff x86 2.4.6', outputs.out) assert_in('Conda packages:', outputs.out) assert_in('< c_lib1only py36_0 2:1.6.4-3', outputs.out) assert_in('< c_libsame py36_0 2.4.6', outputs.out) assert_in('< c_libbuilddiff py36_0 2.4.6', outputs.out) assert_in('< c_libversdiff py36_0 2.4.6', outputs.out) assert_in('Files:', outputs.out) assert_in('< /etc/a', outputs.out) assert_in('< /etc/b', outputs.out)
def test_logging_to_a_file(dst=None): ok_(not exists(dst)) lgr = LoggerHelper("nicemantest").get_initialized_logger(logtarget=dst) ok_(exists(dst)) msg = "Oh my god, they killed Kenny" lgr.error(msg) with open(dst) as f: lines = f.readlines() assert_equal(len(lines), 1, "Read more than a single log line: %s" % lines) line = lines[0] ok_(msg in line) ok_(not '\033[' in line, msg="There should be no color formatting in log files. Got: %s" % line) # verify that time stamp and level are present in the log line # do not want to rely on not having race conditions around date/time changes # so matching just with regexp ok_(re.match("\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} \[ERROR\] %s" % msg, line))
def test_get_url_for_packages(): assert_equal(get_url_for_packages({'cmtk': '3.2'}), {'cmtk': 'http://example.com/cmtk_3.2.deb'}) assert_equal(get_url_for_packages({'cmtk': '3.1'}), {'cmtk': 'http://example.com/cmtk_3.1.deb'})
def test_same(): with swallow_outputs() as outputs: args = ['diff', diff_1_yaml, diff_1_yaml] main(args) assert_equal(outputs.out, '') assert_equal(outputs.err, '')