def test_failure(self) -> None: """ `test_failure` is a simple test for the case when the `.test.cpp` gets WA. """ files = { 'timestamps.json': json.dumps({ 'example.test.cpp': get_timestamp_string_of_past(), }).encode(), 'example.test.cpp': failure_test_cpp, } paths = [pathlib.Path('example.test.cpp')] with tests.utils.load_files(files) as tempdir: with tests.utils.chdir(tempdir): timestamps_path = tempdir / 'timestamps.json' with onlinejudge_verify.marker.VerificationMarker( json_path=timestamps_path, use_git_timestamp=False) as marker: self.assertEqual( verify.main(paths, marker=marker).failed_test_paths, paths) with open(timestamps_path) as fh: timestamps = json.load(fh) self.assertEqual(timestamps, {})
def test_failure(self) -> None: files = { 'timestamps.json': b"""{"data/example.test.cpp": "2000-01-01 00:00:00 +0900"}""", 'example.test.cpp': '\n'.join([ '#define PROBLEM "https://judge.yosupo.jp/problem/aplusb"', '#include <cstdio>', 'int main() {', ' int a, b; scanf("%d%d", &a, &b);', ' printf("%d\\n", a ^ b);', ' return 0;', '}', ]).encode(), } paths = [pathlib.Path('example.test.cpp')] with tests.utils.load_files(files) as tempdir: with tests.utils.chdir(tempdir): timestamps_path = tempdir / 'timestamps.json' with onlinejudge_verify.marker.VerificationMarker( json_path=timestamps_path, use_git_timestamp=False) as marker: self.assertEqual( verify.main(paths, marker=marker).failed_test_paths, paths) with open(str(timestamps_path)) as fh: timestamps = json.load(fh) self.assertEqual(timestamps, {})
def test_timestamps(self) -> None: files = { 'timestamps.json': json.dumps({ 'not-updated.test.cpp': get_timestamp_string_of_past(), 'updated-success.test.cpp': get_timestamp_string_of_past(), 'updated-failure.test.cpp': get_timestamp_string_of_past(), }).encode(), 'not-updated.test.cpp': success_test_cpp, 'updated-success.test.cpp': success_test_cpp, 'updated-failure.test.cpp': failure_test_cpp, 'new-success.test.cpp': success_test_cpp, 'new-failure.test.cpp': failure_test_cpp, } paths = [ pathlib.Path(file) for file in files.keys() if file.endswith('.cpp') ] with tests.utils.load_files(files) as tempdir: set_timestamp_string(tempdir / 'not-updated.test.cpp', get_timestamp_string_of_past()) expected_return = list( map(pathlib.Path, [ 'updated-failure.test.cpp', 'new-failure.test.cpp', ])) expected_timestamps = { 'not-updated.test.cpp': get_timestamp_string_of_past(), 'updated-success.test.cpp': get_timestamp_string(tempdir / 'updated-success.test.cpp'), 'updated-failure.test.cpp': get_timestamp_string_of_past( ), # this doesn't disappear but is recognized as failure 'new-success.test.cpp': get_timestamp_string(tempdir / 'new-success.test.cpp'), } with tests.utils.chdir(tempdir): timestamps_path = tempdir / 'timestamps.json' with onlinejudge_verify.marker.VerificationMarker( json_path=timestamps_path, use_git_timestamp=False) as marker: self.assertEqual( sorted( verify.main(paths, marker=marker).failed_test_paths), sorted(expected_return)) with open(str(timestamps_path)) as fh: timestamps = json.load(fh) self.assertEqual(timestamps, expected_timestamps)
def test_success(self) -> None: files = { 'example.test.cpp': '\n'.join([ '#define PROBLEM "https://judge.yosupo.jp/problem/aplusb"', '#include <cstdio>', 'int main() {', ' int a, b; scanf("%d%d", &a, &b);', ' printf("%d\\n", a + b);', ' return 0;', '}', ]).encode(), } paths = [pathlib.Path('example.test.cpp')] with load_files(files) as tempdir: with chdir(tempdir): timestamps_path = tempdir / 'timestamps.json' with onlinejudge_verify.marker.VerificationMarker( json_path=timestamps_path, use_git_timestamp=False) as marker: verify.main(paths, marker=marker) with open(str(timestamps_path)) as fh: timestamps = json.load(fh) self.assertEqual(list(timestamps.keys()), ['example.test.cpp'])
def test_success(self) -> None: files = { 'example.test.cpp': success_test_cpp, } paths = [pathlib.Path('example.test.cpp')] with tests.utils.load_files(files) as tempdir: with tests.utils.chdir(tempdir): timestamps_path = tempdir / 'timestamps.json' with onlinejudge_verify.marker.VerificationMarker( json_path=timestamps_path, use_git_timestamp=False) as marker: self.assertEqual( verify.main(paths, marker=marker).failed_test_paths, []) with open(str(timestamps_path)) as fh: timestamps = json.load(fh) self.assertEqual(list(timestamps.keys()), ['example.test.cpp'])
def test_success(self) -> None: """ `test_success` is a simple test for the case when the `.test.cpp` gets AC. """ files = { 'example.test.cpp': SUCCESS_TEST_CPP, } paths = [pathlib.Path('example.test.cpp')] with tests.utils.load_files(files) as tempdir: with tests.utils.chdir(tempdir): timestamps_path = tempdir / 'timestamps.json' with onlinejudge_verify.marker.VerificationMarker(json_path=timestamps_path, use_git_timestamp=False) as marker: self.assertEqual(verify.main(paths, marker=marker).failed_test_paths, []) with open(timestamps_path) as fh: timestamps = json.load(fh) self.assertEqual(list(timestamps.keys()), ['example.test.cpp'])
def test_success(self) -> None: files = { pathlib.Path('rust-toolchain'): textwrap.dedent("""\ 1.42.0 """).encode(), pathlib.Path('Cargo.toml'): textwrap.dedent("""\ [package] name = "verification" version = "0.0.0" edition = "2018" """).encode(), pathlib.Path('src', 'bin', 'library-checker-aplusb.rs'): textwrap.dedent("""\ // verification-helper: PROBLEM https://judge.yosupo.jp/problem/aplusb use std::io::{self, Read as _}; fn main() { let mut input = "".to_owned(); io::stdin().read_to_string(&mut input).unwrap(); let mut input = input.split_ascii_whitespace(); macro_rules! read(($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap())); let (a, b) = (read!(u64), read!(u64)); println!("{}", a + b); } """).encode(), } path = pathlib.Path('src', 'bin', 'library-checker-aplusb.rs') with tests.utils.load_files_pathlib(files) as tempdir: with tests.utils.chdir(tempdir): timestamps_path = tempdir / 'timestamps.json' with onlinejudge_verify.marker.VerificationMarker( json_path=timestamps_path, use_git_timestamp=False) as marker: self.assertEqual( verify.main([path], marker=marker).failed_test_paths, []) with open(timestamps_path) as fh: timestamps = json.load(fh) self.assertEqual(list(timestamps.keys()), [path.as_posix()])
def test_timestamps(self) -> None: """ `test_timestamps` checks whether `timestamps.json` is properly updated for all cases which files have no dependencies. """ # prepare files files = { 'not-updated.test.cpp': SUCCESS_TEST_CPP, 'updated-success.test.cpp': SUCCESS_TEST_CPP, 'updated-failure.test.cpp': FAILURE_TEST_CPP, 'new-success.test.cpp': SUCCESS_TEST_CPP, 'new-failure.test.cpp': FAILURE_TEST_CPP, } paths = list(map(pathlib.Path, files.keys())) with tests.utils.load_files(files) as tempdir: timestamps_path = tempdir / 'timestamps.json' with open(timestamps_path, 'w') as fh: json.dump( { 'not-updated.test.cpp': get_timestamp_string(tempdir / 'not-updated.test.cpp'), # NOTE: os.utime doesn't work as expected on Windows 'updated-success.test.cpp': get_timestamp_string_of_past(), 'updated-failure.test.cpp': get_timestamp_string_of_past(), 'removed.test.cpp': get_timestamp_string_of_past(), }, fh) # prepare expected values expected_return = list(map(pathlib.Path, [ 'updated-failure.test.cpp', 'new-failure.test.cpp', ])) expected_timestamps = { 'not-updated.test.cpp': get_timestamp_string(tempdir / 'not-updated.test.cpp'), 'updated-success.test.cpp': get_timestamp_string(tempdir / 'updated-success.test.cpp'), 'new-success.test.cpp': get_timestamp_string(tempdir / 'new-success.test.cpp'), } # check actual values with tests.utils.chdir(tempdir): with onlinejudge_verify.marker.VerificationMarker(json_path=timestamps_path, use_git_timestamp=False) as marker: self.assertEqual(sorted(verify.main(paths, marker=marker).failed_test_paths), sorted(expected_return)) with open(str(timestamps_path)) as fh: timestamps = json.load(fh) self.assertEqual(timestamps, expected_timestamps)
def test_failure(self) -> None: files = { 'timestamps.json': json.dumps({ "data/example.test.cpp": "2000-01-01 00:00:00 +0900", }).encode(), 'example.test.cpp': failure_test_cpp, } paths = [pathlib.Path('example.test.cpp')] with tests.utils.load_files(files) as tempdir: with tests.utils.chdir(tempdir): timestamps_path = tempdir / 'timestamps.json' with onlinejudge_verify.marker.VerificationMarker( json_path=timestamps_path, use_git_timestamp=False) as marker: self.assertEqual( verify.main(paths, marker=marker).failed_test_paths, paths) with open(str(timestamps_path)) as fh: timestamps = json.load(fh) self.assertEqual(timestamps, {})
def test_separated_dir(self) -> None: """`test_separated_dir` is a test for the case when the library files exist at the separate directory of the test file. """ files = { pathlib.Path('library', '__init__.py'): b"", pathlib.Path('library', 'imported.py'): LIBRARY_IMPORTED_PY, pathlib.Path('tests', 'main.py'): TESTS_MAIN_PY, } path = pathlib.Path('tests', 'main.py') with tests.utils.load_files_pathlib(files) as tempdir: with tests.utils.chdir(tempdir): timestamps_path = tempdir / 'timestamps.json' with onlinejudge_verify.marker.VerificationMarker( json_path=timestamps_path, use_git_timestamp=False) as marker: self.assertEqual( verify.main([path], marker=marker).failed_test_paths, []) with open(timestamps_path) as fh: timestamps = json.load(fh) self.assertEqual(list(timestamps.keys()), [str(pathlib.Path('tests', 'main.py'))])