Unit tests - Replace old version.t with the new python based version.py
This commit is contained in:
committed by
Paul Beckingham
parent
5daca69b4b
commit
b250ded517
@@ -1,67 +0,0 @@
|
|||||||
#!/usr/bin/env python2.7
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
# Ensure python finds the local simpletap module
|
|
||||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
from subprocess import Popen, PIPE, STDOUT
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
|
|
||||||
class TestVersion(unittest.TestCase):
|
|
||||||
@classmethod
|
|
||||||
def setUpClass(cls):
|
|
||||||
"""Executed once before any test in the class"""
|
|
||||||
# Empty rc file
|
|
||||||
open("version.rc", 'w').close()
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
"""Executed before each test in the class"""
|
|
||||||
|
|
||||||
def testVersion(self):
|
|
||||||
"""Copyright is current"""
|
|
||||||
command = ["../src/task", "rc:version.rc", "version"]
|
|
||||||
|
|
||||||
# Merge STDOUT and STDERR
|
|
||||||
p = Popen(command, stdout=PIPE, stderr=STDOUT)
|
|
||||||
out, err = p.communicate()
|
|
||||||
|
|
||||||
expected = "Copyright \(C\) \d{4} - %d" % (datetime.now().year,)
|
|
||||||
self.assertRegexpMatches(out.decode("utf8"), expected)
|
|
||||||
|
|
||||||
def testFailVersion(self):
|
|
||||||
"""Copyright is one year old"""
|
|
||||||
command = ["../src/task", "rc:version.rc", "version"]
|
|
||||||
|
|
||||||
# Merge STDOUT and STDERR
|
|
||||||
p = Popen(command, stdout=PIPE, stderr=STDOUT)
|
|
||||||
out, _ = p.communicate()
|
|
||||||
|
|
||||||
expected = "Copyright \(C\) \d{4} - %d" % (datetime.now().year - 1,)
|
|
||||||
self.assertRegexpMatches(out.decode("utf8"), expected)
|
|
||||||
|
|
||||||
def testFailOther(self):
|
|
||||||
"""Nothing to do with Copyright"""
|
|
||||||
self.assertEqual("I like to code", "I like\nto code\n")
|
|
||||||
|
|
||||||
@unittest.skipIf(1 != 0, "This machine has sane logic")
|
|
||||||
def testSkipped(self):
|
|
||||||
"""Test all logic of the world"""
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
"""Executed after each test in the class"""
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def tearDownClass(cls):
|
|
||||||
"""Executed once after all tests in the class"""
|
|
||||||
os.remove("version.rc")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
from simpletap import TAPTestRunner
|
|
||||||
unittest.main(testRunner=TAPTestRunner())
|
|
||||||
|
|
||||||
# vim: ai sts=4 et sw=4
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#! /usr/bin/env perl
|
#! /usr/bin/env python2.7
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
################################################################################
|
################################################################################
|
||||||
##
|
##
|
||||||
## Copyright 2006 - 2014, Paul Beckingham, Federico Hernandez.
|
## Copyright 2006 - 2014, Paul Beckingham, Federico Hernandez.
|
||||||
@@ -25,20 +26,42 @@
|
|||||||
##
|
##
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
use strict;
|
import sys
|
||||||
use warnings;
|
import os
|
||||||
use Test::More tests => 2;
|
# Ensure python finds the local simpletap module
|
||||||
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
qx{touch version.rc};
|
import unittest
|
||||||
|
from subprocess import Popen, PIPE, STDOUT
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
my $year = (localtime (time))[5] + 1900;
|
|
||||||
|
|
||||||
my $output = qx{../src/task rc:version.rc version 2>&1};
|
class TestVersion(unittest.TestCase):
|
||||||
like ($output, qr/Copyright \(C\) \d{4} - $year/, 'Copyright is current');
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
"""Executed once before any test in the class"""
|
||||||
|
# Empty rc file
|
||||||
|
open("version.rc", 'w').close()
|
||||||
|
|
||||||
# Cleanup.
|
def testVersion(self):
|
||||||
unlink 'version.rc';
|
"""Copyright is current"""
|
||||||
ok (!-r 'version.rc', 'Removed version.rc');
|
command = ["../src/task", "rc:version.rc", "version"]
|
||||||
|
|
||||||
exit 0;
|
# Merge STDOUT and STDERR
|
||||||
|
p = Popen(command, stdout=PIPE, stderr=STDOUT)
|
||||||
|
out, err = p.communicate()
|
||||||
|
|
||||||
|
expected = "Copyright \(C\) \d{4} - %d" % (datetime.now().year,)
|
||||||
|
self.assertRegexpMatches(out.decode("utf8"), expected)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
"""Executed once after all tests in the class"""
|
||||||
|
os.remove("version.rc")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
from simpletap import TAPTestRunner
|
||||||
|
unittest.main(testRunner=TAPTestRunner())
|
||||||
|
|
||||||
|
# vim: ai sts=4 et sw=4
|
||||||
|
|||||||
Reference in New Issue
Block a user